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: addressed comments 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
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
493 private: 496 private:
494 // Linked list implementation of stack of states. 497 // Linked list implementation of stack of states.
495 RegExpParserState* previous_state_; 498 RegExpParserState* previous_state_;
496 // Builder for the stored disjunction. 499 // Builder for the stored disjunction.
497 RegExpBuilder* builder_; 500 RegExpBuilder* builder_;
498 // Stored disjunction type (capture, look-ahead or grouping), if any. 501 // Stored disjunction type (capture, look-ahead or grouping), if any.
499 SubexpressionType group_type_; 502 SubexpressionType group_type_;
503 // Stored read direction.
504 RegExpLookaround::Type lookaround_type_;
500 // Stored disjunction's capture index (if any). 505 // Stored disjunction's capture index (if any).
501 int disjunction_capture_index_; 506 int disjunction_capture_index_;
502 }; 507 };
503 508
509 // Return the 1-indexed RegExpCapture object, allocate if necessary.
510 RegExpCapture* GetCapture(int index);
511
504 Isolate* isolate() { return isolate_; } 512 Isolate* isolate() { return isolate_; }
505 Zone* zone() const { return zone_; } 513 Zone* zone() const { return zone_; }
506 514
507 uc32 current() { return current_; } 515 uc32 current() { return current_; }
508 bool has_more() { return has_more_; } 516 bool has_more() { return has_more_; }
509 bool has_next() { return next_pos_ < in()->length(); } 517 bool has_next() { return next_pos_ < in()->length(); }
510 uc32 Next(); 518 uc32 Next();
511 FlatStringReader* in() { return in_; } 519 FlatStringReader* in() { return in_; }
512 void ScanForCaptures(); 520 void ScanForCaptures();
513 521
514 Isolate* isolate_; 522 Isolate* isolate_;
515 Zone* zone_; 523 Zone* zone_;
516 Handle<String>* error_; 524 Handle<String>* error_;
517 ZoneList<RegExpCapture*>* captures_; 525 ZoneList<RegExpCapture*>* captures_;
518 FlatStringReader* in_; 526 FlatStringReader* in_;
519 uc32 current_; 527 uc32 current_;
520 int next_pos_; 528 int next_pos_;
529 int captures_started_;
521 // The capture count is only valid after we have scanned for captures. 530 // The capture count is only valid after we have scanned for captures.
522 int capture_count_; 531 int capture_count_;
523 bool has_more_; 532 bool has_more_;
524 bool multiline_; 533 bool multiline_;
525 bool unicode_; 534 bool unicode_;
526 bool simple_; 535 bool simple_;
527 bool contains_anchor_; 536 bool contains_anchor_;
528 bool is_scanned_for_captures_; 537 bool is_scanned_for_captures_;
529 bool failed_; 538 bool failed_;
530 }; 539 };
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 1393
1385 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1394 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1386 return parser_->ParseDoExpression(ok); 1395 return parser_->ParseDoExpression(ok);
1387 } 1396 }
1388 1397
1389 1398
1390 } // namespace internal 1399 } // namespace internal
1391 } // namespace v8 1400 } // namespace v8
1392 1401
1393 #endif // V8_PARSER_H_ 1402 #endif // V8_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698