OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 4386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4397 } else { | 4397 } else { |
4398 Advance(); | 4398 Advance(); |
4399 return CharacterRange::Singleton(first); | 4399 return CharacterRange::Singleton(first); |
4400 } | 4400 } |
4401 } | 4401 } |
4402 | 4402 |
4403 | 4403 |
4404 RegExpTree* RegExpParser::ParseCharacterClass() { | 4404 RegExpTree* RegExpParser::ParseCharacterClass() { |
4405 static const char* kUnterminated = "Unterminated character class"; | 4405 static const char* kUnterminated = "Unterminated character class"; |
4406 static const char* kRangeOutOfOrder = "Range out of order in character class"; | 4406 static const char* kRangeOutOfOrder = "Range out of order in character class"; |
| 4407 static const char* kInvalidRange = "Invalid character range"; |
4407 | 4408 |
4408 ASSERT_EQ(current(), '['); | 4409 ASSERT_EQ(current(), '['); |
4409 Advance(); | 4410 Advance(); |
4410 bool is_negated = false; | 4411 bool is_negated = false; |
4411 if (current() == '^') { | 4412 if (current() == '^') { |
4412 is_negated = true; | 4413 is_negated = true; |
4413 Advance(); | 4414 Advance(); |
4414 } | 4415 } |
| 4416 // A CharacterClass is a sequence of single characters, character class |
| 4417 // escapes or ranges. Ranges are on the form "x-y" where x and y are |
| 4418 // single characters (and not character class escapes like \s). |
| 4419 // A "-" may occur at the start or end of the character class (just after |
| 4420 // "[" or "[^", or just before "]") without being considered part of a |
| 4421 // range. A "-" may also appear as the beginning or end of a range. |
| 4422 // I.e., [--+] is valid, so is [!--]. |
| 4423 |
4415 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); | 4424 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); |
4416 while (has_more() && current() != ']') { | 4425 while (has_more() && current() != ']') { |
4417 uc16 char_class = 0; | 4426 uc16 char_class = 0; |
4418 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); | 4427 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); |
4419 if (char_class) { | 4428 if (char_class) { |
4420 CharacterRange::AddClassEscape(char_class, ranges); | 4429 CharacterRange::AddClassEscape(char_class, ranges); |
| 4430 if (current() == '-') { |
| 4431 Advance(); |
| 4432 ranges->Add(CharacterRange::Singleton('-')); |
| 4433 if (current() != ']') { |
| 4434 ReportError(CStrVector(kInvalidRange) CHECK_FAILED); |
| 4435 } |
| 4436 break; |
| 4437 } |
4421 continue; | 4438 continue; |
4422 } | 4439 } |
4423 if (current() == '-') { | 4440 if (current() == '-') { |
4424 Advance(); | 4441 Advance(); |
4425 if (current() == kEndMarker) { | 4442 if (current() == kEndMarker) { |
4426 // If we reach the end we break out of the loop and let the | 4443 // If we reach the end we break out of the loop and let the |
4427 // following code report an error. | 4444 // following code report an error. |
4428 break; | 4445 break; |
4429 } else if (current() == ']') { | 4446 } else if (current() == ']') { |
4430 ranges->Add(first); | 4447 ranges->Add(first); |
4431 ranges->Add(CharacterRange::Singleton('-')); | 4448 ranges->Add(CharacterRange::Singleton('-')); |
4432 break; | 4449 break; |
4433 } | 4450 } |
4434 CharacterRange next = ParseClassAtom(&char_class CHECK_FAILED); | 4451 CharacterRange next = ParseClassAtom(&char_class CHECK_FAILED); |
4435 if (char_class) { | 4452 if (char_class) { |
4436 ranges->Add(first); | 4453 ReportError(CStrVector(kInvalidRange) CHECK_FAILED); |
4437 ranges->Add(CharacterRange::Singleton('-')); | |
4438 CharacterRange::AddClassEscape(char_class, ranges); | |
4439 continue; | |
4440 } | 4454 } |
4441 if (first.from() > next.to()) { | 4455 if (first.from() > next.to()) { |
4442 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); | 4456 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); |
4443 } | 4457 } |
4444 ranges->Add(CharacterRange::Range(first.from(), next.to())); | 4458 ranges->Add(CharacterRange::Range(first.from(), next.to())); |
4445 } else { | 4459 } else { |
4446 ranges->Add(first); | 4460 ranges->Add(first); |
4447 } | 4461 } |
4448 } | 4462 } |
4449 if (!has_more()) { | 4463 if (!has_more()) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4636 Handle<String> source = Handle<String>(String::cast(script->source())); | 4650 Handle<String> source = Handle<String>(String::cast(script->source())); |
4637 result = parser.ParseProgram(source, info->is_global()); | 4651 result = parser.ParseProgram(source, info->is_global()); |
4638 } | 4652 } |
4639 } | 4653 } |
4640 | 4654 |
4641 info->SetFunction(result); | 4655 info->SetFunction(result); |
4642 return (result != NULL); | 4656 return (result != NULL); |
4643 } | 4657 } |
4644 | 4658 |
4645 } } // namespace v8::internal | 4659 } } // namespace v8::internal |
OLD | NEW |