Chromium Code Reviews| 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 private: | 538 private: |
| 539 uc32 current() { return current_; } | 539 uc32 current() { return current_; } |
| 540 bool has_more() { return has_more_; } | 540 bool has_more() { return has_more_; } |
| 541 bool has_next() { return next_pos_ < in()->length(); } | 541 bool has_next() { return next_pos_ < in()->length(); } |
| 542 uc32 Next(); | 542 uc32 Next(); |
| 543 FlatStringReader* in() { return in_; } | 543 FlatStringReader* in() { return in_; } |
| 544 void ScanForCaptures(); | 544 void ScanForCaptures(); |
| 545 bool CaptureAvailable(int index); | 545 bool CaptureAvailable(int index); |
| 546 uc32 current_; | 546 uc32 current_; |
| 547 bool has_more_; | 547 bool has_more_; |
| 548 bool multiline_mode_; | 548 bool multiline_; |
| 549 int next_pos_; | 549 int next_pos_; |
| 550 FlatStringReader* in_; | 550 FlatStringReader* in_; |
| 551 Handle<String>* error_; | 551 Handle<String>* error_; |
| 552 bool has_character_escapes_; | 552 bool has_character_escapes_; |
| 553 ZoneList<RegExpCapture*>* captures_; | 553 ZoneList<RegExpCapture*>* captures_; |
| 554 bool is_scanned_for_captures_; | 554 bool is_scanned_for_captures_; |
| 555 // The capture count is only valid after we have scanned for captures. | 555 // The capture count is only valid after we have scanned for captures. |
| 556 int capture_count_; | 556 int capture_count_; |
| 557 }; | 557 }; |
| 558 | 558 |
| (...skipping 2933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3492 scanner().location().beg_pos); | 3492 scanner().location().beg_pos); |
| 3493 } | 3493 } |
| 3494 | 3494 |
| 3495 | 3495 |
| 3496 // ---------------------------------------------------------------------------- | 3496 // ---------------------------------------------------------------------------- |
| 3497 // Regular expressions | 3497 // Regular expressions |
| 3498 | 3498 |
| 3499 | 3499 |
| 3500 RegExpParser::RegExpParser(FlatStringReader* in, | 3500 RegExpParser::RegExpParser(FlatStringReader* in, |
| 3501 Handle<String>* error, | 3501 Handle<String>* error, |
| 3502 bool multiline_mode) | 3502 bool multiline) |
| 3503 : current_(kEndMarker), | 3503 : current_(kEndMarker), |
| 3504 has_more_(true), | 3504 has_more_(true), |
| 3505 multiline_mode_(multiline_mode), | 3505 multiline_(multiline), |
| 3506 next_pos_(0), | 3506 next_pos_(0), |
| 3507 in_(in), | 3507 in_(in), |
| 3508 error_(error), | 3508 error_(error), |
| 3509 has_character_escapes_(false), | 3509 has_character_escapes_(false), |
| 3510 captures_(NULL), | 3510 captures_(NULL), |
| 3511 is_scanned_for_captures_(false), | 3511 is_scanned_for_captures_(false), |
| 3512 capture_count_(0) { | 3512 capture_count_(0) { |
| 3513 Advance(1); | 3513 Advance(1); |
| 3514 } | 3514 } |
| 3515 | 3515 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3610 capture_start_index = capture_new_alt_start_index; | 3610 capture_start_index = capture_new_alt_start_index; |
| 3611 continue; | 3611 continue; |
| 3612 } | 3612 } |
| 3613 case '*': | 3613 case '*': |
| 3614 case '+': | 3614 case '+': |
| 3615 case '?': | 3615 case '?': |
| 3616 ReportError(CStrVector("Nothing to repeat"), CHECK_OK); | 3616 ReportError(CStrVector("Nothing to repeat"), CHECK_OK); |
| 3617 case '^': { | 3617 case '^': { |
| 3618 Advance(); | 3618 Advance(); |
| 3619 RegExpAssertion::Type type = | 3619 RegExpAssertion::Type type = |
| 3620 multiline_mode_ ? RegExpAssertion::START_OF_LINE : | 3620 multiline_ ? RegExpAssertion::START_OF_LINE : |
| 3621 RegExpAssertion::START_OF_INPUT; | 3621 RegExpAssertion::START_OF_INPUT; |
| 3622 builder.AddAssertion(new RegExpAssertion(type)); | 3622 builder.AddAssertion(new RegExpAssertion(type)); |
| 3623 continue; | 3623 continue; |
| 3624 } | 3624 } |
| 3625 case '$': { | 3625 case '$': { |
| 3626 Advance(); | 3626 Advance(); |
| 3627 RegExpAssertion::Type type = | 3627 RegExpAssertion::Type type = |
| 3628 multiline_mode_ ? RegExpAssertion::END_OF_LINE : | 3628 multiline_ ? RegExpAssertion::END_OF_LINE : |
| 3629 RegExpAssertion::END_OF_INPUT; | 3629 RegExpAssertion::END_OF_INPUT; |
| 3630 builder.AddAssertion(new RegExpAssertion(type)); | 3630 builder.AddAssertion(new RegExpAssertion(type)); |
| 3631 continue; | 3631 continue; |
| 3632 } | 3632 } |
| 3633 case '.': { | 3633 case '.': { |
| 3634 Advance(); | 3634 Advance(); |
| 3635 // everything except \x0a, \x0d, \u2028 and \u2029 | 3635 // everything except \x0a, \x0d, \u2028 and \u2029 |
| 3636 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); | 3636 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); |
| 3637 CharacterRange::AddClassEscape('.', ranges); | 3637 CharacterRange::AddClassEscape('.', ranges); |
| 3638 RegExpTree* atom = new RegExpCharacterClass(ranges, false); | 3638 RegExpTree* atom = new RegExpCharacterClass(ranges, false); |
| 3639 builder.AddAtom(atom); | 3639 builder.AddAtom(atom); |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4287 PreParser parser(no_script, allow_natives_syntax, extension); | 4287 PreParser parser(no_script, allow_natives_syntax, extension); |
| 4288 if (!parser.PreParseProgram(stream)) return NULL; | 4288 if (!parser.PreParseProgram(stream)) return NULL; |
| 4289 // The list owns the backing store so we need to clone the vector. | 4289 // The list owns the backing store so we need to clone the vector. |
| 4290 // That way, the result will be exactly the right size rather than | 4290 // That way, the result will be exactly the right size rather than |
| 4291 // the expected 50% too large. | 4291 // the expected 50% too large. |
| 4292 Vector<unsigned> store = parser.recorder()->store()->ToVector().Clone(); | 4292 Vector<unsigned> store = parser.recorder()->store()->ToVector().Clone(); |
| 4293 return new ScriptDataImpl(store); | 4293 return new ScriptDataImpl(store); |
| 4294 } | 4294 } |
| 4295 | 4295 |
| 4296 | 4296 |
| 4297 bool ParseRegExp(FlatStringReader* input, RegExpParseResult* result) { | 4297 bool ParseRegExp(FlatStringReader* input, |
| 4298 bool multiline, | |
| 4299 RegExpParseResult* result) { | |
| 4298 ASSERT(result != NULL); | 4300 ASSERT(result != NULL); |
| 4299 // TODO(plesner): Get multiline flag somehow | 4301 // TODO(plesner): Get multiline flag somehow |
|
Erik Corry
2008/11/27 10:30:05
out of date comment
| |
| 4300 RegExpParser parser(input, &result->error, false); | 4302 RegExpParser parser(input, &result->error, multiline); |
| 4301 bool ok = true; | 4303 bool ok = true; |
| 4302 result->tree = parser.ParsePattern(&ok); | 4304 result->tree = parser.ParsePattern(&ok); |
| 4303 if (!ok) { | 4305 if (!ok) { |
| 4304 ASSERT(result->tree == NULL); | 4306 ASSERT(result->tree == NULL); |
| 4305 ASSERT(!result->error.is_null()); | 4307 ASSERT(!result->error.is_null()); |
| 4306 } else { | 4308 } else { |
| 4307 ASSERT(result->tree != NULL); | 4309 ASSERT(result->tree != NULL); |
| 4308 ASSERT(result->error.is_null()); | 4310 ASSERT(result->error.is_null()); |
| 4309 } | 4311 } |
| 4310 if (ok) { | 4312 if (ok) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4360 start_position, | 4362 start_position, |
| 4361 is_expression); | 4363 is_expression); |
| 4362 return result; | 4364 return result; |
| 4363 } | 4365 } |
| 4364 | 4366 |
| 4365 | 4367 |
| 4366 #undef NEW | 4368 #undef NEW |
| 4367 | 4369 |
| 4368 | 4370 |
| 4369 } } // namespace v8::internal | 4371 } } // namespace v8::internal |
| OLD | NEW |