-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Parser: add missing escape sequence for Char #5075
Parser: add missing escape sequence for Char #5075
Conversation
Add `\xFF` and `\100` style escape sequence for `Char`
when 'u' | ||
value = consume_char_unicode_escape | ||
@token.value = value.chr | ||
when '0' | ||
@token.value = '\0' | ||
when '0', '1', '2', '3', '4', '5', '6', '7' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use '0'..'7'
?
This was removed on purpose, the x escape is incorrect for chars. For example \xff is not a valid unicode codepoint. |
Same goes with octal. This was removed explicitly by me some months ago. Let's not add it back. |
related to #2886 |
Why? |
This is also about character escape codes and you suggested to maybe remove |
@straight-shoota Thank you. @asterite I can't understand "for example \xff is not a valid unicode codepoint" because U+00FF points 'LATIN SMALL LETTER Y WITH DIAERESIS' and I consider |
In a String, "\xff" will generate a string with one byte whose value is 255. That's not a valid UTF-8 string but it's valid as just a sequence of bytes (there's a big discussion on whether this should be allowed or not, or maybe just allowed in Slice(UInt8) literals, but that doesn't exist yet). But a Char is an Int32 that holds an UTF-8 codepoint. A byte value and a codepoint are different things. It's a bit confusing, and in the original implementation '\xff' did generate 'ÿ', but that's wrong. |
Another way to show it. Using this PR, do this: "\xFF"[0] == '\xFF' You will see that is |
@asterite Good example! |
The compiler accepts this code:
But the compiler does not accept this:
And
\100
style escape sequence has same issue.This PR adds
\xFF
(hex) and\100
(octal) style escape sequence forChar
.