boost-spirit-qi

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

此生再无相见时 提交于 2019-12-01 22:31:06
问题 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? 回答1: You'd want

Can Boost Spirit Rules be parameterized

让人想犯罪 __ 提交于 2019-12-01 22:02:13
问题 In my Boost Spirit grammar I would like to have a rule that does this: rule<...> noCaseLit = no_case[ lit( "KEYWORD" ) ]; but for a custom keyword so that I can do this: ... >> noCaseLit( "SomeSpecialKeyword" ) >> ... >> noCaseLit( "OtherSpecialKeyword1" ) Is this possible with Boost Spirit rules and if so how? P.S. I use the case insensitive thing as an example, what I'm after is rule parameterization in general. Edits: Through the link provided by 'sehe' in the comments I was able to come

Add to a spirit qi symbol table in a semantic action

╄→гoц情女王★ 提交于 2019-12-01 20:53:18
Going by the opening paragraph of the boost::spirit::qi::symbols documentation , I assumed that it wouldn't be too hard to add symbols to a qi::symbols from a semantic action. Unfortunately it appears to be not as straightforward as I would have assumed. The following bit of test code exhibits the problem: #define BOOST_SPIRIT_USE_PHOENIX_V3 #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix.hpp> #include <string> namespace qi = boost::spirit::qi; typedef qi::symbols<char, unsigned int> constants_dictionary; template <typename Iter> struct parser : public qi::grammar

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

boost spirit reporting semantic error

风流意气都作罢 提交于 2019-12-01 11:10:29
I am playing with boost.spirit library and I cannot manage to report a simple error message from my semantic action. // supported parameter types (int or quoted strings) parameter = bsqi::int_ | bsqi::lexeme[L'"' > *(bsqi_coding::char_ - L'"') > L'"']; parameter.name("parameter"); // comma separator list of parameters (or no parameters) parameters = -(parameter % L','); parameters.name("parameters"); // action with parameters action = (Actions > L'(' > parameters > L')')[bsqi::_pass = boost::phoenix::bind(&ValidateAction, bsqi::_1, bsqi::_2)]; action.name("action"); The Actions is just a

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:

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

╄→尐↘猪︶ㄣ 提交于 2019-12-01 09:27:23
问题 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

cannot get boost::spirit parser&lexer working for token types other than std::string or int or double

。_饼干妹妹 提交于 2019-12-01 09:27:07
This does not compile (code below). There was another question here with the same error. But I don't understand the answer. I already tried inserting qi::eps in places -- but without success. I also tried already adding meta functions (boost::spirit::raits::is_container) for the types used -- but this also does not help. I also tried using the same variant containing all types I need to use everywhere. Same problem. Has anybody gotten this working for a lexer returning something else than double or int or string? And for the parser also returning non-trivial objects? I've tried implementing