Skip to content
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

Relatively small Unicode wins #290

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Ensure Unicode escapes can't be used in character classes yet
  • Loading branch information
hildjj committed Jul 30, 2022
commit a919ab322b86bbf3c5dac5e4accbb9d311f13ae6
112 changes: 75 additions & 37 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ IdentifierStart
/ "$"
/ "_"
/ "\\" @UnicodeEscapeSequence
/ "\\" @ExtendedUnicodeEscapeSequence

IdentifierPart
= IdentifierStart
Expand Down Expand Up @@ -329,12 +330,12 @@ StringLiteral "string"

DoubleStringCharacter
= $(!('"' / "\\" / LineTerminator) SourceCharacter)
/ "\\" @EscapeSequence
/ "\\" @ExtendedEscapeSequence
/ LineContinuation

SingleStringCharacter
= $(!("'" / "\\" / LineTerminator) SourceCharacter)
/ "\\" @EscapeSequence
/ "\\" @ExtendedEscapeSequence
/ LineContinuation

CharacterClassMatcher "character class"
Expand Down Expand Up @@ -372,6 +373,10 @@ ClassCharacter
LineContinuation
= "\\" LineTerminatorSequence { return ""; }

ExtendedEscapeSequence
= EscapeSequence
/ ExtendedUnicodeEscapeSequence

EscapeSequence
= CharacterEscapeSequence
/ "0" !DecimalDigit { return "\0"; }
Expand Down Expand Up @@ -411,7 +416,9 @@ UnicodeEscapeSequence
= "u" digits:$(HexDigit HexDigit HexDigit HexDigit) {
return String.fromCharCode(parseInt(digits, 16));
}
/ "u{" digits:$HexDigit+ "}" {

ExtendedUnicodeEscapeSequence
= "u{" digits:$HexDigit+ "}" {
// String.fromCodePoint() is not supported in IE11.
let codepoint = parseInt(digits, 16);
if (codepoint > 0x10FFFF) {
Expand Down