Antlr4: Escape quotes

Created on 15 May 2017  Â·  6Comments  Â·  Source: antlr/antlr4

The following worked in version 4.5.3, but not in 4.7:

grammar SymbolStructure;
document : '\"';

The error is invalid escape sequence. If I remove the backslash, then the grammar builds.

I have a larger grammar which uses an escaped quote. Removing the backslash leads ANTLR to fail at runtime to

File "...\site-packages\antlr4\atn\ATNDeserializer.py", line 118, in checkUUID
    " (expected " + str(SERIALIZED_UUID) + " or a legacy UUID).", uuid, SERIALIZED_UUID)
Exception: ('Could not deserialize ATN with UUID: 59627784-3be5-417a-b9eb-8131a7286089 (expected 
aadb8d7e-aeef-4415-ad2b-8204d6cf042e or a legacy UUID).', UUID('59627784-3be5-417a-b9eb-
8131a7286089'), UUID('aadb8d7e-aeef-4415-ad2b-8204d6cf042e'))

The same grammar builds and runs fine with 4.5.3.

Most helpful comment

@parrt I believe this can be closed. The "invalid escape sequence" warning is fixed by removing unnecessary backslashes, and the UUID error at runtime is resolved by using the same (matching) version of the ANTLR tool and runtime library.

All 6 comments

It's a warning, not error. Just remove useless escape literal: '\"' to '"' and it will work fine.
Can you add a full grammar or grammar fragment where generation fails?

antlr4.7 has the same error, remove backslash fail too.

the 2 issues are unrelated
the UUID error is cause by incompatible tool and runtime version
use the latest tool and runtime from pypi

Le 15 mai 2017 à 21:14, Kalle Rutanen notifications@github.com a écrit :

The following worked in version 4.5.3, but not in 4.7:

grammar SymbolStructure;
document : '\"';
The error is invalid escape sequence. If I remove the backslash, then the grammar builds.

I have a larger grammar which uses an escaped quote. Removing the backslash leads ANTLR to fail at runtime to

File "...\site-packages\antlr4\atn\ATNDeserializer.py", line 118, in checkUUID
" (expected " + str(SERIALIZED_UUID) + " or a legacy UUID).", uuid, SERIALIZED_UUID)
Exception: ('Could not deserialize ATN with UUID: 59627784-3be5-417a-b9eb-8131a7286089 (expected
aadb8d7e-aeef-4415-ad2b-8204d6cf042e or a legacy UUID).', UUID('59627784-3be5-417a-b9eb-
8131a7286089'), UUID('aadb8d7e-aeef-4415-ad2b-8204d6cf042e'))
The same grammar builds and runs fine with 4.5.3.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/antlr/antlr4/issues/1871, or mute the thread https://github.com/notifications/unsubscribe-auth/ADLYJHh5fg-2p_-jivKP3L4j-RS_RyKvks5r6E_BgaJpZM4NbHc1.

I got the warning too: invalid escape sequence '\''

fragment ESC        : '\\' ([\'\\/bfnrt] | UNICODE) ;
String              : '\'' (ESC | ~[\'\\])* '\'';

What is wrong here?

Remove escaping for single quotes: \' to '. They are useless for [] blocks.

@parrt I believe this can be closed. The "invalid escape sequence" warning is fixed by removing unnecessary backslashes, and the UUID error at runtime is resolved by using the same (matching) version of the ANTLR tool and runtime library.

Was this page helpful?
0 / 5 - 0 ratings