tags:

views:

15

answers:

1

ANTLR gives me the following error when my input file has either no newline at the EOF, or more than one.

line 0:-1 mismatched input '' expecting NEWLINE

How would I go about taking into account the possibilities of having multiple or no newlines at the end of the input file. Preferably I'd like to account for this in the grammar.

A: 

The rule:

parse
  :  (Token LineBreak)+ EOF
  ;

only parses a stream of tokens, separated by exactly one line break, ending with exactly one line break.

While the rule:

parse
  :  Token (LineBreak+ Token)* LineBreak* EOF
  ;

parses a stream of tokens separated by one or more line breaks, ending with zero, one or more line breaks.

But do you really need to make the line breaks visible in the parser? Couldn't you put them on a "hidden channel" instead?

If this doesn't answer your question, you'll have to post your grammar (you can edit your original question for that).

HTH

Bart Kiers