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 | |
194 bool ParseClassProperty(ZoneList<CharacterRange>* result); | 187 bool ParseClassProperty(ZoneList<CharacterRange>* result); |
195 CharacterRange ParseClassAtom(uc16* char_class); | 188 CharacterRange ParseClassAtom(uc16* char_class); |
196 RegExpTree* ReportError(Vector<const char> message); | 189 RegExpTree* ReportError(Vector<const char> message); |
197 void Advance(ScanMode mode = ScanMode::DEFAULT); | 190 void Advance(); |
198 void Advance(int dist, ScanMode mode = ScanMode::DEFAULT); | 191 void Advance(int dist); |
199 void Reset(int pos); | 192 void Reset(int pos); |
200 | 193 |
201 // Reports whether the pattern might be used as a literal search string. | 194 // Reports whether the pattern might be used as a literal search string. |
202 // Only use if the result of the parse is a single atom node. | 195 // Only use if the result of the parse is a single atom node. |
203 bool simple(); | 196 bool simple(); |
204 bool contains_anchor() { return contains_anchor_; } | 197 bool contains_anchor() { return contains_anchor_; } |
205 void set_contains_anchor() { contains_anchor_ = true; } | 198 void set_contains_anchor() { contains_anchor_ = true; } |
206 int captures_started() { return captures_started_; } | 199 int captures_started() { return captures_started_; } |
207 int position() { return next_pos_ - 1; } | 200 int position() { return next_pos_ - 1; } |
208 bool failed() { return failed_; } | 201 bool failed() { return failed_; } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // ScanForCaptures to look ahead at the remaining pattern. | 297 // ScanForCaptures to look ahead at the remaining pattern. |
305 bool HasNamedCaptures(); | 298 bool HasNamedCaptures(); |
306 | 299 |
307 Isolate* isolate() { return isolate_; } | 300 Isolate* isolate() { return isolate_; } |
308 Zone* zone() const { return zone_; } | 301 Zone* zone() const { return zone_; } |
309 | 302 |
310 uc32 current() { return current_; } | 303 uc32 current() { return current_; } |
311 bool has_more() { return has_more_; } | 304 bool has_more() { return has_more_; } |
312 bool has_next() { return next_pos_ < in()->length(); } | 305 bool has_next() { return next_pos_ < in()->length(); } |
313 uc32 Next(); | 306 uc32 Next(); |
314 uc32 ReadNext(bool update_position, ScanMode mode); | 307 template <bool update_position> |
| 308 uc32 ReadNext(); |
315 FlatStringReader* in() { return in_; } | 309 FlatStringReader* in() { return in_; } |
316 void ScanForCaptures(); | 310 void ScanForCaptures(); |
317 | 311 |
318 Isolate* isolate_; | 312 Isolate* isolate_; |
319 Zone* zone_; | 313 Zone* zone_; |
320 Handle<String>* error_; | 314 Handle<String>* error_; |
321 ZoneList<RegExpCapture*>* captures_; | 315 ZoneList<RegExpCapture*>* captures_; |
322 ZoneList<RegExpCapture*>* named_captures_; | 316 ZoneList<RegExpCapture*>* named_captures_; |
323 ZoneList<RegExpBackReference*>* named_back_references_; | 317 ZoneList<RegExpBackReference*>* named_back_references_; |
324 FlatStringReader* in_; | 318 FlatStringReader* in_; |
(...skipping 10 matching lines...) Expand all Loading... |
335 bool contains_anchor_; | 329 bool contains_anchor_; |
336 bool is_scanned_for_captures_; | 330 bool is_scanned_for_captures_; |
337 bool has_named_captures_; // Only valid after we have scanned for captures. | 331 bool has_named_captures_; // Only valid after we have scanned for captures. |
338 bool failed_; | 332 bool failed_; |
339 }; | 333 }; |
340 | 334 |
341 } // namespace internal | 335 } // namespace internal |
342 } // namespace v8 | 336 } // namespace v8 |
343 | 337 |
344 #endif // V8_REGEXP_REGEXP_PARSER_H_ | 338 #endif // V8_REGEXP_REGEXP_PARSER_H_ |
OLD | NEW |