It seems the only characters that should be escaped in bracket expressions in regexes are ], \, and -. I'm not sure if this means that there needs to be different escaping in different contexts.
https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#lexer-rule-elements
Example token rule that generates broken code (not by any means good or correct, I just noticed that the resulting lexer file doesn't work) :
token NoteToken ["abcdefgr"]({"es"} | {"is"})*["\',"]*(digit)*["."]* ;
results in the following line in the Lexer.g4 file
NoteToken : [abcdefgr]('e''s'|'i''s')*[\',]*DIGIT*'.'*;
which generates the following when building:
warning(156): lily/lilyLexer.g4:83:38: invalid escape sequence \'
The build also complains about the following line:
STRINGTEXT : ~[\"\\] -> more;
|
, "STRINGTEXT : ~[\\\"\\\\] -> more;" |
The build works as expected when removing the extra backslashes as follows:
NoteToken : [abcdefgr]('e''s'|'i''s')*[',]*DIGIT*'.'*;
...
STRINGTEXT : ~["\\] -> more;
Sidenote:
I first thought this could be related to this line, referencing RegToJLex.hs instead of RegToAntlrLexer.hs, but it seems the reference is correct, even if it's confusing naming.
|
[ text name <> " : " <> text (printRegJLex exp) <> ";" |
Export from RegToAntlrLexer:
|
module BNFC.Backend.Java.RegToAntlrLexer (printRegJLex, escapeChar) where |
It seems the only characters that should be escaped in bracket expressions in regexes are
],\, and-. I'm not sure if this means that there needs to be different escaping in different contexts.https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#lexer-rule-elements
Example token rule that generates broken code (not by any means good or correct, I just noticed that the resulting lexer file doesn't work) :
token NoteToken ["abcdefgr"]({"es"} | {"is"})*["\',"]*(digit)*["."]* ;results in the following line in the Lexer.g4 file
NoteToken : [abcdefgr]('e''s'|'i''s')*[\',]*DIGIT*'.'*;which generates the following when building:
warning(156): lily/lilyLexer.g4:83:38: invalid escape sequence \'The build also complains about the following line:
STRINGTEXT : ~[\"\\] -> more;bnfc/source/src/BNFC/Backend/Java/CFtoAntlr4Lexer.hs
Line 157 in 3ca7211
The build works as expected when removing the extra backslashes as follows:
NoteToken : [abcdefgr]('e''s'|'i''s')*[',]*DIGIT*'.'*;...
STRINGTEXT : ~["\\] -> more;Sidenote:
I first thought this could be related to this line, referencing RegToJLex.hs instead of RegToAntlrLexer.hs, but it seems the reference is correct, even if it's confusing naming.
bnfc/source/src/BNFC/Backend/Java/CFtoAntlr4Lexer.hs
Line 150 in 3ca7211
Export from RegToAntlrLexer:
bnfc/source/src/BNFC/Backend/Java/RegToAntlrLexer.hs
Line 1 in 3ca7211