I am about to write a parser for a mathematica-like language and have found out, that it would be nice to sometimes invoke my spirit grammar for subparts of the expression to parse.
i.e. If I am about to parse
a+b*c+d
it would be handy to call parse()
on the 'b*c' part while querying the '+' sign.
Is this possible to do while using the same instance of my grammar? (The grammar parameter would be '*this')
Though I am not yet fully convinced whether this is the best way to accomplish this particular task, I find the question rather interesting, since I could not find anything in the docs.
Obvously I should not depend on class-local or global variables if I used this technique. But I would like to know if it is principally allowed by the design of spirit.
EDIT:
My grammar instances look as follows:
class MyGrammar : public boost::spirit::qi::grammar<...>
{
/* a few rules. Some with local and/or inherited attributes */
MyGrammar( void )
{
/* assign all the rules, use a few 'on_error' statements */
// In one or two rules I would like to invoke parse(...,*this,...)
// on a subrange of the expression
}
}
Thanks!