[antlr-interest] Doesn't the lexer try rules in order?

Todd O'Bryan toddobryan at gmail.com
Sat May 7 07:06:05 PDT 2011


Can anyone explain to me why tabs, spaces, and greater-thans at the
beginning of lines are ending up in TEXT tokens, rather than in INDENT
or QUOTE tokens, as I think they should?

fragment SPECIAL_CHARS
	: ('\n' | '[' | ']' | '*' | '/' |'=' | '^' | '_' | '8' | '@' | '#' |
'$' | '!' | '(' | ')' | '{' | '}' );

INDENT 	: { getCharPositionInLine() == 0 }?=> (' '|'\t')+;
QUOTE	: { getCharPositionInLine() == 0 }?=> '>';
TEXT	: (~SPECIAL_CHARS)+;

This is in a lexer grammar and I've omitted some other rules that
shouldn't (I don't think) have any bearing on this question.

Todd


More information about the antlr-interest mailing list