| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 class RegExpBuilder: public ZoneObject { | 364 class RegExpBuilder: public ZoneObject { |
| 365 public: | 365 public: |
| 366 RegExpBuilder(); | 366 RegExpBuilder(); |
| 367 void AddCharacter(uc16 character); | 367 void AddCharacter(uc16 character); |
| 368 // "Adds" an empty expression. Does nothing except consume a | 368 // "Adds" an empty expression. Does nothing except consume a |
| 369 // following quantifier | 369 // following quantifier |
| 370 void AddEmpty(); | 370 void AddEmpty(); |
| 371 void AddAtom(RegExpTree* tree); | 371 void AddAtom(RegExpTree* tree); |
| 372 void AddAssertion(RegExpTree* tree); | 372 void AddAssertion(RegExpTree* tree); |
| 373 void NewAlternative(); // '|' | 373 void NewAlternative(); // '|' |
| 374 void AddQuantifierToAtom(int min, int max, bool is_greedy); | 374 void AddQuantifierToAtom(int min, int max, RegExpQuantifier::Type type); |
| 375 RegExpTree* ToRegExp(); | 375 RegExpTree* ToRegExp(); |
| 376 private: | 376 private: |
| 377 void FlushCharacters(); | 377 void FlushCharacters(); |
| 378 void FlushText(); | 378 void FlushText(); |
| 379 void FlushTerms(); | 379 void FlushTerms(); |
| 380 bool pending_empty_; | 380 bool pending_empty_; |
| 381 ZoneList<uc16>* characters_; | 381 ZoneList<uc16>* characters_; |
| 382 BufferedZoneList<RegExpTree, 2> terms_; | 382 BufferedZoneList<RegExpTree, 2> terms_; |
| 383 BufferedZoneList<RegExpTree, 2> text_; | 383 BufferedZoneList<RegExpTree, 2> text_; |
| 384 BufferedZoneList<RegExpTree, 2> alternatives_; | 384 BufferedZoneList<RegExpTree, 2> alternatives_; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 if (num_alternatives == 0) { | 496 if (num_alternatives == 0) { |
| 497 return RegExpEmpty::GetInstance(); | 497 return RegExpEmpty::GetInstance(); |
| 498 } | 498 } |
| 499 if (num_alternatives == 1) { | 499 if (num_alternatives == 1) { |
| 500 return alternatives_.last(); | 500 return alternatives_.last(); |
| 501 } | 501 } |
| 502 return new RegExpDisjunction(alternatives_.GetList()); | 502 return new RegExpDisjunction(alternatives_.GetList()); |
| 503 } | 503 } |
| 504 | 504 |
| 505 | 505 |
| 506 void RegExpBuilder::AddQuantifierToAtom(int min, int max, bool is_greedy) { | 506 void RegExpBuilder::AddQuantifierToAtom(int min, |
| 507 int max, |
| 508 RegExpQuantifier::Type type) { |
| 507 if (pending_empty_) { | 509 if (pending_empty_) { |
| 508 pending_empty_ = false; | 510 pending_empty_ = false; |
| 509 return; | 511 return; |
| 510 } | 512 } |
| 511 RegExpTree* atom; | 513 RegExpTree* atom; |
| 512 if (characters_ != NULL) { | 514 if (characters_ != NULL) { |
| 513 ASSERT(last_added_ == ADD_CHAR); | 515 ASSERT(last_added_ == ADD_CHAR); |
| 514 // Last atom was character. | 516 // Last atom was character. |
| 515 Vector<const uc16> char_vector = characters_->ToConstVector(); | 517 Vector<const uc16> char_vector = characters_->ToConstVector(); |
| 516 int num_chars = char_vector.length(); | 518 int num_chars = char_vector.length(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 536 return; | 538 return; |
| 537 } | 539 } |
| 538 terms_.Add(atom); | 540 terms_.Add(atom); |
| 539 return; | 541 return; |
| 540 } | 542 } |
| 541 } else { | 543 } else { |
| 542 // Only call immediately after adding an atom or character! | 544 // Only call immediately after adding an atom or character! |
| 543 UNREACHABLE(); | 545 UNREACHABLE(); |
| 544 return; | 546 return; |
| 545 } | 547 } |
| 546 terms_.Add(new RegExpQuantifier(min, max, is_greedy, atom)); | 548 terms_.Add(new RegExpQuantifier(min, max, type, atom)); |
| 547 LAST(ADD_TERM); | 549 LAST(ADD_TERM); |
| 548 } | 550 } |
| 549 | 551 |
| 550 | 552 |
| 551 class RegExpParser { | 553 class RegExpParser { |
| 552 public: | 554 public: |
| 553 RegExpParser(FlatStringReader* in, | 555 RegExpParser(FlatStringReader* in, |
| 554 Handle<String>* error, | 556 Handle<String>* error, |
| 555 bool multiline_mode); | 557 bool multiline_mode); |
| 556 RegExpTree* ParsePattern(); | 558 RegExpTree* ParsePattern(); |
| (...skipping 3714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4271 ReportError(CStrVector("numbers out of order in {} quantifier.") | 4273 ReportError(CStrVector("numbers out of order in {} quantifier.") |
| 4272 CHECK_FAILED); | 4274 CHECK_FAILED); |
| 4273 } | 4275 } |
| 4274 break; | 4276 break; |
| 4275 } else { | 4277 } else { |
| 4276 continue; | 4278 continue; |
| 4277 } | 4279 } |
| 4278 default: | 4280 default: |
| 4279 continue; | 4281 continue; |
| 4280 } | 4282 } |
| 4281 bool is_greedy = true; | 4283 RegExpQuantifier::Type type = RegExpQuantifier::GREEDY; |
| 4282 if (current() == '?') { | 4284 if (current() == '?') { |
| 4283 is_greedy = false; | 4285 type = RegExpQuantifier::NON_GREEDY; |
| 4286 Advance(); |
| 4287 } else if (FLAG_regexp_possessive_quantifier && current() == '+') { |
| 4288 // FLAG_regexp_possessive_quantifier is a debug-only flag. |
| 4289 type = RegExpQuantifier::POSSESSIVE; |
| 4284 Advance(); | 4290 Advance(); |
| 4285 } | 4291 } |
| 4286 builder->AddQuantifierToAtom(min, max, is_greedy); | 4292 builder->AddQuantifierToAtom(min, max, type); |
| 4287 } | 4293 } |
| 4288 } | 4294 } |
| 4289 | 4295 |
| 4290 class SourceCharacter { | 4296 class SourceCharacter { |
| 4291 public: | 4297 public: |
| 4292 static bool Is(uc32 c) { | 4298 static bool Is(uc32 c) { |
| 4293 switch (c) { | 4299 switch (c) { |
| 4294 // case ']': case '}': | 4300 // case ']': case '}': |
| 4295 // In spidermonkey and jsc these are treated as source characters | 4301 // In spidermonkey and jsc these are treated as source characters |
| 4296 // so we do too. | 4302 // so we do too. |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4790 start_position, | 4796 start_position, |
| 4791 is_expression); | 4797 is_expression); |
| 4792 return result; | 4798 return result; |
| 4793 } | 4799 } |
| 4794 | 4800 |
| 4795 | 4801 |
| 4796 #undef NEW | 4802 #undef NEW |
| 4797 | 4803 |
| 4798 | 4804 |
| 4799 } } // namespace v8::internal | 4805 } } // namespace v8::internal |
| OLD | NEW |