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

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') | no next file with comments »
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 e34854fe7adacd564655429abd05a62caa2d4b20..81b1ca41d8d6bae2ea3a99eba2dae413ded30a9a 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -4479,7 +4479,7 @@ RegExpTree* RegExpParser::ParseDisjunction() {
case 'u': {
Advance(2);
uc32 value;
- if (ParseHexEscape(4, &value)) {
+ if (ParseUnicodeEscape(&value)) {
builder->AddCharacter(value);
} else {
builder->AddCharacter('u');
@@ -4732,11 +4732,10 @@ uc32 RegExpParser::ParseOctalLiteral() {
}
-bool RegExpParser::ParseHexEscape(int length, uc32 *value) {
+bool RegExpParser::ParseHexEscape(int length, uc32* value) {
int start = position();
uc32 val = 0;
- bool done = false;
- for (int i = 0; !done; i++) {
+ for (int i = 0; i < length; ++i) {
uc32 c = current();
int d = HexValue(c);
if (d < 0) {
@@ -4745,8 +4744,48 @@ bool RegExpParser::ParseHexEscape(int length, uc32 *value) {
}
val = val * 16 + d;
Advance();
- if (i == length - 1) {
- done = true;
+ }
+ *value = val;
+ return true;
+}
+
+
+bool RegExpParser::ParseUnicodeEscape(uc32* value) {
+ if (current() == '{') {
+ int start = position();
+ Advance();
+ if (ParseUnlimitedLengthHexEscape(0x10ffff, value)) {
+ if (current() == '}') {
+ Advance();
+ return true;
+ }
+ Reset(start);
+ return false;
+ }
+ // Parsing the hex number failed.
+ Reset(start);
+ return false;
+ }
+ // \u but no {
+ return ParseHexEscape(4, value);
+}
+
+
+bool RegExpParser::ParseUnlimitedLengthHexEscape(int max_value, uc32* value) {
+ int start = position();
+ uc32 val = 0;
+ int d = HexValue(current());
+ if (d < 0) {
+ Reset(start);
+ return false;
+ }
+ while (d >= 0) {
+ val = val * 16 + d;
+ Advance();
+ d = HexValue(current());
+ if (val > max_value) {
+ Reset(start);
+ return false;
}
}
*value = val;
@@ -4815,11 +4854,12 @@ uc32 RegExpParser::ParseClassCharacterEscape() {
case 'u': {
Advance();
uc32 value;
- if (ParseHexEscape(4, &value)) {
+ if (ParseUnicodeEscape(&value)) {
+ fprintf(stderr, "worked; returning code point %d\n", value);
return value;
}
- // If \u is not followed by a four-digit hexadecimal, treat it
- // as an identity escape.
+ // If \u is not followed by a legal hex decimal sequence, treat it as an
+ // identity escape.
return 'u';
}
default: {
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698