[antlr-interest] Handling optional spaces

Gavin Lambert antlr at mirality.co.nz
Mon Oct 8 00:38:17 PDT 2007


At 14:46 8/10/2007, Justin Crites wrote:
>expr     :    OptSpace ID OptSpace;
>
>OptSpace :    ' '*;

Lexer rules must never have a path that can match nothing.  This 
leads to infinite loops.  And madness.  Change your OptSpace rule 
to use + (and probably rename it to Space, since it's no longer 
optional) and then use ? against it in the parser rule to indicate 
that it's optional.  Or (if whitespace is unimportant at the 
parser level), just skip it or put it on the hidden channel -- 
then you won't need to refer to it at all.



More information about the antlr-interest mailing list