[antlr-interest] C-style includes: problem with parser vs. lexer rules
Bjoern Doebel
doebel at tudos.org
Mon Aug 27 06:37:55 PDT 2007
Hi,
Johannes Luber wrote:
> My guess is that FNAME should be a parser rule, not a lexer rule. Or
> WORD hat do be changed into a fragment rule.
Thanks. I already had it working with FNAME being a parser rule and
changing WORD to a fragment also made it work the other way round. However,
this is kind of inconvenient, because if WORD is a fragment rule, it cannot
be used from parser rules directly, unless I duplicate a rule and have it
as a fragment and a normal lexer rule:
fragment DIGIT : '0'..'9';
fragment CHAR : 'a'..'z' | 'A'..'Z';
IMPORT : ''#include' ;
GT : '>' ;
LT : '<' ;
WS : (' '|'\t'|'\n'|'\r')+ { self.skip(); } ;
WORD : CHAR (CHAR|DIGIT|'_')*;
fragment WORD2 : CHAR (CHAR|DIGIT|'_')*;
FNAME : WORD2 ('/' WORD2)* '.' WORD2 ;
import_r : IMPORT LT f=FNAME GT;
stat : w=WORD+ ';' ;
entry : (import_r | stat)+
;
Can we improve this?
Sincerely,
Bjoern
More information about the antlr-interest
mailing list