[antlr-interest] Newlines (yet again)
David Wigg
wiggjd at lsbu.ac.uk
Tue Jan 18 05:49:38 PST 2005
With reference to this message,
Message: 5
Date: Mon, 17 Jan 2005 21:08:22 -0800 (PST)
From: "Paul J. Lucas" <pauljlucas at mac.com>
Subject: [antlr-interest] Newlines (yet again)
To: ANTLR Interest <antlr-interest at antlr.org>
Message-ID:
<Pine.LNX.4.44.0501172106110.17600-100000 at g4.pauljlucas.org>
Content-Type: TEXT/PLAIN; charset=US-ASCII
A while ago, I mentioned that I do:
('\r')? '\n' { newline(); }
to match newlines. It seems to be the case that explicitly
testing for the '\r' is unnecessary: if a '\n' is required, who
cares what the character immediately before it is? So this can
simply be:
'\n' { newline(); }
and it will work on both *nix and Windows, right?
- Paul
I have the following comments to make;
Admittedly I have not seen any previous correspondence on this
subject but I don't see how you can ignore the possibility of a
'\r' appearing here.
In any case I don't think it will work on a Mac file, or has
this been changed now?
I use the following following for C++ which I believe is simple
and comprehensive.
Whitespace
: ( (' ' |'\t' | '\f')
// handle newlines
| ( "\r\n" // MS
| '\r' // Mac
| '\n' // Unix
) {newline();}
// handle continuation lines
| ( "\\\r\n" // MS
| "\\\r" // Mac
| "\\\n" // Unix
) {deferredNewline();}
)
{_ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP;}
;
David.
More information about the antlr-interest
mailing list