Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ module.exports = grammar({

character_literal: _ => token(seq(
'\'',
// this accepts multiple characters while java doesn't
// hence multiple characters (even unicode ones) are allowed
repeat1(choice(
/[^\\'\n]/,
/\\./,
/\\\n/,
/\\u+005[cC]./,
/\\u+005[cC]\n/,
)),
'\'',
)),
Expand Down Expand Up @@ -213,12 +217,12 @@ module.exports = grammar({
prec(1, $.escape_sequence),
),
escape_sequence: _ => token.immediate(seq(
'\\',
choice('\\', /\\u+005[cC]/),
choice(
/[^xu0-7]/,
/[0-7]{1,3}/,
/x[0-9a-fA-F]{2}/,
/u[0-9a-fA-F]{4}/,
/u+[0-9a-fA-F]{4}/,
/u\{[0-9a-fA-F]+\}/,
))),

Expand Down
14 changes: 13 additions & 1 deletion test/corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ character literals
'\uFFFF';
'\177';
'™';
'\u005cn';
'\u005c'';

---

Expand All @@ -137,6 +139,8 @@ character literals
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal))
(expression_statement (character_literal)))

===============
Expand All @@ -147,6 +151,8 @@ string literals
"\"";
"This is a string";
"'";
"\uuu0041";
"\u005c"";

---

Expand All @@ -161,7 +167,13 @@ string literals
(string_fragment)))
(expression_statement
(string_literal
(string_fragment))))
(string_fragment)))
(expression_statement
(string_literal
(escape_sequence)))
(expression_statement
(string_literal
(escape_sequence))))

===============
text block
Expand Down