Skip to content

Various fixes for parsing string and char literals #210

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

theawless
Copy link

Fix unicode backslash escaped double quote in string and char literals

Closes #209

As described in JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.2, the translation for unicode escapes happens before parsing. Hence this is allowed:

Original: '\u005c''
After Unicode escape processing: '\''
Final interpretation: a char literal containing a single quote character

To handle this behaviour I've updated the existing rules such that wherever \\ was accepted \u005c is also accepted.

Allow multiple u chars in unicode escapes within string literals

Closes #207

I feel it's weird but it is mentioned in the JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.2:~:text=If%20an%20eligible%20%5C%20is%20followed%20by%20u%2C%20or%20more%20than%20one%20u%2C%20and%20the%20last%20u%20is%20not%20followed%20by%20four%20hexadecimal%20digits%2C%20then%20a%20compile%2Dtime%20error%20occurs - there can be multiple u after \u as long as the 4 hex digits come at the end.

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

Successfully merging this pull request may close these issues.

Parsing error for unicode escape in char/string literals Parsing error for unicode in string literals
1 participant