[antlr-interest] Whitespace matching

Jason Jones jmjones5 at gmail.com
Thu Apr 12 09:43:50 PDT 2012

Hi ANTLR reading list,

I'm fairly new to ANTLR, and all it's oddities, and I'm having issues with
whitespace matching. I have a file which begins with "\r\n" and everytime I
try to run my parser over the file I get the error "line 1:0 mismatched
input '\r\n' expecting WHITESPACE" however since both '\r' and '\n' are in
the WHITESPACE rule and allowing it to be 0 or more over all alternatives I
would expect it to match '\r\n'. I do find that replacing the first
WHITESPACE occurrence with '\r\n' does work but I'm trying to understand
why this way doesn't.

Here are the rules in questions:

start : program ;

WHITESPACE  : (' ' | '\t' | '\r' | '\n')* ; //currently only used in string

Thanks for any help in advance!


More information about the antlr-interest mailing list