[antlr-interest] Re: skiping the rest of a line

Xue Yong Zhi seclib at seclib.com
Mon Feb 6 14:52:28 PST 2006


> I tried the following and it works but this gives me a nondeterministic
> warning, which it understandable because matched everything but newline
> characters.
> 
> IGNORE: ':'(~('\n'|'\r'))* ('\n'|'\r'('\n')?){$setType(Token.SKIP);
> newline();};
> 

I guess the warning comes from here:
('\n'|'\r'('\n')?)

If I am right, you have a public lexer rule(probabally called 
LINE_BREAK) which matches '\n'. Since antlr assumes "whatever followes" 
when computing the exit branch, it does not know if '\n' followed by 
'\r' should be matched right away, or matched as another token(LINE_BREAK).

In your case, you do want the lexer be greedy, so just add the following:
('\n'|'\r'(options {greedy=true;} :'\n')?)

-- 
Xue Yong Zhi
http://seclib.blogspot.com



More information about the antlr-interest mailing list