Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index fd93aae4241d7494dc26522ca4904081e746c4eb..94ad57c9c28ba02a40b111562c56aa1f243129b1 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -4449,6 +4449,22 @@ CharacterRange RegExpParser::ParseClassAtom(uc16* char_class) { |
} |
+static const uc16 kNoCharClass = 0; |
+ |
+// Adds range or pre-defined character class to character ranges. |
+// If char_class is not kInvalidClass, it's interpreted as a class |
+// escape (i.e., 's' means whitespace, from '\s'). |
+static inline void AddRangeOrEscape(ZoneList<CharacterRange>* ranges, |
+ uc16 char_class, |
+ CharacterRange range) { |
+ if (char_class != kNoCharClass) { |
+ CharacterRange::AddClassEscape(char_class, ranges); |
+ } else { |
+ ranges->Add(range); |
+ } |
+} |
+ |
+ |
RegExpTree* RegExpParser::ParseCharacterClass() { |
static const char* kUnterminated = "Unterminated character class"; |
static const char* kRangeOutOfOrder = "Range out of order in character class"; |
@@ -4462,12 +4478,8 @@ RegExpTree* RegExpParser::ParseCharacterClass() { |
} |
ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); |
while (has_more() && current() != ']') { |
- uc16 char_class = 0; |
+ uc16 char_class = kNoCharClass; |
CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); |
- if (char_class) { |
- CharacterRange::AddClassEscape(char_class, ranges); |
- continue; |
- } |
if (current() == '-') { |
Advance(); |
if (current() == kEndMarker) { |
@@ -4475,15 +4487,17 @@ RegExpTree* RegExpParser::ParseCharacterClass() { |
// following code report an error. |
break; |
} else if (current() == ']') { |
- ranges->Add(first); |
+ AddRangeOrEscape(ranges, char_class, first); |
ranges->Add(CharacterRange::Singleton('-')); |
break; |
} |
- CharacterRange next = ParseClassAtom(&char_class CHECK_FAILED); |
- if (char_class) { |
- ranges->Add(first); |
+ uc16 char_class_2 = kNoCharClass; |
+ CharacterRange next = ParseClassAtom(&char_class_2 CHECK_FAILED); |
+ if (char_class != kNoCharClass || char_class_2 != kNoCharClass) { |
+ // Either end is an escaped character class. Treat the '-' verbatim. |
+ AddRangeOrEscape(ranges, char_class, first); |
ranges->Add(CharacterRange::Singleton('-')); |
- CharacterRange::AddClassEscape(char_class, ranges); |
+ AddRangeOrEscape(ranges, char_class_2, next); |
continue; |
} |
if (first.from() > next.to()) { |
@@ -4491,7 +4505,7 @@ RegExpTree* RegExpParser::ParseCharacterClass() { |
} |
ranges->Add(CharacterRange::Range(first.from(), next.to())); |
} else { |
- ranges->Add(first); |
+ AddRangeOrEscape(ranges, char_class, first); |
} |
} |
if (!has_more()) { |