[antlr-interest] Matching Last Line in ANTLR?
David-Sarah Hopwood
david-sarah at jacaranda.org
Tue Aug 18 11:43:09 PDT 2009
consiliens at gmail.com wrote:
> The last line, b., doesn't match the MC_INCORRECT token because there's
> no newline after it. Is there an easy way to match this in ANTLR?
Yes. I had the same problem when matching the end of a //-style comment,
and solved it like this:
fragment ENDOFLINE
: NEWLINE
| { input.LA(1) == EOF }?
;
(If this were a non-fragment rule, it would be a problem that it can
sometimes match no characters, but since it's a fragment, that's OK.)
--
David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
More information about the antlr-interest
mailing list