boost-spirit

How can I use polymorphic attributes with boost::spirit::qi parsers?

两盒软妹~` 提交于 2019-11-26 22:55:34
I would like my boost::spirit-based parser to be able to parse a file, convert the parsed rules into different types, and emit a vector containing all of the matches it found. All of the types that are emitted as attributes should be inherited from a base type, for example: #include <boost/spirit/include/qi.hpp> #include <boost/fusion/adapt_struct.hpp> #include <boost/shared_ptr.hpp> #include <boost/foreach.hpp> struct CommandBase { virtual void commandAction() { std::cout << "This is a base command. You should never see this!" << std::endl; //Boost::spirit seems to get mad if I make this

boost::spirit::qi keywords and identifiers

◇◆丶佛笑我妖孽 提交于 2019-11-26 21:53:50
问题 I've seen a few posts related to the nuances of keyword/identifier use in qi grammars, but I can't quite make sense of how the approach demonstrated in the boost examples is supposed to work... Keywords declaration: qi::symbols<char> keywords; Example keyword set: keywords.add ("foo") ("bar") ; Identifier rule declaration: qi::rule<std::string::const_iterator, std::string(), ascii::space_type> identifier; Here's how the identifier rule is defined in the qi calc and compiler examples:

C++ Boost qi recursive rule construction

▼魔方 西西 提交于 2019-11-26 21:40:54
问题 [It seems my explanations and expectations are not clear at all, so I added precision on how I'd like to use the feature at the end of the post] I'm currently working on grammars using boost qi. I had a loop construction for a rule cause I needed to build it from the elements of a vector. I have re-written it with simple types, and it looks like: #include <string> // using boost 1.43.0 #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/qi_eps.hpp> #include <boost/spirit

Parse quoted strings with boost::spirit

时光总嘲笑我的痴心妄想 提交于 2019-11-26 20:58:52
I would like to parse a sentence where some strings may be unquoted, 'quoted' or "quoted". The code below almost works - but it fails to match closing quotes. I'm guessing this is because of the qq reference. A modification is commented in the code, the modification reults in "quoted' or 'quoted" also parsing and helps show the original problem is with the closing quote. The code also describes the exact grammar. To be completely clear: unquoted strings parse. A quoted string like 'hello' will parse the open quote ' , all the characters hello , but then fail to parse the final quote ' . I made

Boost::spirit how to parse and call c++ function-like expressions

末鹿安然 提交于 2019-11-26 20:51:04
问题 I want to use boost spirit to parse an expression like function1(arg1, arg2, function2(arg1, arg2, arg3), function3(arg1,arg2)) and call corresponding c++ functions. What should be the grammar to parse above expression and call the corresponding c++ function by phoneix::bind()? I have 2 types of functions to call 1) string functions; wstring GetSubString(wstring stringToCut, int position, int length); wstring GetStringToken(wstring stringToTokenize, wstring seperators, int tokenNumber ); 2)

Detecting the parameter types in a Spirit semantic action

北城以北 提交于 2019-11-26 20:32:36
General case: I can't figure out why my Spirit grammar/semantics actions aren't compiling. Sometimes, the compiler will complain about assignment or type incompatibilities and I have no clue what's wrong. The problem occurs in two main areas: predicting the type of synthesized attributes for a rule/expression consequently, predicting what types of attributes can be legally defined as the exposed attribute for the rule (relying in builting conversions, fusion adaptors or Spirit customization points) matching the argument types for my semantic action so that the compiler will be able to compile

Spirit Qi attribute propagation issue with single-member struct

一笑奈何 提交于 2019-11-26 18:59:45
I have an compilation issue with Spirit Qi where it complains that value_type is not a member of identifier . For some reason, Qi's attribute system considers identifier to be a container type, and tries to enumerate it's value type. This is a similar issue as in this question , however, I believe the cause is the single member struct and may be related to this bug . #include <string> #include <boost/spirit/include/qi.hpp> #include <boost/fusion/include/adapt_struct.hpp> using namespace boost::spirit::qi; struct identifier { std::wstring name; }; struct problem { identifier _1; identifier _2;

How to calculate boolean expression in Spirit

て烟熏妆下的殇ゞ 提交于 2019-11-26 18:25:09
问题 I found a really good example about boolean translator, * Boolean expression (grammar) parser in c++ What I am thinking now is to do a further step, translate (!T|F)&T into F or 0 , so it is very convenient for calculating a very long boolean expression. Is there some examples about this using spirit? What I have done is making a calculator first, and then let it calculate '(T+!F*T)', which equal to (T||!F&&T) but when I type () , there is an error. How to modify it? Thanks a lot! #include

parsing into several vector members

那年仲夏 提交于 2019-11-26 18:24:52
问题 I want to recursively parse a string and store the results in one struct. I've written a parser that can handle one iteration. The input is formatted as follows: v 1.5 2.0 2.5 v 3.0 3.5 4.0 f 1 2 3 f 4 5 6 v 4.5 5.0 5.5 v 6.0 6.5 7.0 f 7 8 9 f 10 11 12 The problem is that it only parses the first 4 lines, it stops at the third encountered 'v'. The complete code is given below. How do I modify this code so it also parses the rest of the input into the same struct? I've tried modifying the

How to parse csv using boost::spirit

拥有回忆 提交于 2019-11-26 17:50:39
问题 I have this csv line std::string s = R"(1997,Ford,E350,"ac, abs, moon","some "rusty" parts",3000.00)"; I can parse it using boost::tokenizer : typedef boost::tokenizer< boost::escaped_list_separator<char> , std::string::const_iterator, std::string> Tokenizer; boost::escaped_list_separator<char> seps('\\', ',', '\"'); Tokenizer tok(s, seps); for (auto i : tok) { std::cout << i << std::endl; } It gets it right except token "rusty" should have double quotes which are getting stripped. Here is my