I am writing a parser in ANTLR using C# for a language which allows a line of syntax to be split over multiple lines using the back slash to indicate there are subsequent lines. This is further complication by the ability to add a comment to any line of code. e.g I can write something like
If ((A = B) AND :Check A and B
(C <> D)) :Check C and D
Add 1 Count
End
i.e the If statement is split over two lines but also has a comment on both lines. The break can be anywhere in the line of syntax, so could equally write
If ((A = B) :Check A and B
AND (C <> D)) :Check C and D
Add 1 Count
End
Currently I am treating the back slash as white space and ignoring it.
WS : [ ()\trnf;]+ -> channel(HIDDEN);
My definition for a boolean is
// Boolean Expressions
booleanCondition : booleanExpression | '(' booleanExpression ')';
booleanExpression : expression ('='|'<>'|'<'|'>') expression ((AND|OR|'&&'|'||') booleanExpression)*;
and a comment is
COMMENT : ':'+ ~[:=rn]*;
When I parse the example code it almost gets things right, but misses the first comment completely and parses the second comment as a ErrorNode. Is there any way I can do this in ANTLR without writing some form of pre-parser?
Any advice would be much appreciated