boost spirit V2 qi bug associated with optimization level

It’s a bug in your code, nothing wrong with the compiler or the optimization levels. The cinch is with expression templates (like the ones used by Boost Proto, and hence by Boost Spirit). They are only valid to the end of their enclosing full expression [1] The canonical workaound is: BOOST_SPIRIT_AUTO(ana, *~qi::char_(‘*’) > +qi::char_(‘*’)); You … Read more

Understanding Boost.spirit’s string parser

It’s not the string matcher per se. It’s [attribute propagation] + [backtracking] in action. A string attribute is a container attribute and many elements could be assigned into it by different parser subexpressions. Now for efficiency reasons, Spirit doesn’t rollback the values of emitted attributes on backtracking. Often this is no problem at all, but … Read more

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

Spirit is a lot friendlier to compiletime-polymorphism typedef variant<Command1, Command2, Command3> Command; But, let’s suppose you really want to do the old-fashioned polymorphism thing… Just newing-up the polymorphic objects on the fly during parsing, however, is a sure-fire way to make your parser bloated with semantic actions create lot of memory leaks on back-tracking in … Read more

Assigning parsers to auto variables

Spirit Parsers are not designed to be used with auto in Spirit V2. This is because the underlying Proto expression templates hold references to the temporaries. You can use qi::copy() (existing in the trunk after boost_1_55_0, not in any released version at this time) boost::proto::deep_copy or BOOST_SPIRIT_AUTO (first coined here) I’ve written about these things … Read more

Boost spirit skipper issues

In general the following directives are helpful for inhibiting/switching skippers mid-grammar: qi::lexeme [ p ]which inhibits a skipper, e.g. if you want to be sure you parse an identifier without internal skips) – see also no_skip for comparison qi::raw [ p ]which parses like always, including skips, but returns the raw iterator range of the … Read more