I have the following line that I want to combine with the rule, stringLiteral:
"D:\\Downloads\\Java\\MyFile"
And my grammar is a file: String.g4, as shown below:
grammar String; fragment HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ; stringLiteral : '"' ( EscapeSequence | XXXXX )* '"' ; fragment EscapeSequence : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | UnicodeEscape | OctalEscape ; fragment OctalEscape : '\\' ('0'..'3') ('0'..'7') ('0'..'7') | '\\' ('0'..'7') ('0'..'7') | '\\' ('0'..'7') ; fragment UnicodeEscape : '\\' 'u' HexDigit HexDigit HexDigit HexDigit ;
What should I put in XXXXX to match any character that is not \ or "?
I tried the following and it all does not work:
~['\\'"'] ~['\\'\"'] ~["\] ~[\"\\] ~('\"'|'\\') ~[\\\"]
I am using ANTLRWorks 2 to try this. Errors are as follows:
D:\Downloads\ANTLR\String.g4 line 26:5 mismatched character '<EOF>' expecting '"' error(50): D:\Downloads\ANTLR\String.g4:26:5: syntax error: '<EOF>' came as a complete surprise to me while looking for rule element
source share