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

Unified Diff: src/parser.cc

Issue 13016: Allow [a-\d] in RegExp parser. (Closed)
Patch Set: Created 12 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 | « no previous file | test/cctest/test-regexp.cc » ('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 64a87d568c4890e2e5c16f351ae1f2e81190db58..2d46949dab05a4962eb6f6d7d1f9bf0897ffdd77 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -521,8 +521,7 @@ class RegExpParser {
// can be reparsed.
bool ParseBackReferenceIndex(int* index_out);
- CharacterRange ParseClassAtom(bool* is_char_class,
- ZoneList<CharacterRange>* ranges,
+ CharacterRange ParseClassAtom(uc16* is_char_class,
bool* ok);
RegExpTree* ReportError(Vector<const char> message, bool* ok);
void Advance();
@@ -4158,19 +4157,15 @@ RegExpTree* RegExpParser::ParseGroup(bool* ok) {
}
-CharacterRange RegExpParser::ParseClassAtom(bool* is_char_class,
- ZoneList<CharacterRange>* ranges,
- bool* ok) {
- ASSERT_EQ(false, *is_char_class);
+CharacterRange RegExpParser::ParseClassAtom(uc16* char_class, bool* ok) {
+ ASSERT_EQ(0, *char_class);
uc32 first = current();
if (first == '\\') {
switch (Next()) {
case 'w': case 'W': case 'd': case 'D': case 's': case 'S': {
- *is_char_class = true;
- uc32 c = Next();
- CharacterRange::AddClassEscape(c, ranges);
+ *char_class = Next();
Advance(2);
- return NULL;
+ return CharacterRange::Singleton(0);
}
default:
uc32 c = ParseClassCharacterEscape(CHECK_OK);
@@ -4185,7 +4180,6 @@ CharacterRange RegExpParser::ParseClassAtom(bool* is_char_class,
RegExpTree* RegExpParser::ParseCharacterClass(bool* ok) {
static const char* kUnterminated = "Unterminated character class";
- static const char* kIllegal = "Illegal character class";
static const char* kRangeOutOfOrder = "Range out of order in character class";
ASSERT_EQ(current(), '[');
@@ -4197,32 +4191,36 @@ RegExpTree* RegExpParser::ParseCharacterClass(bool* ok) {
}
ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2);
while (has_more() && current() != ']') {
- bool is_char_class = false;
- CharacterRange first = ParseClassAtom(&is_char_class, ranges, CHECK_OK);
- if (!is_char_class) {
- if (current() == '-') {
- Advance();
- if (current() == kEndMarker) {
- // If we reach the end we break out of the loop and let the
- // following code report an error.
- break;
- } else if (current() == ']') {
- ranges->Add(first);
- ranges->Add(CharacterRange::Singleton('-'));
- break;
- }
- CharacterRange next =
- ParseClassAtom(&is_char_class, ranges, CHECK_OK);
- if (is_char_class) {
- return ReportError(CStrVector(kIllegal), CHECK_OK);
- }
- if (first.from() > next.to()) {
- return ReportError(CStrVector(kRangeOutOfOrder), CHECK_OK);
- }
- ranges->Add(CharacterRange::Range(first.from(), next.to()));
- } else {
+ uc16 char_class = 0;
+ CharacterRange first = ParseClassAtom(&char_class, CHECK_OK);
+ if (char_class) {
+ CharacterRange::AddClassEscape(char_class, ranges);
+ continue;
+ }
+ if (current() == '-') {
+ Advance();
+ if (current() == kEndMarker) {
+ // If we reach the end we break out of the loop and let the
+ // following code report an error.
+ break;
+ } else if (current() == ']') {
+ ranges->Add(first);
+ ranges->Add(CharacterRange::Singleton('-'));
+ break;
+ }
+ CharacterRange next = ParseClassAtom(&char_class, CHECK_OK);
+ if (char_class) {
ranges->Add(first);
+ ranges->Add(CharacterRange::Singleton('-'));
+ CharacterRange::AddClassEscape(char_class, ranges);
+ continue;
}
+ if (first.from() > next.to()) {
+ return ReportError(CStrVector(kRangeOutOfOrder), CHECK_OK);
+ }
+ ranges->Add(CharacterRange::Range(first.from(), next.to()));
+ } else {
+ ranges->Add(first);
}
}
if (!has_more()) {
« no previous file with comments | « no previous file | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698