Skip to content

Commit

Permalink
fix unicode in identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Protryon committed May 1, 2019
1 parent 7e0f66b commit 2636f20
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,16 @@ private Maybe<String> eatUnicodeOrCharacter() {
return Maybe.empty();
}
return this.backtrackOnFailureMaybe(state -> {
int characterValue;
if (state.match("\\u")) {
state.skipCodePoint();
Maybe<Integer> maybeCharacterValue = acceptUnicodeEscape(state);
if (!maybeCharacterValue.isJust()) {
return Maybe.empty();
}
characterValue = maybeCharacterValue.fromJust();
} else {
characterValue = pattern.codePointAt(state.index);
state.index += Character.toChars(characterValue).length;
return maybeCharacterValue.map(value -> new String(Character.toChars(value)));
}
Maybe<String> character = state.nextCodePoint();
if (character.isJust()) {
state.skipCodePoint();
}
String character = new String(Character.toChars(characterValue));
return Maybe.of(character);
return character;
});
}

Expand Down Expand Up @@ -663,7 +659,7 @@ private Maybe<Integer> acceptUnicodeEscape(State superState) {
}
int value = Integer.parseInt(hex, 16);

if (value >= 0xD800 && value <= 0xDBFF) {
if (this.unicode && value >= 0xD800 && value <= 0xDBFF) {
Maybe<Integer> surrogatePairValue = state.backtrackOnFailureMaybe(subState -> {
if (!subState.eat("\\u")) {
return Maybe.empty();
Expand Down

0 comments on commit 2636f20

Please sign in to comment.