OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/regexp/regexp-parser.h" | 5 #include "src/regexp/regexp-parser.h" |
6 | 6 |
7 #include "src/char-predicates-inl.h" | 7 #include "src/char-predicates-inl.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 RegExpParser::RegExpParser(FlatStringReader* in, Handle<String>* error, | 22 RegExpParser::RegExpParser(FlatStringReader* in, Handle<String>* error, |
23 JSRegExp::Flags flags, Isolate* isolate, Zone* zone) | 23 JSRegExp::Flags flags, Isolate* isolate, Zone* zone) |
24 : isolate_(isolate), | 24 : isolate_(isolate), |
25 zone_(zone), | 25 zone_(zone), |
26 error_(error), | 26 error_(error), |
27 captures_(NULL), | 27 captures_(NULL), |
28 named_captures_(NULL), | 28 named_captures_(NULL), |
29 named_back_references_(NULL), | 29 named_back_references_(NULL), |
30 in_(in), | 30 in_(in), |
31 current_(kEndMarker), | 31 current_(kEndMarker), |
| 32 dotall_(flags & JSRegExp::kDotAll), |
32 ignore_case_(flags & JSRegExp::kIgnoreCase), | 33 ignore_case_(flags & JSRegExp::kIgnoreCase), |
33 multiline_(flags & JSRegExp::kMultiline), | 34 multiline_(flags & JSRegExp::kMultiline), |
34 unicode_(flags & JSRegExp::kUnicode), | 35 unicode_(flags & JSRegExp::kUnicode), |
35 next_pos_(0), | 36 next_pos_(0), |
36 captures_started_(0), | 37 captures_started_(0), |
37 capture_count_(0), | 38 capture_count_(0), |
38 has_more_(true), | 39 has_more_(true), |
39 simple_(false), | 40 simple_(false), |
40 contains_anchor_(false), | 41 contains_anchor_(false), |
41 is_scanned_for_captures_(false), | 42 is_scanned_for_captures_(false), |
42 failed_(false) { | 43 failed_(false) { |
| 44 DCHECK_IMPLIES(dotall(), FLAG_harmony_regexp_dotall); |
43 Advance(); | 45 Advance(); |
44 } | 46 } |
45 | 47 |
46 template <bool update_position> | 48 template <bool update_position> |
47 inline uc32 RegExpParser::ReadNext() { | 49 inline uc32 RegExpParser::ReadNext() { |
48 int position = next_pos_; | 50 int position = next_pos_; |
49 uc32 c0 = in()->Get(position); | 51 uc32 c0 = in()->Get(position); |
50 position++; | 52 position++; |
51 // Read the whole surrogate pair in case of unicode flag, if possible. | 53 // Read the whole surrogate pair in case of unicode flag, if possible. |
52 if (unicode() && position < in()->length() && | 54 if (unicode() && position < in()->length() && |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 case '$': { | 265 case '$': { |
264 Advance(); | 266 Advance(); |
265 RegExpAssertion::AssertionType assertion_type = | 267 RegExpAssertion::AssertionType assertion_type = |
266 multiline() ? RegExpAssertion::END_OF_LINE | 268 multiline() ? RegExpAssertion::END_OF_LINE |
267 : RegExpAssertion::END_OF_INPUT; | 269 : RegExpAssertion::END_OF_INPUT; |
268 builder->AddAssertion(new (zone()) RegExpAssertion(assertion_type)); | 270 builder->AddAssertion(new (zone()) RegExpAssertion(assertion_type)); |
269 continue; | 271 continue; |
270 } | 272 } |
271 case '.': { | 273 case '.': { |
272 Advance(); | 274 Advance(); |
273 // everything except \x0a, \x0d, \u2028 and \u2029 | |
274 ZoneList<CharacterRange>* ranges = | 275 ZoneList<CharacterRange>* ranges = |
275 new (zone()) ZoneList<CharacterRange>(2, zone()); | 276 new (zone()) ZoneList<CharacterRange>(2, zone()); |
276 CharacterRange::AddClassEscape('.', ranges, false, zone()); | 277 |
| 278 if (dotall()) { |
| 279 // Everything. |
| 280 DCHECK(FLAG_harmony_regexp_dotall); |
| 281 CharacterRange::AddClassEscape('*', ranges, false, zone()); |
| 282 } else { |
| 283 // Everything except \x0a, \x0d, \u2028 and \u2029 |
| 284 CharacterRange::AddClassEscape('.', ranges, false, zone()); |
| 285 } |
| 286 |
277 RegExpCharacterClass* cc = | 287 RegExpCharacterClass* cc = |
278 new (zone()) RegExpCharacterClass(ranges, false); | 288 new (zone()) RegExpCharacterClass(ranges, false); |
279 builder->AddCharacterClass(cc); | 289 builder->AddCharacterClass(cc); |
280 break; | 290 break; |
281 } | 291 } |
282 case '(': { | 292 case '(': { |
283 SubexpressionType subexpr_type = CAPTURE; | 293 SubexpressionType subexpr_type = CAPTURE; |
284 RegExpLookaround::Type lookaround_type = state->lookaround_type(); | 294 RegExpLookaround::Type lookaround_type = state->lookaround_type(); |
285 bool is_named_capture = false; | 295 bool is_named_capture = false; |
286 Advance(); | 296 Advance(); |
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 return false; | 1820 return false; |
1811 } | 1821 } |
1812 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), | 1822 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), |
1813 zone()); | 1823 zone()); |
1814 LAST(ADD_TERM); | 1824 LAST(ADD_TERM); |
1815 return true; | 1825 return true; |
1816 } | 1826 } |
1817 | 1827 |
1818 } // namespace internal | 1828 } // namespace internal |
1819 } // namespace v8 | 1829 } // namespace v8 |
OLD | NEW |