
I have a pair of grammars where one is currently used purely as if it were a single rule in the second grammar. I'm finding that I want to use a second rule in the first grammar for a start rule when invoked from a particular rule in the second grammar. sort of like this: struct grammarA : public grammar<grammarA> { ... struct definition<ScannerT> { ... definition(grammarA const& self) { r_ruleOne = ... r_ruleTwo = ... ... } rule<ScannerT, parser_context<>, parser_tag<ruleOneId> > const & start() const { return r_ruleOne; } }; }; grammarA r_grammarA; struct grammarB : public grammar<grammarB> { struct definition<ScannerT> { ... definition(grammarB const& self) { r_ruleBOne = ( r_grammarA | chseq_p("foo") ); r_ruleBTwo = ( chseq_p("bar") >> ??? r_grammarA.definition.r_ruleTwo ??? ); // obviously bogus - // r_ruleBTwo is currently like the above with just r_grammarA in the second part. ... } ... }; }; Is this possible? grammar_def doesn't appear to apply here - it could work if I wanted to start the WHOLE parse at a different start node, but referenced from another grammar? I can't find any (other) appropriate wordage under "rule" or "grammar" in the spirit docs. is my example understandable? I elided a lot of "boilerplate" to keep it short... I can't separate grammarA::r_ruleTwo from grammarA, it needs other rules in grammarA. I >could< just copy the whole damn grammarA and specify a different start rule, but that just doesn't seem very elegant, no'wuddimean? Hugh Hoover Enumclaw Software

Hugh Hoover wrote: What you're asking for is definitely possible. The grammar_def is your friend here. Just refer to the rule to use as the start node as: r_grammarA.use_parser<1>() (where the 1 stands for the second argument passed to the start_parsers() function here, index is zero based, zero is the default start rule). HTH Regards Hartmut
I have a pair of grammars where one is currently used purely as if it were a single rule in the second grammar. I'm finding that I want to use a second rule in the first grammar for a start rule when invoked from a particular rule in the second grammar.
sort of like this: struct grammarA : public grammar<grammarA> { ... struct definition<ScannerT> { ... definition(grammarA const& self) { r_ruleOne = ... r_ruleTwo = ... ... } rule<ScannerT, parser_context<>, parser_tag<ruleOneId> > const & start() const { return r_ruleOne; } }; };
grammarA r_grammarA;
struct grammarB : public grammar<grammarB> { struct definition<ScannerT> { ... definition(grammarB const& self) { r_ruleBOne = ( r_grammarA | chseq_p("foo") ); r_ruleBTwo = ( chseq_p("bar") >> ??? r_grammarA.definition.r_ruleTwo ??? ); // obviously bogus - // r_ruleBTwo is currently like the above with just r_grammarA in the second part. ... } ... }; };
Is this possible? grammar_def doesn't appear to apply here - it could work if I wanted to start the WHOLE parse at a different start node, but referenced from another grammar? I can't find any (other) appropriate wordage under "rule" or "grammar" in the spirit docs.
is my example understandable? I elided a lot of "boilerplate" to keep it short...
I can't separate grammarA::r_ruleTwo from grammarA, it needs other rules in grammarA. I >could< just copy the whole damn grammarA and specify a different start rule, but that just doesn't seem very elegant, no'wuddimean?
Hugh Hoover Enumclaw Software
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Hartmut Kaiser
-
Hugh Hoover