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

Side by Side Diff: src/parser.cc

Issue 40103: Fix issue 246. (Closed)
Patch Set: Created 11 years, 9 months 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 | « no previous file | test/mjsunit/regress/regress-246.js » ('j') | test/mjsunit/regress/regress-246.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3588 matching lines...) Expand 10 before | Expand all | Expand 10 after
3599 3599
3600 RegExpParser::RegExpParser(FlatStringReader* in, 3600 RegExpParser::RegExpParser(FlatStringReader* in,
3601 Handle<String>* error, 3601 Handle<String>* error,
3602 bool multiline) 3602 bool multiline)
3603 : current_(kEndMarker), 3603 : current_(kEndMarker),
3604 has_more_(true), 3604 has_more_(true),
3605 multiline_(multiline), 3605 multiline_(multiline),
3606 next_pos_(0), 3606 next_pos_(0),
3607 in_(in), 3607 in_(in),
3608 error_(error), 3608 error_(error),
3609 simple_(true), 3609 simple_(false),
3610 contains_anchor_(false), 3610 contains_anchor_(false),
3611 captures_(NULL), 3611 captures_(NULL),
3612 is_scanned_for_captures_(false), 3612 is_scanned_for_captures_(false),
3613 capture_count_(0), 3613 capture_count_(0),
3614 failed_(false) { 3614 failed_(false) {
3615 Advance(1); 3615 Advance(1);
3616 } 3616 }
3617 3617
3618 3618
3619 uc32 RegExpParser::Next() { 3619 uc32 RegExpParser::Next() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3669 } 3669 }
3670 3670
3671 3671
3672 // Pattern :: 3672 // Pattern ::
3673 // Disjunction 3673 // Disjunction
3674 RegExpTree* RegExpParser::ParsePattern() { 3674 RegExpTree* RegExpParser::ParsePattern() {
3675 RegExpTree* result = ParseDisjunction(CHECK_FAILED); 3675 RegExpTree* result = ParseDisjunction(CHECK_FAILED);
3676 if (has_more()) { 3676 if (has_more()) {
3677 ReportError(CStrVector("Unmatched ')'") CHECK_FAILED); 3677 ReportError(CStrVector("Unmatched ')'") CHECK_FAILED);
3678 } 3678 }
3679 // If the result of parsing is a literal string atom, and it has the
3680 // same length as the input, then the atom is identical to the input.
3681 if (result->IsAtom() && result->AsAtom()->length() == in()->length()) {
3682 simple_ = true;
3683 }
3679 return result; 3684 return result;
3680 } 3685 }
3681 3686
3682 3687
3683 bool RegExpParser::CaptureAvailable(int index) { 3688 bool RegExpParser::CaptureAvailable(int index) {
3684 if (captures_ == NULL) return false; 3689 if (captures_ == NULL) return false;
3685 if (index >= captures_->length()) return false; 3690 if (index >= captures_->length()) return false;
3686 RegExpCapture* capture = captures_->at(index); 3691 RegExpCapture* capture = captures_->at(index);
3687 return capture != NULL && capture->available() == CAPTURE_AVAILABLE; 3692 return capture != NULL && capture->available() == CAPTURE_AVAILABLE;
3688 } 3693 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3868 builder.AddCharacter('u'); 3873 builder.AddCharacter('u');
3869 } 3874 }
3870 break; 3875 break;
3871 } 3876 }
3872 default: 3877 default:
3873 // Identity escape. 3878 // Identity escape.
3874 builder.AddCharacter(Next()); 3879 builder.AddCharacter(Next());
3875 Advance(2); 3880 Advance(2);
3876 break; 3881 break;
3877 } 3882 }
3878 simple_ = false;
3879 break; 3883 break;
3880 case '{': { 3884 case '{': {
3881 int dummy; 3885 int dummy;
3882 if (ParseIntervalQuantifier(&dummy, &dummy)) { 3886 if (ParseIntervalQuantifier(&dummy, &dummy)) {
3883 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED); 3887 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED);
3884 } 3888 }
3885 // fallthrough 3889 // fallthrough
3886 } 3890 }
3887 default: 3891 default:
3888 builder.AddCharacter(current()); 3892 builder.AddCharacter(current());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3925 continue; 3929 continue;
3926 } 3930 }
3927 default: 3931 default:
3928 continue; 3932 continue;
3929 } 3933 }
3930 bool is_greedy = true; 3934 bool is_greedy = true;
3931 if (current() == '?') { 3935 if (current() == '?') {
3932 is_greedy = false; 3936 is_greedy = false;
3933 Advance(); 3937 Advance();
3934 } 3938 }
3935 simple_ = false; // Adding quantifier might *remove* look-ahead.
3936 builder.AddQuantifierToAtom(min, max, is_greedy); 3939 builder.AddQuantifierToAtom(min, max, is_greedy);
3937 } 3940 }
3938 } 3941 }
3939 3942
3940 class SourceCharacter { 3943 class SourceCharacter {
3941 public: 3944 public:
3942 static bool Is(uc32 c) { 3945 static bool Is(uc32 c) {
3943 switch (c) { 3946 switch (c) {
3944 // case ']': case '}': 3947 // case ']': case '}':
3945 // In spidermonkey and jsc these are treated as source characters 3948 // In spidermonkey and jsc these are treated as source characters
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
4510 start_position, 4513 start_position,
4511 is_expression); 4514 is_expression);
4512 return result; 4515 return result;
4513 } 4516 }
4514 4517
4515 4518
4516 #undef NEW 4519 #undef NEW
4517 4520
4518 4521
4519 } } // namespace v8::internal 4522 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-246.js » ('j') | test/mjsunit/regress/regress-246.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698