I cannot find anything on this except ominous hints that it might be entirely impossible, but I don't want to simply believe it since lazy parsers would seem so useless in that case. What I want to do is choose a parser at parse-time depending on the result of some previous non-terminal. It essentially boils down to:
static rule<Constant *(Scope &)> &get_constant_parser(Typename type);
rule<Constant *(Scope &, Typename)> constant {
lazy(phoenix::bind(&get_constant_parser, _r2))(_r1)
};
So get_constant_parser
returns a parser fitting the given type name, however that parser requires an argument of type Scope &
. So intuitively, I'd write that down as above, adding the argument to the lazy parser. However that gives me an invalid expression:
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:177:13: error: static assertion failed: error_invalid_expression
BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
^~~~~~~~~~~~~~~~~~~~~~~~~
So how do I give arguments to a lazy parser? If it is indeed impossible, then does anyone have an idea why?
Sorry this is not a proper MWE, right now I'm hoping that someone has done it before and just knows the answer. Please let me know if you want to actively investigate and need an MWE ;-)