Generating Spirit parser expressions from a variadic list of alternative parser expressions

Thank you for a quick hint! I’ve just tried your code and unless I do something wrong … I get this output: Syntax error:abc 8.81 Parsed:-a atoken Syntax error:-b btoken Syntax error:-c ctoken Syntax error:-d dtoken – G. Civardi 2 hours ago Okay, so, I couldn’t leave it alone :/ Turns out there was Undefined … Read more

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

Compiling a simple parser with Boost.Spirit

Mmm. I feel that we have discussed a few more details in chat than have been reflected in the question as it is. Let me entertain you with my ‘toy’ implementation, complete with test cases, of a grammar that will recognize <<macros>> like this, including nested expansion of the same. Notable features: Expansion is done … Read more

Spirit Qi attribute propagation issue with single-member struct

This is a quite infamous edge-case in Spirit. The problem is, special-case handling of single-element Fusion Sequences in Spirit breaks some abstractions. The usual workaround is to adapt the exposed-attribute side to be less-trivial: rule<It, single_member_struct()> r = eps >> XXX; // the `eps` is there to break the spell However, here that won’t work, … 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