parsing - Unindented code breaks my grammar -


i have .g4 grammar / 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 code above gave me parser error:

extraneous input 'vbnewline' expecting ws

for solution tell users indent code. there way can fix grammar rule?

(full vba.g4 grammar file on github)

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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -