From: Hugh Hoover (hugh_at_[hidden])
Date: 2005-09-18 00:02:56


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