Skip to content

Commit

Permalink
Parse unicode escape sequences in strings
Browse files Browse the repository at this point in the history
In v0.33.0, strings can use escapes like `\u{200D}` to escape in
arbitrary unicode codepoints.
  • Loading branch information
the-mikedavis committed Dec 6, 2023
1 parent b864714 commit c63c3b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,11 @@ module.exports = grammar({
repeat(choice($.escape_sequence, $.quoted_content)),
token.immediate('"')
),
escape_sequence: ($) => token.immediate(/\\[efnrt\"\\]/),
escape_sequence: ($) =>
choice(
token.immediate(/\\[efnrt\"\\]/),
token.immediate(/\\u\{[0-9a-fA-F]{1,6}\}/)
),
float: ($) => /-?[0-9_]+\.[0-9_]*(e-?[0-9_]+)?/,
integer: ($) =>
seq(optional("-"), choice($._hex, $._decimal, $._octal, $._binary)),
Expand Down
9 changes: 9 additions & 0 deletions test/corpus/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Escape sequences
"¯\\_(ツ)_/¯"
"\"\""
"Hello, \e\f"
// 🏴‍☠️ is 🏴 and ☠️ joined with a zero-width joiner (U+200D)
"🏴‍☠️ == \u{1F3F4}\u{200D}\u{2620}\u{FE0F}"

--------------------------------------------------------------------------------

Expand All @@ -26,4 +28,11 @@ Escape sequences
(string
(quoted_content)
(escape_sequence)
(escape_sequence))
(comment)
(string
(quoted_content)
(escape_sequence)
(escape_sequence)
(escape_sequence)
(escape_sequence)))

0 comments on commit c63c3b8

Please sign in to comment.