[antlr-interest] Antlr 3 and the newline token problem

Martin Probst mail at martin-probst.com
Fri Nov 25 15:28:35 PST 2005


Am Freitag, den 25.11.2005, 20:58 +0000 schrieb Micheal J:
> Please don't post HTML mail to the list. 

Yeah, please don't do that. You too ;-)

> WS : '\r' '\n' {newline();}
>        | '\r'    {newline();}
>        | '\n'   {newline();}
>      ;

What about

NL: (('\r' ( '\n' /* Windows */ | /* empty, MAC OS <=9 */ )
    ) | '\n' /* the proper way ... */ ) { newline(); };

(untested, but works, doesn't it?).

It's a documentation issue, just put it into a prominently linked FAQ.
Also tell people which method to override in case they want to count
from 0 (e.g. "return super.getLine() - 1;").

I would opt against doing the newline magic behind the scenes
automagically. Doing newlines properly is a good exercise to get started
with ANTLR, and those who can't get it to work with some documentation
have much bigger problems. On the other hand, there are people parsing
binary files (line what?), people using Eclipse (that's the offset
people ;-)), people who want to provide proper line/column numbers to
users. It's easy to do all of these, just some minor Java work. IMHO
ANTLR should keep out of that business.

Martin



More information about the antlr-interest mailing list