parsing into several vector members

There are several ways đŸ™‚ Custom attribute traits The same using semantic actions Everything in semantic actions, at detail level 1. Custom attribute traits The cleanest, IMO would to replace the Fusion Sequence Adaptation (BOOST_FUSION_ADAPT_STRUCT) by custom container attribute traits for Spirit: namespace boost { namespace spirit { namespace traits { template<> struct is_container<ElemParseData, void> … Read more

How to benchmark Boost Spirit Parser?

I have given things a quick scan. My profiler quickly told me that constructing the grammar and (especially) the lexer object took quite some resources. Indeed, just changing a single line in SpiritParser.cpp saved 40% of execution time1 (~28s down to ~17s): lexer::Lexer lexer; into static const lexer::Lexer lexer; Now, making the grammar static involves … Read more

How to parse csv using boost::spirit

For a background on parsing (optionally) quoted delimited fields, including different quoting characters (‘, “), see here: Parse quoted strings with boost::spirit For a very, very, very complete example complete with support for partially quoted values and a splitInto(input, output, ‘ ‘); method that takes ‘arbitrary’ output containers and delimiter expressions, see here: How to … 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

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

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