[antlr-interest] help requested for selective whitespace
Scott Amort
jsamort at sympatico.ca
Mon Feb 6 13:42:47 PST 2006
Martin Probst wrote:
> What about:
>
> note_desc
> : NOTENAME WS (OCTAVE)? WS (DURATION)? WS (DOT)?
> ;
>
> and in the Lexer
>
> WS
> : ( ' ' | '\t' | '\n' | '\r' )+;
> (no $setType(Token.SKIP) here!).
>
> This way you can explicitly ask for white space to be between your
> tokens.
>
> Martin
>
>
Hi Martin,
Thanks again for taking the time to respond. Your suggestion is much
like my first idea, looking like this:
note_desc
: NOTENAME (OCTAVE)? (DURATION)? (DOT)? WS
;
as I only need to require trailing WS after note descriptions. But, if
I allow the lexer to pass white space to the parser, I then have to
account for it in all my other rules (whitespace can be safely ignored
in all other instances). It seems a bit inelegant to me to then have to
put (WS)? all throughout my parser rules. But, perhaps that is the only
way.
Best,
Scott
More information about the antlr-interest
mailing list