| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 } | 389 } |
| 390 | 390 |
| 391 | 391 |
| 392 template<typename Char> | 392 template<typename Char> |
| 393 bool ExperimentalScanner<Char>::ScanRegExpPattern(bool seen_equal) { | 393 bool ExperimentalScanner<Char>::ScanRegExpPattern(bool seen_equal) { |
| 394 // Scan: ('/' | '/=') RegularExpressionBody '/' RegularExpressionFlags | 394 // Scan: ('/' | '/=') RegularExpressionBody '/' RegularExpressionFlags |
| 395 bool in_character_class = false; | 395 bool in_character_class = false; |
| 396 | 396 |
| 397 // Previous token is either '/' or '/=', in the second case, the | 397 // Previous token is either '/' or '/=', in the second case, the |
| 398 // pattern starts at =. | 398 // pattern starts at =. |
| 399 next_.beg_pos = (cursor_ - buffer_) - (seen_equal ? 2 : 1); | 399 next_.beg_pos = next_.end_pos = (cursor_ - buffer_) - (seen_equal ? 1 : 0); |
| 400 next_.end_pos = (cursor_ - buffer_) - (seen_equal ? 1 : 0); | |
| 401 | 400 |
| 402 // Scan regular expression body: According to ECMA-262, 3rd, 7.8.5, | 401 // Scan regular expression body: According to ECMA-262, 3rd, 7.8.5, |
| 403 // the scanner should pass uninterpreted bodies to the RegExp | 402 // the scanner should pass uninterpreted bodies to the RegExp |
| 404 // constructor. | 403 // constructor. |
| 405 if (cursor_ >= buffer_end_) return false; | 404 if (cursor_ >= buffer_end_) return false; |
| 406 | 405 |
| 407 while (*cursor_ != '/' || in_character_class) { | 406 while (*cursor_ != '/' || in_character_class) { |
| 408 if (unicode_cache_->IsLineTerminator(*cursor_)) return false; | 407 if (unicode_cache_->IsLineTerminator(*cursor_)) return false; |
| 409 if (*cursor_ == '\\') { // Escape sequence. | 408 if (*cursor_ == '\\') { // Escape sequence. |
| 410 ++cursor_; | 409 ++cursor_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 421 // of the escape sequence. | 420 // of the escape sequence. |
| 422 | 421 |
| 423 // TODO(896): At some point, parse RegExps more throughly to capture | 422 // TODO(896): At some point, parse RegExps more throughly to capture |
| 424 // octal esacpes in strict mode. | 423 // octal esacpes in strict mode. |
| 425 } else { // Unescaped character. | 424 } else { // Unescaped character. |
| 426 if (*cursor_ == '[') in_character_class = true; | 425 if (*cursor_ == '[') in_character_class = true; |
| 427 if (*cursor_ == ']') in_character_class = false; | 426 if (*cursor_ == ']') in_character_class = false; |
| 428 if (++cursor_ >= buffer_end_) return false; | 427 if (++cursor_ >= buffer_end_) return false; |
| 429 } | 428 } |
| 430 } | 429 } |
| 430 next_.end_pos = (cursor_ - buffer_); |
| 431 ++cursor_; // consume '/' | 431 ++cursor_; // consume '/' |
| 432 return true; | 432 return true; |
| 433 } | 433 } |
| 434 | 434 |
| 435 | 435 |
| 436 template<typename Char> | 436 template<typename Char> |
| 437 bool ExperimentalScanner<Char>::ScanRegExpFlags() { | 437 bool ExperimentalScanner<Char>::ScanRegExpFlags() { |
| 438 next_.beg_pos = cursor_ - buffer_; |
| 438 // Scan regular expression flags. | 439 // Scan regular expression flags. |
| 439 while (cursor_ < buffer_end_ && unicode_cache_->IsIdentifierPart(*cursor_)) { | 440 while (cursor_ < buffer_end_ && unicode_cache_->IsIdentifierPart(*cursor_)) { |
| 440 if (*cursor_ != '\\') { | 441 if (*cursor_ != '\\') { |
| 441 if (++cursor_ >= buffer_end_) break; | 442 if (++cursor_ >= buffer_end_) break; |
| 442 } else { | 443 } else { |
| 443 if (!ScanLiteralUnicodeEscape()) break; | 444 if (!ScanLiteralUnicodeEscape()) break; |
| 444 if (++cursor_ >= buffer_end_) break; | 445 if (++cursor_ >= buffer_end_) break; |
| 445 } | 446 } |
| 446 } | 447 } |
| 447 next_.end_pos = cursor_ - buffer_ - 1; | 448 next_.end_pos = cursor_ - buffer_; |
| 448 return true; | 449 return true; |
| 449 } | 450 } |
| 450 | 451 |
| 451 | 452 |
| 452 template<typename Char> | 453 template<typename Char> |
| 453 uc32 ExperimentalScanner<Char>::ScanHexNumber(int length) { | 454 uc32 ExperimentalScanner<Char>::ScanHexNumber(int length) { |
| 454 // We have seen \uXXXX, let's see what it is. | 455 // We have seen \uXXXX, let's see what it is. |
| 455 uc32 x = 0; | 456 uc32 x = 0; |
| 456 for (const Char* s = cursor_ - length; s != cursor_; ++s) { | 457 for (const Char* s = cursor_ - length; s != cursor_; ++s) { |
| 457 int d = HexValue(*s); | 458 int d = HexValue(*s); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 // character. | 602 // character. |
| 602 const Char* temp_cursor = last_octal_end_ - 1; | 603 const Char* temp_cursor = last_octal_end_ - 1; |
| 603 while (temp_cursor >= buffer_ && *temp_cursor >= '0' && *temp_cursor <= '7') | 604 while (temp_cursor >= buffer_ && *temp_cursor >= '0' && *temp_cursor <= '7') |
| 604 --temp_cursor; | 605 --temp_cursor; |
| 605 return Location(temp_cursor - buffer_ + 1, last_octal_end_ - buffer_); | 606 return Location(temp_cursor - buffer_ + 1, last_octal_end_ - buffer_); |
| 606 } | 607 } |
| 607 | 608 |
| 608 } } | 609 } } |
| 609 | 610 |
| 610 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H | 611 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H |
| OLD | NEW |