parsing - how to parse string of SQL contain ESCAPE in ANTLR4? -


there 2 escape type in sql: \' , '' input may like:

 select '\'', ''''; 

i parse string grammar:

string_literal  : '\'' ( '\\\'' | '\'\'' | ~'\'' )* '\''  ; 

but antlr parse input error, tree this: error parsed tree

i tried type of string_literal grammar greedy: "?":

string_literal  : '\'' ( '\\\'' | '\'\'' | ~'\'' )*? '\'' ; 

but give me error parse resule this: error parsed tree in grammar '''' should parsed string contain not 2 empty string.

how should modify grammar fix problem?

you didn't exclude \ in ( ... )*. try this:

string_literal  : '\'' ( '\\\'' | '\'\'' | ~['\\] )* '\''  ; 

where ~['\\] matches char except ' , \. may want include line break chars in it: ~[\r\n'\\].


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -