[antlr-interest] Does it make sense a "fragment parser rule"?

Alex Shneyderman a.shneyderman at gmail.com
Sun Aug 19 00:20:03 PDT 2007


I guess the problem Corellian has is that even if you declare the
parser rule as fragment the corresponding method of the parser is
still public (v3.0 from May). I think it makes sense to have those
fragments for parsers as often I create a rule for as a predicate
only. Obviously no class but the parser itself should ever call it.

On 8/19/07, Gavin Lambert <antlr at mirality.co.nz> wrote:
> At 13:05 19/08/2007, Corellian wrote:
>  >Here a (probably) stupid question:
>  >
>  >When I'm writing a parser rule like:
>  >
>  >   identifierList: ID (COMMA ID)* ;
>  >
>  >and then, another parser rule like:
>  >
>  >   variableDeclaration: type identifierList SEMI ;
>  >
>  >does it make sense declaring the "identifierList" as a
> "fragment"
>  >rule?
>
> It doesn't make any difference to ANTLR itself (fragment rules
> only change behaviour in the lexer, not the parser), but depending
> on your target language making a parser rule a fragment can turn
> it into a private (or otherwise hidden a bit more) method, thus
> making it harder to accidentally call from your main app.  So you
> may find it useful, but it's totally up to you :)
>
>


-- 
Thanks,
Alex.


More information about the antlr-interest mailing list