parsing - Unindented code breaks my grammar -
i have .g4 grammar vba/vb6 lexer/parser, lexer skipping line continuation tokens - not skipping them breaks parser , isn't option. here's lexer rule in question:
line_continuation : ' ' '_' '\r'? '\n' -> skip; the problem causing, whenever continued line starts @ column 1, parser blows up:
sub test() debug.print "some text " & _ vbnewline & "some more text" end sub
i thought "hey know! i'll pre-process string i'm feeding antlr insert whitespace before underscore, , change grammar accept it!"
so changed rule this:
line_continuation : ws? ws '_' newline -> skip; newline : ws? ('\r'? '\n') ws?; ws : [ \t]+; ...and test vba code above gave me parser error:
extraneous input 'vbnewline' expecting ws
for solution tell users indent code. there way can fix grammar rule?
you want line continuation treated whitespace.
ok, add lexical definition of line continuation ws token. ws pick line continuation, , don't need linecontinuation anywhere.
//line_continuation : ' ' '_' '\r'? '\n' -> skip; newline : ws? ('\r'? '\n') ws?; ws : ([ \t]+)|(' ' '_' '\r'? '\n');
Comments
Post a Comment