[antlr-interest] Both hidden and required whitespace
Kaleb Pederson
kaleb.pederson at gmail.com
Thu May 8 11:48:42 PDT 2008
I must have impeccable timing giving the recent conversation, but
assuming I can't avoid having some whitespace requirements, how's do I
best handle requiring whitespace at certain locations, but not at
others?
Here's my attempt and testcase:
expr: 'one' 'two' COLON (INDENT 'numbers')*;
COLON: ':';
fragment INDENT: '\n' (' '|'\t')*;
WS: (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;};
And my input:
one two :
numbers
numbers
When I interpret the above, I get the following:
% java org.antlr.tool.Interp Test.g 'WS' expr test_input.txt
(<grammar Test> (expr one two : NoViableAltException(9!=[()* loopback
of 19:25: ( INDENT 'numbers' )*])))
where Token 9 is 'numbers'. I presume that WS is consuming the INDENT
and thus I'm not seeing it in the stream. I know I read somewhere
that I could get access to the hidden tokens in the actions, but I'd
like to be able to express the required whitespace at that location in
the grammar.
Suggestions?
Thanks.
--Kaleb
More information about the antlr-interest
mailing list