[antlr-interest] ANTLR v4 progress
Terence Parr
Parrt at cs.usfca.edu
Wed May 26 16:18:28 PDT 2010
Just passing along an example HTML subset lexer/parser using ANTLR v4; thanks to debugging and moral support from Oliver Zeigermann, we got the code generation and runtime support working sufficiently to use the following grammars. generate some really nice code indeed. You will note that, except for the enhancement of the lexer modes, the grammars are backward compatible with v3 :)
I still have a long way to go, but it's looking more & more useful (only does LL(1) code generation at this point).
Ter
---------------------------
lexer grammar HTMLLexer;
TAG_START : '<' {pushMode(INSIDE);} ;
COMMENT : '<!--' .* '-->' {skip();} ;
TEXT : ~'<'+ ;
mode INSIDE;
TAG_STOP : '>' {popMode();} ;
END_TAG : '/' ID '>' {popMode();} ;
ID : ('A'..'Z'|'a'..'z'|'0'..'9'|'_'|'#')+ ;
EQ : '=' ;
STRING : '"' .* '"'
;
WS : ' '+ {skip();} ;
------------------------
parser grammar HTMLParser;
options { tokenVocab=HTMLLexer; }
file : ( TAG_START (starttag | endtag) | TEXT)+ EOF ;
starttag : ID attr* TAG_STOP ;
attr : ID (EQ (ID|STRING))? ;
endtag
: END_TAG
;
More information about the antlr-interest
mailing list