Commit 45850f40 authored by yangguo's avatar yangguo Committed by Commit bot

[regexp] simplify unicode flag check.

It's sufficient to check for --harmony-unicode-regexps when parsing the
regexp flags from string.

R=neis@chromium.org

Review URL: https://codereview.chromium.org/1567413002

Cr-Commit-Position: refs/heads/master@{#33178}
parent 43d45493
...@@ -343,7 +343,7 @@ RegExpTree* RegExpParser::ParseDisjunction() { ...@@ -343,7 +343,7 @@ RegExpTree* RegExpParser::ParseDisjunction() {
// escaped, // escaped,
// no other identity escapes are allowed. If the 'u' flag is not // no other identity escapes are allowed. If the 'u' flag is not
// present, all identity escapes are allowed. // present, all identity escapes are allowed.
if (!FLAG_harmony_unicode_regexps || !unicode_) { if (!unicode_) {
builder->AddCharacter(first_digit); builder->AddCharacter(first_digit);
Advance(2); Advance(2);
} else { } else {
...@@ -404,7 +404,7 @@ RegExpTree* RegExpParser::ParseDisjunction() { ...@@ -404,7 +404,7 @@ RegExpTree* RegExpParser::ParseDisjunction() {
uc32 value; uc32 value;
if (ParseHexEscape(2, &value)) { if (ParseHexEscape(2, &value)) {
builder->AddCharacter(value); builder->AddCharacter(value);
} else if (!FLAG_harmony_unicode_regexps || !unicode_) { } else if (!unicode_) {
builder->AddCharacter('x'); builder->AddCharacter('x');
} else { } else {
// If the 'u' flag is present, invalid escapes are not treated as // If the 'u' flag is present, invalid escapes are not treated as
...@@ -418,7 +418,7 @@ RegExpTree* RegExpParser::ParseDisjunction() { ...@@ -418,7 +418,7 @@ RegExpTree* RegExpParser::ParseDisjunction() {
uc32 value; uc32 value;
if (ParseUnicodeEscape(&value)) { if (ParseUnicodeEscape(&value)) {
builder->AddCharacter(value); builder->AddCharacter(value);
} else if (!FLAG_harmony_unicode_regexps || !unicode_) { } else if (!unicode_) {
builder->AddCharacter('u'); builder->AddCharacter('u');
} else { } else {
// If the 'u' flag is present, invalid escapes are not treated as // If the 'u' flag is present, invalid escapes are not treated as
...@@ -434,8 +434,7 @@ RegExpTree* RegExpParser::ParseDisjunction() { ...@@ -434,8 +434,7 @@ RegExpTree* RegExpParser::ParseDisjunction() {
// other identity escapes are allowed. If the 'u' flag is not // other identity escapes are allowed. If the 'u' flag is not
// present, // present,
// all identity escapes are allowed. // all identity escapes are allowed.
if (!FLAG_harmony_unicode_regexps || !unicode_ || if (!unicode_ || IsSyntaxCharacter(current())) {
IsSyntaxCharacter(current())) {
builder->AddCharacter(current()); builder->AddCharacter(current());
Advance(); Advance();
} else { } else {
...@@ -736,7 +735,7 @@ bool RegExpParser::ParseUnicodeEscape(uc32* value) { ...@@ -736,7 +735,7 @@ bool RegExpParser::ParseUnicodeEscape(uc32* value) {
// Accept both \uxxxx and \u{xxxxxx} (if harmony unicode escapes are // Accept both \uxxxx and \u{xxxxxx} (if harmony unicode escapes are
// allowed). In the latter case, the number of hex digits between { } is // allowed). In the latter case, the number of hex digits between { } is
// arbitrary. \ and u have already been read. // arbitrary. \ and u have already been read.
if (current() == '{' && FLAG_harmony_unicode_regexps && unicode_) { if (current() == '{' && unicode_) {
int start = position(); int start = position();
Advance(); Advance();
if (ParseUnlimitedLengthHexNumber(0x10ffff, value)) { if (ParseUnlimitedLengthHexNumber(0x10ffff, value)) {
...@@ -831,7 +830,7 @@ uc32 RegExpParser::ParseClassCharacterEscape() { ...@@ -831,7 +830,7 @@ uc32 RegExpParser::ParseClassCharacterEscape() {
if (ParseHexEscape(2, &value)) { if (ParseHexEscape(2, &value)) {
return value; return value;
} }
if (!FLAG_harmony_unicode_regexps || !unicode_) { if (!unicode_) {
// If \x is not followed by a two-digit hexadecimal, treat it // If \x is not followed by a two-digit hexadecimal, treat it
// as an identity escape. // as an identity escape.
return 'x'; return 'x';
...@@ -847,7 +846,7 @@ uc32 RegExpParser::ParseClassCharacterEscape() { ...@@ -847,7 +846,7 @@ uc32 RegExpParser::ParseClassCharacterEscape() {
if (ParseUnicodeEscape(&value)) { if (ParseUnicodeEscape(&value)) {
return value; return value;
} }
if (!FLAG_harmony_unicode_regexps || !unicode_) { if (!unicode_) {
return 'u'; return 'u';
} }
// If the 'u' flag is present, invalid escapes are not treated as // If the 'u' flag is present, invalid escapes are not treated as
...@@ -860,8 +859,7 @@ uc32 RegExpParser::ParseClassCharacterEscape() { ...@@ -860,8 +859,7 @@ uc32 RegExpParser::ParseClassCharacterEscape() {
// If the 'u' flag is present, only syntax characters can be escaped, no // If the 'u' flag is present, only syntax characters can be escaped, no
// other identity escapes are allowed. If the 'u' flag is not present, all // other identity escapes are allowed. If the 'u' flag is not present, all
// identity escapes are allowed. // identity escapes are allowed.
if (!FLAG_harmony_unicode_regexps || !unicode_ || if (!unicode_ || IsSyntaxCharacter(result)) {
IsSyntaxCharacter(result)) {
Advance(); Advance();
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment