Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape quotes #1871

Closed
kaba2 opened this issue May 15, 2017 · 6 comments
Closed

Escape quotes #1871

kaba2 opened this issue May 15, 2017 · 6 comments

Comments

@kaba2
Copy link

kaba2 commented May 15, 2017

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.

@KvanTTT
Copy link
Member

KvanTTT commented May 15, 2017

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?

@zhouqilin1993
Copy link

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

@ericvergnaud
Copy link
Contributor

ericvergnaud commented Feb 11, 2018 via email

@viceice
Copy link
Contributor

viceice commented Jul 15, 2019

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

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

What is wrong here?

@KvanTTT
Copy link
Member

KvanTTT commented Jul 15, 2019

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

@sharwell
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants