I am trying to parse input files that have a bad structure because usually a newline is skipped, yet in some cases it is used to terminate a statement, so, sometimes it must be matched. Yet in this case, a newline seems to become a normal token in general and cannot be skipped.
To illustrate my problem consider the following grammar:
text
: (line '\n')+
;
line
: ( ID )+
| '(' ID* ')'
;
ID : [a-zA-Z]+
;
WS : [ \t\n\r]+ -> skip
;
In this grammar I would like to parse statements like the following:
a b
c d
(e
f)
Yet I get the following error:
line 3:2 extraneous input '\n' expecting {')', ID}
because the newline inside the brackets is not skipped. The grammar itself is much more complicated, hence it is not possible to simply put "'\n'?" everywhere where it is needed.
What is the best way to deal with this issue?