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

Gavin Lambert antlr at mirality.co.nz
Sat Aug 18 23:25:25 PDT 2007


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 :)



More information about the antlr-interest mailing list