[antlr-interest] [solved] newbie: are selective lexer rules (depending on where in grammar parser is) possible?
Vladimir Konrad
vladimir at ok2home.net
Wed Mar 25 06:33:38 PDT 2009
Hello,
Well, this works. It obviously takes a time to get used to writing
grammars for ANTLR.
Here is the grammar which does much better:
content : block* EOF ;
block : BEGIN TIME_STAMP? record* END ;
record : BEGIN_RECORD assignment+ END_RECORD ;
assignment
: (ASSIGNMENT_LHS ASSIGNMENT_RHS) ;
BEGIN_RECORD
: BEGIN SUFFIX '\r'? '\n' ;
END_RECORD
: (END_RECORD) => END SUFFIX '\r'? '\n' ;
SUFFIX : SEPARATOR LETTER+ ;
BEGIN : '/begin' ;
END : '/end' ;
SEPARATOR
: '-' ;
TIME_STAMP
: 'time-stamp:' ' '+ DIGIT+ (SEPARATOR DIGIT+)+ ;
LETTER : 'a'..'z' | 'A'..'Z' ;
DIGIT : '0'..'9' ;
ASSIGNMENT_RHS
: '=' (options {greedy=false;} : . )+ '\r'? '\n' ;
ASSIGNMENT_LHS
: (~( '=' | ' ' | '\r' | '\n'))+ ;
Kind regards,
Vlad
More information about the antlr-interest
mailing list