Boost logo

Boost :

From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2005-09-18 14:56:34


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk