-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding escape sequences to char literals (#514)
This change also modifies the escape sequence parsing for unicode characters to use the logic in the `Char.fromInt` prelude method, now that it exists.
- Loading branch information
Showing
25 changed files
with
145 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
val chars = "a£→😀".chars() | ||
// val chars = "a£→😀".chars() | ||
|
||
/// Expect: a 97 [0b1100001] | ||
/// Expect: £ 163 [0b11000010, 0b10100011] | ||
/// Expect: → 65515 [0b11101111, 0b10111111, 0b10101011] | ||
/// Expect: 😀 128512 [0b11110000, 0b10011111, 0b10011000, 0b10000000] | ||
for ch in chars { | ||
println(ch, ch.asInt(), ch.bytes().map(b => b.binary())) | ||
} | ||
// /// Expect: a 97 [0b1100001] | ||
// /// Expect: £ 163 [0b11000010, 0b10100011] | ||
// /// Expect: → 65515 [0b11101111, 0b10111111, 0b10101011] | ||
// /// Expect: 😀 128512 [0b11110000, 0b10011111, 0b10011000, 0b10000000] | ||
// for ch in chars { | ||
// println(ch, ch.asInt(), ch.bytes().map(b => b.binary())) | ||
// } | ||
|
||
val ch = Char.fromInt(0xD800) | ||
/// Expect: � | ||
println(ch) | ||
// val ch = Char.fromInt(0xD800) | ||
// /// Expect: � | ||
// println(ch) | ||
|
||
println(0.hex()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
'a' | ||
' ' | ||
'{' | ||
'Z' | ||
'Z' | ||
|
||
'\0' | ||
'\n' | ||
'\\' | ||
'\u00E9' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
projects/compiler/test/lexer/chars_error_invalid_unicode_seq_char.abra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'\u04x4' |
5 changes: 5 additions & 0 deletions
5
projects/compiler/test/lexer/chars_error_invalid_unicode_seq_char.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Error at %FILE_NAME%:1:2 | ||
Unsupported escape sequence: | ||
| '\u04x4' | ||
^^^^ | ||
Unicode escape sequences must be \u followed by 4 hexadecimal characters (between 0000 and 7FFF) |
1 change: 1 addition & 0 deletions
1
projects/compiler/test/lexer/chars_error_invalid_unicode_seq_eof.abra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'\u04 |
5 changes: 5 additions & 0 deletions
5
projects/compiler/test/lexer/chars_error_invalid_unicode_seq_eof.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Error at %FILE_NAME%:1:2 | ||
Unsupported escape sequence: | ||
| '\u04 | ||
^^^^ | ||
Unicode escape sequences must be \u followed by 4 hexadecimal characters (between 0000 and 7FFF) |
1 change: 1 addition & 0 deletions
1
projects/compiler/test/lexer/chars_error_invalid_unicode_seq_length.abra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'\u04' |
5 changes: 5 additions & 0 deletions
5
projects/compiler/test/lexer/chars_error_invalid_unicode_seq_length.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Error at %FILE_NAME%:1:2 | ||
Unsupported escape sequence: | ||
| '\u04' | ||
^^^^ | ||
Unicode escape sequences must be \u followed by 4 hexadecimal characters (between 0000 and 7FFF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Error at %FILE_NAME%:1:3 | ||
Unexpected character 'b': | ||
Unterminated character literal: | ||
| 'ab' | ||
^ |
1 change: 1 addition & 0 deletions
1
projects/compiler/test/lexer/chars_error_unsupported_escape_sequence.abra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'\z' |
4 changes: 4 additions & 0 deletions
4
projects/compiler/test/lexer/chars_error_unsupported_escape_sequence.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Error at %FILE_NAME%:1:2 | ||
Unsupported escape sequence: | ||
| '\z' | ||
^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'a |
4 changes: 4 additions & 0 deletions
4
projects/compiler/test/lexer/chars_error_unterminated_eof.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Error at %FILE_NAME%:1:3 | ||
Unterminated character literal: | ||
| 'a | ||
^ |
2 changes: 2 additions & 0 deletions
2
projects/compiler/test/lexer/chars_error_unterminated_newline.abra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'a | ||
' |
4 changes: 4 additions & 0 deletions
4
projects/compiler/test/lexer/chars_error_unterminated_newline.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Error at %FILE_NAME%:1:3 | ||
Unterminated character literal: | ||
| 'a | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"" "abcd" | ||
"hello wörld: 1 + 2 ! 👩🏻⚕️" | ||
"a\nb\tc\\\\nd\'e\"f\$$" | ||
"a\nb\tc\\\\nde\"f\$$" | ||
"\u007a\u306e\u77e7\ud801" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
"kind": { | ||
"name": "String", | ||
"value": "a | ||
b c\\nd'e"f$$" | ||
b c\\nde"f$$" | ||
} | ||
}, | ||
{ | ||
|
Oops, something went wrong.