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 3830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3841 current_ = kEndMarker; | 3841 current_ = kEndMarker; |
3842 next_pos_ = in()->length(); | 3842 next_pos_ = in()->length(); |
3843 return NULL; | 3843 return NULL; |
3844 } | 3844 } |
3845 | 3845 |
3846 | 3846 |
3847 // Pattern :: | 3847 // Pattern :: |
3848 // Disjunction | 3848 // Disjunction |
3849 RegExpTree* RegExpParser::ParsePattern() { | 3849 RegExpTree* RegExpParser::ParsePattern() { |
3850 RegExpTree* result = ParseDisjunction(CHECK_FAILED); | 3850 RegExpTree* result = ParseDisjunction(CHECK_FAILED); |
3851 if (has_more()) { | 3851 ASSERT(!has_more()); |
3852 ReportError(CStrVector("Unmatched ')'") CHECK_FAILED); | |
3853 } | |
3854 // If the result of parsing is a literal string atom, and it has the | 3852 // If the result of parsing is a literal string atom, and it has the |
3855 // same length as the input, then the atom is identical to the input. | 3853 // same length as the input, then the atom is identical to the input. |
3856 if (result->IsAtom() && result->AsAtom()->length() == in()->length()) { | 3854 if (result->IsAtom() && result->AsAtom()->length() == in()->length()) { |
3857 simple_ = true; | 3855 simple_ = true; |
3858 } | 3856 } |
3859 return result; | 3857 return result; |
3860 } | 3858 } |
3861 | 3859 |
3862 | 3860 |
3863 // Disjunction :: | 3861 // Disjunction :: |
(...skipping 17 matching lines...) Expand all Loading... |
3881 case kEndMarker: | 3879 case kEndMarker: |
3882 if (stored_state->IsSubexpression()) { | 3880 if (stored_state->IsSubexpression()) { |
3883 // Inside a parenthesized group when hitting end of input. | 3881 // Inside a parenthesized group when hitting end of input. |
3884 ReportError(CStrVector("Unterminated group") CHECK_FAILED); | 3882 ReportError(CStrVector("Unterminated group") CHECK_FAILED); |
3885 } | 3883 } |
3886 ASSERT_EQ(INITIAL, stored_state->group_type()); | 3884 ASSERT_EQ(INITIAL, stored_state->group_type()); |
3887 // Parsing completed successfully. | 3885 // Parsing completed successfully. |
3888 return builder->ToRegExp(); | 3886 return builder->ToRegExp(); |
3889 case ')': { | 3887 case ')': { |
3890 if (!stored_state->IsSubexpression()) { | 3888 if (!stored_state->IsSubexpression()) { |
3891 ReportError(CStrVector("Unexpected ')'") CHECK_FAILED); | 3889 ReportError(CStrVector("Unmatched ')'") CHECK_FAILED); |
3892 } | 3890 } |
3893 ASSERT_NE(INITIAL, stored_state->group_type()); | 3891 ASSERT_NE(INITIAL, stored_state->group_type()); |
3894 | 3892 |
3895 Advance(); | 3893 Advance(); |
3896 // End disjunction parsing and convert builder content to new single | 3894 // End disjunction parsing and convert builder content to new single |
3897 // regexp atom. | 3895 // regexp atom. |
3898 RegExpTree* body = builder->ToRegExp(); | 3896 RegExpTree* body = builder->ToRegExp(); |
3899 | 3897 |
3900 int end_capture_index = captures_started(); | 3898 int end_capture_index = captures_started(); |
3901 | 3899 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4021 // | 4019 // |
4022 // CharacterClassEscape :: one of | 4020 // CharacterClassEscape :: one of |
4023 // d D s S w W | 4021 // d D s S w W |
4024 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': { | 4022 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': { |
4025 uc32 c = Next(); | 4023 uc32 c = Next(); |
4026 Advance(2); | 4024 Advance(2); |
4027 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); | 4025 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); |
4028 CharacterRange::AddClassEscape(c, ranges); | 4026 CharacterRange::AddClassEscape(c, ranges); |
4029 RegExpTree* atom = new RegExpCharacterClass(ranges, false); | 4027 RegExpTree* atom = new RegExpCharacterClass(ranges, false); |
4030 builder->AddAtom(atom); | 4028 builder->AddAtom(atom); |
4031 goto has_read_atom; // Avoid setting has_character_escapes_. | 4029 break; |
4032 } | 4030 } |
4033 case '1': case '2': case '3': case '4': case '5': case '6': | 4031 case '1': case '2': case '3': case '4': case '5': case '6': |
4034 case '7': case '8': case '9': { | 4032 case '7': case '8': case '9': { |
4035 int index = 0; | 4033 int index = 0; |
4036 if (ParseBackReferenceIndex(&index)) { | 4034 if (ParseBackReferenceIndex(&index)) { |
4037 RegExpCapture* capture = NULL; | 4035 RegExpCapture* capture = NULL; |
4038 if (captures_ != NULL && index <= captures_->length()) { | 4036 if (captures_ != NULL && index <= captures_->length()) { |
4039 capture = captures_->at(index - 1); | 4037 capture = captures_->at(index - 1); |
4040 } | 4038 } |
4041 if (capture == NULL) { | 4039 if (capture == NULL) { |
4042 builder->AddEmpty(); | 4040 builder->AddEmpty(); |
4043 goto has_read_atom; | 4041 break; |
4044 } | 4042 } |
4045 RegExpTree* atom = new RegExpBackReference(capture); | 4043 RegExpTree* atom = new RegExpBackReference(capture); |
4046 builder->AddAtom(atom); | 4044 builder->AddAtom(atom); |
4047 goto has_read_atom; // Avoid setting has_character_escapes_. | 4045 break; |
4048 } | 4046 } |
4049 uc32 first_digit = Next(); | 4047 uc32 first_digit = Next(); |
4050 if (first_digit == '8' || first_digit == '9') { | 4048 if (first_digit == '8' || first_digit == '9') { |
4051 // Treat as identity escape | 4049 // Treat as identity escape |
4052 builder->AddCharacter(first_digit); | 4050 builder->AddCharacter(first_digit); |
4053 Advance(2); | 4051 Advance(2); |
4054 break; | 4052 break; |
4055 } | 4053 } |
4056 } | 4054 } |
4057 // FALLTHROUGH | 4055 // FALLTHROUGH |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4122 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED); | 4120 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED); |
4123 } | 4121 } |
4124 // fallthrough | 4122 // fallthrough |
4125 } | 4123 } |
4126 default: | 4124 default: |
4127 builder->AddCharacter(current()); | 4125 builder->AddCharacter(current()); |
4128 Advance(); | 4126 Advance(); |
4129 break; | 4127 break; |
4130 } // end switch(current()) | 4128 } // end switch(current()) |
4131 | 4129 |
4132 has_read_atom: | |
4133 int min; | 4130 int min; |
4134 int max; | 4131 int max; |
4135 switch (current()) { | 4132 switch (current()) { |
4136 // QuantifierPrefix :: | 4133 // QuantifierPrefix :: |
4137 // * | 4134 // * |
4138 // + | 4135 // + |
4139 // ? | 4136 // ? |
4140 // { | 4137 // { |
4141 case '*': | 4138 case '*': |
4142 min = 0; | 4139 min = 0; |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4679 start_position, | 4676 start_position, |
4680 is_expression); | 4677 is_expression); |
4681 return result; | 4678 return result; |
4682 } | 4679 } |
4683 | 4680 |
4684 | 4681 |
4685 #undef NEW | 4682 #undef NEW |
4686 | 4683 |
4687 | 4684 |
4688 } } // namespace v8::internal | 4685 } } // namespace v8::internal |
OLD | NEW |