I have a .g4 grammar for vba/vb6 a lexer/parser, where the lexer is skipping line continuation tokens - not skipping them breaks the parser and isn't an option. Here's the lexer rule in question:
LINE_CONTINUATION : ' ' '_' '\r'? '\n' -> skip;
The problem this is causing, is that whenever a continued line starts at column 1, the parser blows up:
Sub Test() Debug.Print "Some text " & _ vbNewLine & "Some more text" End Sub
I thought "Hey I know! I'll just pre-process the string I'm feeding ANTLR to insert an extra whitespace before the underscore, and change the grammar to accept it!"
So I changed the rule like this:
LINE_CONTINUATION : WS? WS '_' NEWLINE -> skip;
NEWLINE : WS? ('\r'? '\n') WS?;
WS : [ \t]+;
...and the test vba code above gave me this parser error:
extraneous input 'vbNewLine' expecting WS
For now my only solution is to tell my users to properly indent their code. Is there any way I can fix that grammar rule?
WS
is used in lots of other places. What do you mean? – Moustache