Chromium Code Reviews| 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 4431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4442 uc32 c = ParseClassCharacterEscape(CHECK_FAILED); | 4442 uc32 c = ParseClassCharacterEscape(CHECK_FAILED); |
| 4443 return CharacterRange::Singleton(c); | 4443 return CharacterRange::Singleton(c); |
| 4444 } | 4444 } |
| 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 static inline void AddRangeOrEscape(ZoneList<CharacterRange>* ranges, | |
| 4453 uc16 char_class, | |
| 4454 CharacterRange range) { | |
| 4455 if (char_class) { | |
|
Erik Corry
2010/12/10 14:02:51
char_class == kInvalidCharClass?
| |
| 4456 CharacterRange::AddClassEscape(char_class, ranges); | |
| 4457 } else { | |
| 4458 ranges->Add(range); | |
| 4459 } | |
| 4460 } | |
| 4461 | |
| 4462 | |
| 4452 RegExpTree* RegExpParser::ParseCharacterClass() { | 4463 RegExpTree* RegExpParser::ParseCharacterClass() { |
| 4453 static const char* kUnterminated = "Unterminated character class"; | 4464 static const char* kUnterminated = "Unterminated character class"; |
| 4454 static const char* kRangeOutOfOrder = "Range out of order in character class"; | 4465 static const char* kRangeOutOfOrder = "Range out of order in character class"; |
| 4455 | 4466 |
| 4456 ASSERT_EQ(current(), '['); | 4467 ASSERT_EQ(current(), '['); |
| 4457 Advance(); | 4468 Advance(); |
| 4458 bool is_negated = false; | 4469 bool is_negated = false; |
| 4459 if (current() == '^') { | 4470 if (current() == '^') { |
| 4460 is_negated = true; | 4471 is_negated = true; |
| 4461 Advance(); | 4472 Advance(); |
| 4462 } | 4473 } |
| 4463 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); | 4474 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); |
| 4464 while (has_more() && current() != ']') { | 4475 while (has_more() && current() != ']') { |
| 4465 uc16 char_class = 0; | 4476 uc16 char_class = 0; |
| 4466 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); | 4477 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); |
| 4467 if (char_class) { | |
| 4468 CharacterRange::AddClassEscape(char_class, ranges); | |
| 4469 continue; | |
| 4470 } | |
| 4471 if (current() == '-') { | 4478 if (current() == '-') { |
| 4472 Advance(); | 4479 Advance(); |
| 4473 if (current() == kEndMarker) { | 4480 if (current() == kEndMarker) { |
| 4474 // If we reach the end we break out of the loop and let the | 4481 // If we reach the end we break out of the loop and let the |
| 4475 // following code report an error. | 4482 // following code report an error. |
| 4476 break; | 4483 break; |
| 4477 } else if (current() == ']') { | 4484 } else if (current() == ']') { |
| 4478 ranges->Add(first); | 4485 AddRangeOrEscape(ranges, char_class, first); |
| 4479 ranges->Add(CharacterRange::Singleton('-')); | 4486 ranges->Add(CharacterRange::Singleton('-')); |
| 4480 break; | 4487 break; |
| 4481 } | 4488 } |
| 4482 CharacterRange next = ParseClassAtom(&char_class CHECK_FAILED); | 4489 uc16 char_class_2 = 0; |
|
Erik Corry
2010/12/10 14:02:51
kInvalidCharClass
| |
| 4483 if (char_class) { | 4490 CharacterRange next = ParseClassAtom(&char_class_2 CHECK_FAILED); |
| 4484 ranges->Add(first); | 4491 if (char_class || char_class_2) { |
|
Erik Corry
2010/12/10 14:02:51
And here.
| |
| 4492 // Either end is an escaped character class. Treat the '-' verbatim. | |
| 4493 AddRangeOrEscape(ranges, char_class, first); | |
| 4485 ranges->Add(CharacterRange::Singleton('-')); | 4494 ranges->Add(CharacterRange::Singleton('-')); |
| 4486 CharacterRange::AddClassEscape(char_class, ranges); | 4495 AddRangeOrEscape(ranges, char_class_2, next); |
| 4487 continue; | 4496 continue; |
| 4488 } | 4497 } |
| 4489 if (first.from() > next.to()) { | 4498 if (first.from() > next.to()) { |
| 4490 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); | 4499 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); |
| 4491 } | 4500 } |
| 4492 ranges->Add(CharacterRange::Range(first.from(), next.to())); | 4501 ranges->Add(CharacterRange::Range(first.from(), next.to())); |
| 4493 } else { | 4502 } else { |
| 4494 ranges->Add(first); | 4503 AddRangeOrEscape(ranges, char_class, first); |
| 4495 } | 4504 } |
| 4496 } | 4505 } |
| 4497 if (!has_more()) { | 4506 if (!has_more()) { |
| 4498 return ReportError(CStrVector(kUnterminated) CHECK_FAILED); | 4507 return ReportError(CStrVector(kUnterminated) CHECK_FAILED); |
| 4499 } | 4508 } |
| 4500 Advance(); | 4509 Advance(); |
| 4501 if (ranges->length() == 0) { | 4510 if (ranges->length() == 0) { |
| 4502 ranges->Add(CharacterRange::Everything()); | 4511 ranges->Add(CharacterRange::Everything()); |
| 4503 is_negated = !is_negated; | 4512 is_negated = !is_negated; |
| 4504 } | 4513 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4679 Handle<String> source = Handle<String>(String::cast(script->source())); | 4688 Handle<String> source = Handle<String>(String::cast(script->source())); |
| 4680 result = parser.ParseProgram(source, info->is_global()); | 4689 result = parser.ParseProgram(source, info->is_global()); |
| 4681 } | 4690 } |
| 4682 } | 4691 } |
| 4683 | 4692 |
| 4684 info->SetFunction(result); | 4693 info->SetFunction(result); |
| 4685 return (result != NULL); | 4694 return (result != NULL); |
| 4686 } | 4695 } |
| 4687 | 4696 |
| 4688 } } // namespace v8::internal | 4697 } } // namespace v8::internal |
| OLD | NEW |