| 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.h" | 10 #include "src/zone.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 SubexpressionType group_type_; | 255 SubexpressionType group_type_; |
| 256 // Stored read direction. | 256 // Stored read direction. |
| 257 RegExpLookaround::Type lookaround_type_; | 257 RegExpLookaround::Type lookaround_type_; |
| 258 // Stored disjunction's capture index (if any). | 258 // Stored disjunction's capture index (if any). |
| 259 int disjunction_capture_index_; | 259 int disjunction_capture_index_; |
| 260 }; | 260 }; |
| 261 | 261 |
| 262 // Return the 1-indexed RegExpCapture object, allocate if necessary. | 262 // Return the 1-indexed RegExpCapture object, allocate if necessary. |
| 263 RegExpCapture* GetCapture(int index); | 263 RegExpCapture* GetCapture(int index); |
| 264 | 264 |
| 265 // Creates a new named capture at the specified index. Must be called exactly |
| 266 // once for each named capture. Fails if a capture with the same name is |
| 267 // encountered. |
| 268 bool CreateNamedCaptureAtIndex(Vector<const uc16> name, int index); |
| 269 |
| 270 // Parses the name of a capture group (?<name>pattern). The name must adhere |
| 271 // to IdentifierName in the ECMAScript standard. |
| 272 Vector<const uc16> ParseCaptureGroupName(); |
| 273 |
| 274 bool ParseNamedBackReference(RegExpBuilder* builder, |
| 275 RegExpParserState* state); |
| 276 |
| 277 // Looks up the index of the capture group with the specified name. Returns -1 |
| 278 // in case no such group is found. |
| 279 int LookupCaptureGroupIndex(Vector<const uc16> name); |
| 280 |
| 281 // After the initial parsing pass, patch corresponding RegExpCapture objects |
| 282 // into all RegExpBackReferences. This is done after initial parsing in order |
| 283 // to avoid complicating cases in which references comes before the capture. |
| 284 void PatchNamedBackReferences(); |
| 285 |
| 286 Handle<FixedArray> CreateCaptureNameMap(); |
| 287 void FreeCaptureStrings(); |
| 288 |
| 265 Isolate* isolate() { return isolate_; } | 289 Isolate* isolate() { return isolate_; } |
| 266 Zone* zone() const { return zone_; } | 290 Zone* zone() const { return zone_; } |
| 267 | 291 |
| 268 uc32 current() { return current_; } | 292 uc32 current() { return current_; } |
| 269 bool has_more() { return has_more_; } | 293 bool has_more() { return has_more_; } |
| 270 bool has_next() { return next_pos_ < in()->length(); } | 294 bool has_next() { return next_pos_ < in()->length(); } |
| 271 uc32 Next(); | 295 uc32 Next(); |
| 272 template <bool update_position> | 296 template <bool update_position> |
| 273 uc32 ReadNext(); | 297 uc32 ReadNext(); |
| 274 FlatStringReader* in() { return in_; } | 298 FlatStringReader* in() { return in_; } |
| 275 void ScanForCaptures(); | 299 void ScanForCaptures(); |
| 276 | 300 |
| 277 Isolate* isolate_; | 301 Isolate* isolate_; |
| 278 Zone* zone_; | 302 Zone* zone_; |
| 279 Handle<String>* error_; | 303 Handle<String>* error_; |
| 280 ZoneList<RegExpCapture*>* captures_; | 304 ZoneList<RegExpCapture*>* captures_; |
| 305 ZoneList<RegExpCapture*>* named_captures_; |
| 306 ZoneList<RegExpBackReference*>* named_back_references_; |
| 307 ZoneList<Vector<const uc16>> capture_strings_; |
| 281 FlatStringReader* in_; | 308 FlatStringReader* in_; |
| 282 uc32 current_; | 309 uc32 current_; |
| 283 bool ignore_case_; | 310 bool ignore_case_; |
| 284 bool multiline_; | 311 bool multiline_; |
| 285 bool unicode_; | 312 bool unicode_; |
| 286 int next_pos_; | 313 int next_pos_; |
| 287 int captures_started_; | 314 int captures_started_; |
| 288 // The capture count is only valid after we have scanned for captures. | 315 // The capture count is only valid after we have scanned for captures. |
| 289 int capture_count_; | 316 int capture_count_; |
| 290 bool has_more_; | 317 bool has_more_; |
| 291 bool simple_; | 318 bool simple_; |
| 292 bool contains_anchor_; | 319 bool contains_anchor_; |
| 293 bool is_scanned_for_captures_; | 320 bool is_scanned_for_captures_; |
| 294 bool failed_; | 321 bool failed_; |
| 295 }; | 322 }; |
| 296 | 323 |
| 297 } // namespace internal | 324 } // namespace internal |
| 298 } // namespace v8 | 325 } // namespace v8 |
| 299 | 326 |
| 300 #endif // V8_REGEXP_REGEXP_PARSER_H_ | 327 #endif // V8_REGEXP_REGEXP_PARSER_H_ |
| OLD | NEW |