| 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 4434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4445 } else { | 4445 } else { |
| 4446 Advance(); | 4446 Advance(); |
| 4447 return CharacterRange::Singleton(first); | 4447 return CharacterRange::Singleton(first); |
| 4448 } | 4448 } |
| 4449 } | 4449 } |
| 4450 | 4450 |
| 4451 | 4451 |
| 4452 RegExpTree* RegExpParser::ParseCharacterClass() { | 4452 RegExpTree* RegExpParser::ParseCharacterClass() { |
| 4453 static const char* kUnterminated = "Unterminated character class"; | 4453 static const char* kUnterminated = "Unterminated character class"; |
| 4454 static const char* kRangeOutOfOrder = "Range out of order in character class"; | 4454 static const char* kRangeOutOfOrder = "Range out of order in character class"; |
| 4455 static const char* kInvalidRange = "Invalid character range"; | |
| 4456 | 4455 |
| 4457 ASSERT_EQ(current(), '['); | 4456 ASSERT_EQ(current(), '['); |
| 4458 Advance(); | 4457 Advance(); |
| 4459 bool is_negated = false; | 4458 bool is_negated = false; |
| 4460 if (current() == '^') { | 4459 if (current() == '^') { |
| 4461 is_negated = true; | 4460 is_negated = true; |
| 4462 Advance(); | 4461 Advance(); |
| 4463 } | 4462 } |
| 4464 // A CharacterClass is a sequence of single characters, character class | |
| 4465 // escapes or ranges. Ranges are on the form "x-y" where x and y are | |
| 4466 // single characters (and not character class escapes like \s). | |
| 4467 // A "-" may occur at the start or end of the character class (just after | |
| 4468 // "[" or "[^", or just before "]") without being considered part of a | |
| 4469 // range. A "-" may also appear as the beginning or end of a range. | |
| 4470 // I.e., [--+] is valid, so is [!--]. | |
| 4471 | |
| 4472 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); | 4463 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); |
| 4473 while (has_more() && current() != ']') { | 4464 while (has_more() && current() != ']') { |
| 4474 uc16 char_class = 0; | 4465 uc16 char_class = 0; |
| 4475 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); | 4466 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); |
| 4476 if (char_class) { | 4467 if (char_class) { |
| 4477 CharacterRange::AddClassEscape(char_class, ranges); | 4468 CharacterRange::AddClassEscape(char_class, ranges); |
| 4478 if (current() == '-') { | |
| 4479 Advance(); | |
| 4480 ranges->Add(CharacterRange::Singleton('-')); | |
| 4481 if (current() != ']') { | |
| 4482 ReportError(CStrVector(kInvalidRange) CHECK_FAILED); | |
| 4483 } | |
| 4484 break; | |
| 4485 } | |
| 4486 continue; | 4469 continue; |
| 4487 } | 4470 } |
| 4488 if (current() == '-') { | 4471 if (current() == '-') { |
| 4489 Advance(); | 4472 Advance(); |
| 4490 if (current() == kEndMarker) { | 4473 if (current() == kEndMarker) { |
| 4491 // If we reach the end we break out of the loop and let the | 4474 // If we reach the end we break out of the loop and let the |
| 4492 // following code report an error. | 4475 // following code report an error. |
| 4493 break; | 4476 break; |
| 4494 } else if (current() == ']') { | 4477 } else if (current() == ']') { |
| 4495 ranges->Add(first); | 4478 ranges->Add(first); |
| 4496 ranges->Add(CharacterRange::Singleton('-')); | 4479 ranges->Add(CharacterRange::Singleton('-')); |
| 4497 break; | 4480 break; |
| 4498 } | 4481 } |
| 4499 CharacterRange next = ParseClassAtom(&char_class CHECK_FAILED); | 4482 CharacterRange next = ParseClassAtom(&char_class CHECK_FAILED); |
| 4500 if (char_class) { | 4483 if (char_class) { |
| 4501 ReportError(CStrVector(kInvalidRange) CHECK_FAILED); | 4484 ranges->Add(first); |
| 4485 ranges->Add(CharacterRange::Singleton('-')); |
| 4486 CharacterRange::AddClassEscape(char_class, ranges); |
| 4487 continue; |
| 4502 } | 4488 } |
| 4503 if (first.from() > next.to()) { | 4489 if (first.from() > next.to()) { |
| 4504 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); | 4490 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); |
| 4505 } | 4491 } |
| 4506 ranges->Add(CharacterRange::Range(first.from(), next.to())); | 4492 ranges->Add(CharacterRange::Range(first.from(), next.to())); |
| 4507 } else { | 4493 } else { |
| 4508 ranges->Add(first); | 4494 ranges->Add(first); |
| 4509 } | 4495 } |
| 4510 } | 4496 } |
| 4511 if (!has_more()) { | 4497 if (!has_more()) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4693 Handle<String> source = Handle<String>(String::cast(script->source())); | 4679 Handle<String> source = Handle<String>(String::cast(script->source())); |
| 4694 result = parser.ParseProgram(source, info->is_global()); | 4680 result = parser.ParseProgram(source, info->is_global()); |
| 4695 } | 4681 } |
| 4696 } | 4682 } |
| 4697 | 4683 |
| 4698 info->SetFunction(result); | 4684 info->SetFunction(result); |
| 4699 return (result != NULL); | 4685 return (result != NULL); |
| 4700 } | 4686 } |
| 4701 | 4687 |
| 4702 } } // namespace v8::internal | 4688 } } // namespace v8::internal |
| OLD | NEW |