Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/parser.h

Issue 1418963009: Experimental support for RegExp lookbehind. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix arm64 debug code assertion Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | src/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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_PARSER_H_ 5 #ifndef V8_PARSER_H_
6 #define V8_PARSER_H_ 6 #define V8_PARSER_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/compiler.h" // TODO(titzer): remove this include dependency 10 #include "src/compiler.h" // TODO(titzer): remove this include dependency
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 RegExpTree* ReportError(Vector<const char> message); 443 RegExpTree* ReportError(Vector<const char> message);
444 void Advance(); 444 void Advance();
445 void Advance(int dist); 445 void Advance(int dist);
446 void Reset(int pos); 446 void Reset(int pos);
447 447
448 // Reports whether the pattern might be used as a literal search string. 448 // Reports whether the pattern might be used as a literal search string.
449 // Only use if the result of the parse is a single atom node. 449 // Only use if the result of the parse is a single atom node.
450 bool simple(); 450 bool simple();
451 bool contains_anchor() { return contains_anchor_; } 451 bool contains_anchor() { return contains_anchor_; }
452 void set_contains_anchor() { contains_anchor_ = true; } 452 void set_contains_anchor() { contains_anchor_ = true; }
453 int captures_started() { return captures_ == NULL ? 0 : captures_->length(); } 453 int captures_started() { return captures_started_; }
454 int position() { return next_pos_ - 1; } 454 int position() { return next_pos_ - 1; }
455 bool failed() { return failed_; } 455 bool failed() { return failed_; }
456 456
457 static bool IsSyntaxCharacter(uc32 c); 457 static bool IsSyntaxCharacter(uc32 c);
458 458
459 static const int kMaxCaptures = 1 << 16; 459 static const int kMaxCaptures = 1 << 16;
460 static const uc32 kEndMarker = (1 << 21); 460 static const uc32 kEndMarker = (1 << 21);
461 461
462 private: 462 private:
463 enum SubexpressionType { 463 enum SubexpressionType {
464 INITIAL, 464 INITIAL,
465 CAPTURE, // All positive values represent captures. 465 CAPTURE, // All positive values represent captures.
466 POSITIVE_LOOKAHEAD, 466 POSITIVE_LOOKAROUND,
467 NEGATIVE_LOOKAHEAD, 467 NEGATIVE_LOOKAROUND,
468 GROUPING 468 GROUPING
469 }; 469 };
470 470
471 class RegExpParserState : public ZoneObject { 471 class RegExpParserState : public ZoneObject {
472 public: 472 public:
473 RegExpParserState(RegExpParserState* previous_state, 473 RegExpParserState(RegExpParserState* previous_state,
474 SubexpressionType group_type, 474 SubexpressionType group_type,
475 int disjunction_capture_index, 475 RegExpLookaround::Type lookaround_type,
476 Zone* zone) 476 int disjunction_capture_index, Zone* zone)
477 : previous_state_(previous_state), 477 : previous_state_(previous_state),
478 builder_(new(zone) RegExpBuilder(zone)), 478 builder_(new (zone) RegExpBuilder(zone)),
479 group_type_(group_type), 479 group_type_(group_type),
480 lookaround_type_(lookaround_type),
480 disjunction_capture_index_(disjunction_capture_index) {} 481 disjunction_capture_index_(disjunction_capture_index) {}
481 // Parser state of containing expression, if any. 482 // Parser state of containing expression, if any.
482 RegExpParserState* previous_state() { return previous_state_; } 483 RegExpParserState* previous_state() { return previous_state_; }
483 bool IsSubexpression() { return previous_state_ != NULL; } 484 bool IsSubexpression() { return previous_state_ != NULL; }
484 // RegExpBuilder building this regexp's AST. 485 // RegExpBuilder building this regexp's AST.
485 RegExpBuilder* builder() { return builder_; } 486 RegExpBuilder* builder() { return builder_; }
486 // Type of regexp being parsed (parenthesized group or entire regexp). 487 // Type of regexp being parsed (parenthesized group or entire regexp).
487 SubexpressionType group_type() { return group_type_; } 488 SubexpressionType group_type() { return group_type_; }
489 // Lookahead or Lookbehind.
490 RegExpLookaround::Type lookaround_type() { return lookaround_type_; }
488 // Index in captures array of first capture in this sub-expression, if any. 491 // Index in captures array of first capture in this sub-expression, if any.
489 // Also the capture index of this sub-expression itself, if group_type 492 // Also the capture index of this sub-expression itself, if group_type
490 // is CAPTURE. 493 // is CAPTURE.
491 int capture_index() { return disjunction_capture_index_; } 494 int capture_index() { return disjunction_capture_index_; }
492 495
496 // Check whether the parser is inside a capture group with the given index.
497 bool IsInsideCaptureGroup(int index);
498
493 private: 499 private:
494 // Linked list implementation of stack of states. 500 // Linked list implementation of stack of states.
495 RegExpParserState* previous_state_; 501 RegExpParserState* previous_state_;
496 // Builder for the stored disjunction. 502 // Builder for the stored disjunction.
497 RegExpBuilder* builder_; 503 RegExpBuilder* builder_;
498 // Stored disjunction type (capture, look-ahead or grouping), if any. 504 // Stored disjunction type (capture, look-ahead or grouping), if any.
499 SubexpressionType group_type_; 505 SubexpressionType group_type_;
506 // Stored read direction.
507 RegExpLookaround::Type lookaround_type_;
500 // Stored disjunction's capture index (if any). 508 // Stored disjunction's capture index (if any).
501 int disjunction_capture_index_; 509 int disjunction_capture_index_;
502 }; 510 };
503 511
512 // Return the 1-indexed RegExpCapture object, allocate if necessary.
513 RegExpCapture* GetCapture(int index);
514
504 Isolate* isolate() { return isolate_; } 515 Isolate* isolate() { return isolate_; }
505 Zone* zone() const { return zone_; } 516 Zone* zone() const { return zone_; }
506 517
507 uc32 current() { return current_; } 518 uc32 current() { return current_; }
508 bool has_more() { return has_more_; } 519 bool has_more() { return has_more_; }
509 bool has_next() { return next_pos_ < in()->length(); } 520 bool has_next() { return next_pos_ < in()->length(); }
510 uc32 Next(); 521 uc32 Next();
511 FlatStringReader* in() { return in_; } 522 FlatStringReader* in() { return in_; }
512 void ScanForCaptures(); 523 void ScanForCaptures();
513 524
514 Isolate* isolate_; 525 Isolate* isolate_;
515 Zone* zone_; 526 Zone* zone_;
516 Handle<String>* error_; 527 Handle<String>* error_;
517 ZoneList<RegExpCapture*>* captures_; 528 ZoneList<RegExpCapture*>* captures_;
518 FlatStringReader* in_; 529 FlatStringReader* in_;
519 uc32 current_; 530 uc32 current_;
520 int next_pos_; 531 int next_pos_;
532 int captures_started_;
521 // The capture count is only valid after we have scanned for captures. 533 // The capture count is only valid after we have scanned for captures.
522 int capture_count_; 534 int capture_count_;
523 bool has_more_; 535 bool has_more_;
524 bool multiline_; 536 bool multiline_;
525 bool unicode_; 537 bool unicode_;
526 bool simple_; 538 bool simple_;
527 bool contains_anchor_; 539 bool contains_anchor_;
528 bool is_scanned_for_captures_; 540 bool is_scanned_for_captures_;
529 bool failed_; 541 bool failed_;
530 }; 542 };
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 1395
1384 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1396 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1385 return parser_->ParseDoExpression(ok); 1397 return parser_->ParseDoExpression(ok);
1386 } 1398 }
1387 1399
1388 1400
1389 } // namespace internal 1401 } // namespace internal
1390 } // namespace v8 1402 } // namespace v8
1391 1403
1392 #endif // V8_PARSER_H_ 1404 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698