Skip to content

Antlr backend - quotation marks in bracket expressions are escaped when they shouldn't #319

Description

@fonfalleh

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions