[antlr-interest] Tried of dealing with '\r' and '\n' ?

Terence Parr parrt at cs.usfca.edu
Wed Jul 28 12:19:32 PDT 2004


On Jul 28, 2004, at 12:11 PM, thrutchy wrote:

> I got a little tired of dealing with carriage returns and
> newlines/linefeeds in the lexer, so I did these two things:
>
> 1. Filter the Reader through LineNumberReader to convert things to
> unix-style (simple '\n').  For example:
>
> lexer = new myLexer(new LineNumberReader(new FileReader(name)));
>
> 2. Override consume in your lexer to automatically call newline() like
> it already calls tab().  Here's what I did:
>
>     public void consume() throws CharStreamException {
>         if (inputState.guessing==0 && LA(1)=='\n') newline();
>         super.consume();
>     }

A very nice combination!

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list