OLD | NEW |
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 3589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3600 | 3600 |
3601 RegExpParser::RegExpParser(FlatStringReader* in, | 3601 RegExpParser::RegExpParser(FlatStringReader* in, |
3602 Handle<String>* error, | 3602 Handle<String>* error, |
3603 bool multiline) | 3603 bool multiline) |
3604 : current_(kEndMarker), | 3604 : current_(kEndMarker), |
3605 has_more_(true), | 3605 has_more_(true), |
3606 multiline_(multiline), | 3606 multiline_(multiline), |
3607 next_pos_(0), | 3607 next_pos_(0), |
3608 in_(in), | 3608 in_(in), |
3609 error_(error), | 3609 error_(error), |
3610 simple_(true), | 3610 simple_(false), |
3611 contains_anchor_(false), | 3611 contains_anchor_(false), |
3612 captures_(NULL), | 3612 captures_(NULL), |
3613 is_scanned_for_captures_(false), | 3613 is_scanned_for_captures_(false), |
3614 capture_count_(0), | 3614 capture_count_(0), |
3615 failed_(false) { | 3615 failed_(false) { |
3616 Advance(1); | 3616 Advance(1); |
3617 } | 3617 } |
3618 | 3618 |
3619 | 3619 |
3620 uc32 RegExpParser::Next() { | 3620 uc32 RegExpParser::Next() { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3670 } | 3670 } |
3671 | 3671 |
3672 | 3672 |
3673 // Pattern :: | 3673 // Pattern :: |
3674 // Disjunction | 3674 // Disjunction |
3675 RegExpTree* RegExpParser::ParsePattern() { | 3675 RegExpTree* RegExpParser::ParsePattern() { |
3676 RegExpTree* result = ParseDisjunction(CHECK_FAILED); | 3676 RegExpTree* result = ParseDisjunction(CHECK_FAILED); |
3677 if (has_more()) { | 3677 if (has_more()) { |
3678 ReportError(CStrVector("Unmatched ')'") CHECK_FAILED); | 3678 ReportError(CStrVector("Unmatched ')'") CHECK_FAILED); |
3679 } | 3679 } |
| 3680 // If the result of parsing is a literal string atom, and it has the |
| 3681 // same length as the input, then the atom is identical to the input. |
| 3682 if (result->IsAtom() && result->AsAtom()->length() == in()->length()) { |
| 3683 simple_ = true; |
| 3684 } |
3680 return result; | 3685 return result; |
3681 } | 3686 } |
3682 | 3687 |
3683 | 3688 |
3684 bool RegExpParser::CaptureAvailable(int index) { | 3689 bool RegExpParser::CaptureAvailable(int index) { |
3685 if (captures_ == NULL) return false; | 3690 if (captures_ == NULL) return false; |
3686 if (index >= captures_->length()) return false; | 3691 if (index >= captures_->length()) return false; |
3687 RegExpCapture* capture = captures_->at(index); | 3692 RegExpCapture* capture = captures_->at(index); |
3688 return capture != NULL && capture->available() == CAPTURE_AVAILABLE; | 3693 return capture != NULL && capture->available() == CAPTURE_AVAILABLE; |
3689 } | 3694 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3869 builder.AddCharacter('u'); | 3874 builder.AddCharacter('u'); |
3870 } | 3875 } |
3871 break; | 3876 break; |
3872 } | 3877 } |
3873 default: | 3878 default: |
3874 // Identity escape. | 3879 // Identity escape. |
3875 builder.AddCharacter(Next()); | 3880 builder.AddCharacter(Next()); |
3876 Advance(2); | 3881 Advance(2); |
3877 break; | 3882 break; |
3878 } | 3883 } |
3879 simple_ = false; | |
3880 break; | 3884 break; |
3881 case '{': { | 3885 case '{': { |
3882 int dummy; | 3886 int dummy; |
3883 if (ParseIntervalQuantifier(&dummy, &dummy)) { | 3887 if (ParseIntervalQuantifier(&dummy, &dummy)) { |
3884 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED); | 3888 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED); |
3885 } | 3889 } |
3886 // fallthrough | 3890 // fallthrough |
3887 } | 3891 } |
3888 default: | 3892 default: |
3889 builder.AddCharacter(current()); | 3893 builder.AddCharacter(current()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3926 continue; | 3930 continue; |
3927 } | 3931 } |
3928 default: | 3932 default: |
3929 continue; | 3933 continue; |
3930 } | 3934 } |
3931 bool is_greedy = true; | 3935 bool is_greedy = true; |
3932 if (current() == '?') { | 3936 if (current() == '?') { |
3933 is_greedy = false; | 3937 is_greedy = false; |
3934 Advance(); | 3938 Advance(); |
3935 } | 3939 } |
3936 simple_ = false; // Adding quantifier might *remove* look-ahead. | |
3937 builder.AddQuantifierToAtom(min, max, is_greedy); | 3940 builder.AddQuantifierToAtom(min, max, is_greedy); |
3938 } | 3941 } |
3939 } | 3942 } |
3940 | 3943 |
3941 class SourceCharacter { | 3944 class SourceCharacter { |
3942 public: | 3945 public: |
3943 static bool Is(uc32 c) { | 3946 static bool Is(uc32 c) { |
3944 switch (c) { | 3947 switch (c) { |
3945 // case ']': case '}': | 3948 // case ']': case '}': |
3946 // In spidermonkey and jsc these are treated as source characters | 3949 // In spidermonkey and jsc these are treated as source characters |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4511 start_position, | 4514 start_position, |
4512 is_expression); | 4515 is_expression); |
4513 return result; | 4516 return result; |
4514 } | 4517 } |
4515 | 4518 |
4516 | 4519 |
4517 #undef NEW | 4520 #undef NEW |
4518 | 4521 |
4519 | 4522 |
4520 } } // namespace v8::internal | 4523 } } // namespace v8::internal |
OLD | NEW |