[antlr-interest] Parsing whole-line comments?

Christian Convey christian.convey at gmail.com
Sat Jun 5 19:41:05 PDT 2010


I'm new to ANTLR, and I'm having trouble designing a lexicon and
grammar for what I think is really simple.  The DSL I'm dealing with
is mostly line-oriented, where the first character of a line indicates
what kind of thing the line is.  Example:

C This is a test.
E 1 2 3
C Previous line (# 2) was an "edge" line.

Lines starting with 'C' are comment lines, in which all characters
after the 'C' until the end-of-line are comment text that I want the
parser to report.

If I was using standard regular expressions to represent my tokens, I
would define a "comment" token something like this:
  ^C.*$

That is, <beginning of line> <the letter C> <zero or more
non-end-of-line characters> <end-of-line>

My problem is, to my knowledge ANTLR won't let me define tokens that
match on the beginning of a line ('^').

Any suggestions?


More information about the antlr-interest mailing list