boost-spirit

Boost.Spirit.Qi - Errors at the beginning of a rule

爱⌒轻易说出口 提交于 2019-12-01 19:22:14
How would I detect an error at the start of a rule? For example, consider the Mini XML example included in the docs. If I feed the parser something like: <element>this is an error<element> Then I get: Error! Expecting here: "" Error! Expecting here: "" Parsing failed. That's fine, but then consider feeding it: element>this is an error</element> And I get the very generic and not so useful: Parsing failed. How could I modify the rule to report the error in an informative way? You'd want to require an element at the document root level. The other messages are generated by failed expectation

how to make error handling work for boost::spirit

我怕爱的太早我们不能终老 提交于 2019-12-01 18:33:06
in boost::spirit, I added error handling code based on example roman. #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/foreach.hpp> #include <iostream> #include <fstream> #include <string> #include <vector> namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; namespace phoenix = boost::phoenix; template <typename Iterator> struct roman : qi::grammar<Iterator> { roman

how to make error handling work for boost::spirit

血红的双手。 提交于 2019-12-01 18:23:11
问题 in boost::spirit, I added error handling code based on example roman. #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/foreach.hpp> #include <iostream> #include <fstream> #include <string> #include <vector> namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii;

Boost spirit parse rule is not applied

£可爱£侵袭症+ 提交于 2019-12-01 13:20:32
i can´t see my error here .. this rule parse some stuff ok but the last two samples not. Could somebody please give me a hint .. Goal is a parser than can identify member property access and member function calls. Also chained in some way a() a(para) x.a() x.a(para) x.a(para).g(para).j() x.y x.y.z x.y.z() <---fail y.z.z(para) <--- fail lvalue = iter_pos >> name[_val = _1] >> *(lit('(') > paralistopt > lit(')') >> iter_pos)[_val = construct<common_node>(type_cmd_fnc_call, LOCATION_NODE_ITER(_val, _2), key_this, construct<common_node>(_val), key_parameter, construct<std::vector<common_node> >(_1

Boost::Spirit : Optimizing an expression parser

我是研究僧i 提交于 2019-12-01 11:20:19
I'm trying to write a program to parse and evaluate mathematical, litteral and boolean expressions, for example : "(9/3) == 3+3*2" would be parsed as "(9/3) == (3+(3*2))" and evaluted as "false" "1+2/3" would be parsed as "1+(2/3)" and evaluated as "6". "this + is + a + test" would be parsed as "this+is+a+test" and evaluated as "thisisatest" The program correctly parses and solves what I'm giving it, but as soon as I put parenthesis in the expressions, the parsing takes a ridiculous amount of time. I've based my work on Sehe's impressively exhaustive answer on how to write a boolean grammar

Boost Spirit Implement small one-line DSL on a server application

做~自己de王妃 提交于 2019-12-01 10:56:26
Apologies if this question has been answered before. I want to insert a small DSL into a server application I work on. The syntax is very simple and even at this early stage I am stumped. I just can't get my head around how to construct the syntax in spirit. Here is an example of the syntax I want to test for: WHERE [not] <condition> [ and | or <condition> ] <command> [parameters] The WHERE clause will select a number of objects from an internal store by testing named properties on them. The vector of selected objects is then passed as input to the command object. There are 2 possible tests I

Is it possible to reuse a Spirit Qi grammar as a Spirit Karma grammar?

∥☆過路亽.° 提交于 2019-12-01 10:36:30
I have a Qi grammar definition that I use to parse an input. Later I have a Karma generator to output in a way that should be similar to the input. Is this possible at all? It seem that a parser grammar can be transformed into a generator grammar automatically (??). #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/karma.hpp> #include <iostream> int main(){ //test input std::string s = "Xx 1.233 pseudo"; //input variables std::string element; double mass; std::string pseudo; auto GRAMMAR = boost::spirit::qi::lexeme[+(boost::spirit

auto concatenation of parse results into vectors

与世无争的帅哥 提交于 2019-12-01 10:12:23
I've written some rules to parse floats into two std::vector's of floats, which in turn are stored in a struct: Data input: # # object name01 # v -1.5701 33.8087 0.3592 v -24.0119 0.0050 21.7439 # a comment vn 0.0000 0.5346 0.8451 vn 0.8331 0.5531 -0.0000 # another comment Struct: struct ObjParseData { ObjParseData() : verts(), norms() {} std::vector<float> verts; std::vector<float> norms; }; And the relevant parsing code: struct objGram : qi::grammar<std::string::const_iterator, ObjParseData(), iso8859::space_type> { objGram() : objGram::base_type(start) { vertex = 'v' >> qi::double_ >> qi:

How to make Boost.Spirit.Lex token value be a substring of matched sequence (preferably by regex matching group)

爱⌒轻易说出口 提交于 2019-12-01 09:43:03
I'm writing a simple expressions parser. It is build on a Boost.Spirit.Qi grammar based on Boost.Spirit.Lex tokens (Boost in version 1.56). The tokens are defined as follows: using namespace boost::spirit; template< typename lexer_t > struct tokens : lex::lexer<lexer_t> { tokens() : /* ... */, variable("%(\\w+)") { this->self = /* ... */ | variable; } /* ... */ lex::token_def<std::string> variable; }; Now I would like the variable token value to be just the name (the matching group (\\w+) ) without prefix % symbol. How do I do that? Using a matching group by itself doesn't help. Still value is

Boost::Spirit : Optimizing an expression parser

一曲冷凌霜 提交于 2019-12-01 09:31:51
问题 I'm trying to write a program to parse and evaluate mathematical, litteral and boolean expressions, for example : "(9/3) == 3+3*2" would be parsed as "(9/3) == (3+(3*2))" and evaluted as "false" "1+2/3" would be parsed as "1+(2/3)" and evaluated as "6". "this + is + a + test" would be parsed as "this+is+a+test" and evaluated as "thisisatest" The program correctly parses and solves what I'm giving it, but as soon as I put parenthesis in the expressions, the parsing takes a ridiculous amount of