Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Unified Diff: src/parser.cc

Issue 706263002: Implement ES6 unicode escapes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | src/scanner.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index c5bf0d977708df914299099f36f197a0e5b55eca..36150f73abeebaf479feeca544a2a03bc3da889e 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -4411,7 +4411,7 @@ RegExpTree* RegExpParser::ParseDisjunction() {
case 'u': {
Advance(2);
uc32 value;
- if (ParseHexEscape(4, &value)) {
+ if (ParseHexEscape(4, &value, true)) {
builder->AddCharacter(value);
} else {
builder->AddCharacter('u');
@@ -4664,11 +4664,15 @@ uc32 RegExpParser::ParseOctalLiteral() {
}
-bool RegExpParser::ParseHexEscape(int length, uc32 *value) {
+bool RegExpParser::ParseHexEscape(int length, uc32* value, bool allow_brace) {
int start = position();
uc32 val = 0;
- bool done = false;
- for (int i = 0; !done; i++) {
+ bool has_brace = false;
+ if (allow_brace && current() == '{') {
+ has_brace = true;
+ Advance();
+ }
+ for (int i = 0; i < length; ++i) {
uc32 c = current();
int d = HexValue(c);
if (d < 0) {
@@ -4677,9 +4681,13 @@ bool RegExpParser::ParseHexEscape(int length, uc32 *value) {
}
val = val * 16 + d;
Advance();
- if (i == length - 1) {
- done = true;
+ }
+ if (has_brace) {
+ if (current() != '}') {
+ Reset(start);
+ return false;
}
+ Advance();
}
*value = val;
return true;
@@ -4747,7 +4755,7 @@ uc32 RegExpParser::ParseClassCharacterEscape() {
case 'u': {
Advance();
uc32 value;
- if (ParseHexEscape(4, &value)) {
+ if (ParseHexEscape(4, &value, true)) {
return value;
}
// If \u is not followed by a four-digit hexadecimal, treat it
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | src/scanner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698