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 #ifndef V8_REGEXP_REGEXP_PARSER_H_ | 5 #ifndef V8_REGEXP_REGEXP_PARSER_H_ |
6 #define V8_REGEXP_REGEXP_PARSER_H_ | 6 #define V8_REGEXP_REGEXP_PARSER_H_ |
7 | 7 |
8 #include "src/objects.h" | 8 #include "src/objects.h" |
9 #include "src/regexp/regexp-ast.h" | 9 #include "src/regexp/regexp-ast.h" |
10 #include "src/zone/zone.h" | 10 #include "src/zone/zone.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 bool ParsePropertyClass(ZoneList<CharacterRange>* result, bool negate); | 177 bool ParsePropertyClass(ZoneList<CharacterRange>* result, bool negate); |
178 | 178 |
179 uc32 ParseOctalLiteral(); | 179 uc32 ParseOctalLiteral(); |
180 | 180 |
181 // Tries to parse the input as a back reference. If successful it | 181 // Tries to parse the input as a back reference. If successful it |
182 // stores the result in the output parameter and returns true. If | 182 // stores the result in the output parameter and returns true. If |
183 // it fails it will push back the characters read so the same characters | 183 // it fails it will push back the characters read so the same characters |
184 // can be reparsed. | 184 // can be reparsed. |
185 bool ParseBackReferenceIndex(int* index_out); | 185 bool ParseBackReferenceIndex(int* index_out); |
186 | 186 |
| 187 // The default behavior is to combine surrogate pairs in unicode mode and |
| 188 // don't combine them otherwise (a quantifier after a surrogate pair would |
| 189 // then apply only to the trailing surrogate). Forcing combination is required |
| 190 // when parsing capture names since they can always legally contain surrogate |
| 191 // pairs. |
| 192 enum class ScanMode { DEFAULT, FORCE_COMBINE_SURROGATE_PAIRS }; |
| 193 |
187 bool ParseClassProperty(ZoneList<CharacterRange>* result); | 194 bool ParseClassProperty(ZoneList<CharacterRange>* result); |
188 CharacterRange ParseClassAtom(uc16* char_class); | 195 CharacterRange ParseClassAtom(uc16* char_class); |
189 RegExpTree* ReportError(Vector<const char> message); | 196 RegExpTree* ReportError(Vector<const char> message); |
190 void Advance(); | 197 void Advance(ScanMode mode = ScanMode::DEFAULT); |
191 void Advance(int dist); | 198 void Advance(int dist, ScanMode mode = ScanMode::DEFAULT); |
192 void Reset(int pos); | 199 void Reset(int pos); |
193 | 200 |
194 // Reports whether the pattern might be used as a literal search string. | 201 // Reports whether the pattern might be used as a literal search string. |
195 // Only use if the result of the parse is a single atom node. | 202 // Only use if the result of the parse is a single atom node. |
196 bool simple(); | 203 bool simple(); |
197 bool contains_anchor() { return contains_anchor_; } | 204 bool contains_anchor() { return contains_anchor_; } |
198 void set_contains_anchor() { contains_anchor_ = true; } | 205 void set_contains_anchor() { contains_anchor_ = true; } |
199 int captures_started() { return captures_started_; } | 206 int captures_started() { return captures_started_; } |
200 int position() { return next_pos_ - 1; } | 207 int position() { return next_pos_ - 1; } |
201 bool failed() { return failed_; } | 208 bool failed() { return failed_; } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // ScanForCaptures to look ahead at the remaining pattern. | 304 // ScanForCaptures to look ahead at the remaining pattern. |
298 bool HasNamedCaptures(); | 305 bool HasNamedCaptures(); |
299 | 306 |
300 Isolate* isolate() { return isolate_; } | 307 Isolate* isolate() { return isolate_; } |
301 Zone* zone() const { return zone_; } | 308 Zone* zone() const { return zone_; } |
302 | 309 |
303 uc32 current() { return current_; } | 310 uc32 current() { return current_; } |
304 bool has_more() { return has_more_; } | 311 bool has_more() { return has_more_; } |
305 bool has_next() { return next_pos_ < in()->length(); } | 312 bool has_next() { return next_pos_ < in()->length(); } |
306 uc32 Next(); | 313 uc32 Next(); |
307 template <bool update_position> | 314 uc32 ReadNext(bool update_position, ScanMode mode); |
308 uc32 ReadNext(); | |
309 FlatStringReader* in() { return in_; } | 315 FlatStringReader* in() { return in_; } |
310 void ScanForCaptures(); | 316 void ScanForCaptures(); |
311 | 317 |
312 Isolate* isolate_; | 318 Isolate* isolate_; |
313 Zone* zone_; | 319 Zone* zone_; |
314 Handle<String>* error_; | 320 Handle<String>* error_; |
315 ZoneList<RegExpCapture*>* captures_; | 321 ZoneList<RegExpCapture*>* captures_; |
316 ZoneList<RegExpCapture*>* named_captures_; | 322 ZoneList<RegExpCapture*>* named_captures_; |
317 ZoneList<RegExpBackReference*>* named_back_references_; | 323 ZoneList<RegExpBackReference*>* named_back_references_; |
318 FlatStringReader* in_; | 324 FlatStringReader* in_; |
(...skipping 10 matching lines...) Expand all Loading... |
329 bool contains_anchor_; | 335 bool contains_anchor_; |
330 bool is_scanned_for_captures_; | 336 bool is_scanned_for_captures_; |
331 bool has_named_captures_; // Only valid after we have scanned for captures. | 337 bool has_named_captures_; // Only valid after we have scanned for captures. |
332 bool failed_; | 338 bool failed_; |
333 }; | 339 }; |
334 | 340 |
335 } // namespace internal | 341 } // namespace internal |
336 } // namespace v8 | 342 } // namespace v8 |
337 | 343 |
338 #endif // V8_REGEXP_REGEXP_PARSER_H_ | 344 #endif // V8_REGEXP_REGEXP_PARSER_H_ |
OLD | NEW |