OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 case '?': | 640 case '?': |
641 token = Select(Token::CONDITIONAL); | 641 token = Select(Token::CONDITIONAL); |
642 break; | 642 break; |
643 | 643 |
644 case '~': | 644 case '~': |
645 token = Select(Token::BIT_NOT); | 645 token = Select(Token::BIT_NOT); |
646 break; | 646 break; |
647 | 647 |
648 case '`': | 648 case '`': |
649 if (HarmonyTemplates()) { | 649 if (HarmonyTemplates()) { |
650 token = ScanTemplateSpan(); | 650 token = ScanTemplateStart(); |
651 break; | 651 break; |
652 } | 652 } |
653 | 653 |
654 default: | 654 default: |
655 if (c0_ < 0) { | 655 if (c0_ < 0) { |
656 token = Token::EOS; | 656 token = Token::EOS; |
657 } else if (unicode_cache_->IsIdentifierStart(c0_)) { | 657 } else if (unicode_cache_->IsIdentifierStart(c0_)) { |
658 token = ScanIdentifierOrKeyword(); | 658 token = ScanIdentifierOrKeyword(); |
659 } else if (IsDecimalDigit(c0_)) { | 659 } else if (IsDecimalDigit(c0_)) { |
660 token = ScanNumber(false); | 660 token = ScanNumber(false); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 // ` LiteralChars* ${ | 801 // ` LiteralChars* ${ |
802 // | } LiteralChars* ${ | 802 // | } LiteralChars* ${ |
803 // | 803 // |
804 // TEMPLATE_TAIL :: | 804 // TEMPLATE_TAIL :: |
805 // ` LiteralChars* ` | 805 // ` LiteralChars* ` |
806 // | } LiteralChar* ` | 806 // | } LiteralChar* ` |
807 // | 807 // |
808 // A TEMPLATE_SPAN should always be followed by an Expression, while a | 808 // A TEMPLATE_SPAN should always be followed by an Expression, while a |
809 // TEMPLATE_TAIL terminates a TemplateLiteral and does not need to be | 809 // TEMPLATE_TAIL terminates a TemplateLiteral and does not need to be |
810 // followed by an Expression. | 810 // followed by an Expression. |
811 // | |
812 | 811 |
813 if (next_.token == Token::RBRACE) { | |
814 // After parsing an Expression, the source position is incorrect due to | |
815 // having scanned the brace. Push the RBRACE back into the stream. | |
816 PushBack('}'); | |
817 } | |
818 | |
819 next_.location.beg_pos = source_pos(); | |
820 Token::Value result = Token::TEMPLATE_SPAN; | 812 Token::Value result = Token::TEMPLATE_SPAN; |
821 DCHECK(c0_ == '`' || c0_ == '}'); | |
822 Advance(); // Consume ` or } | |
823 | |
824 LiteralScope literal(this, true); | 813 LiteralScope literal(this, true); |
825 | 814 |
826 while (true) { | 815 while (true) { |
827 uc32 c = c0_; | 816 uc32 c = c0_; |
828 Advance(); | 817 Advance(); |
829 if (c == '`') { | 818 if (c == '`') { |
830 result = Token::TEMPLATE_TAIL; | 819 result = Token::TEMPLATE_TAIL; |
831 ReduceRawLiteralLength(1); | 820 ReduceRawLiteralLength(1); |
832 break; | 821 break; |
833 } else if (c == '$' && c0_ == '{') { | 822 } else if (c == '$' && c0_ == '{') { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 AddLiteralChar(c); | 863 AddLiteralChar(c); |
875 } | 864 } |
876 } | 865 } |
877 literal.Complete(); | 866 literal.Complete(); |
878 next_.location.end_pos = source_pos(); | 867 next_.location.end_pos = source_pos(); |
879 next_.token = result; | 868 next_.token = result; |
880 return result; | 869 return result; |
881 } | 870 } |
882 | 871 |
883 | 872 |
| 873 Token::Value Scanner::ScanTemplateStart() { |
| 874 DCHECK(c0_ == '`'); |
| 875 next_.location.beg_pos = source_pos(); |
| 876 Advance(); // Consume ` |
| 877 return ScanTemplateSpan(); |
| 878 } |
| 879 |
| 880 |
| 881 Token::Value Scanner::ScanTemplateContinuation() { |
| 882 DCHECK_EQ(next_.token, Token::RBRACE); |
| 883 next_.location.beg_pos = source_pos() - 1; // We already consumed } |
| 884 return ScanTemplateSpan(); |
| 885 } |
| 886 |
| 887 |
884 void Scanner::ScanDecimalDigits() { | 888 void Scanner::ScanDecimalDigits() { |
885 while (IsDecimalDigit(c0_)) | 889 while (IsDecimalDigit(c0_)) |
886 AddLiteralCharAdvance(); | 890 AddLiteralCharAdvance(); |
887 } | 891 } |
888 | 892 |
889 | 893 |
890 Token::Value Scanner::ScanNumber(bool seen_period) { | 894 Token::Value Scanner::ScanNumber(bool seen_period) { |
891 DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction | 895 DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction |
892 | 896 |
893 enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL; | 897 enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL; |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 } | 1470 } |
1467 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1471 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1468 } | 1472 } |
1469 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1473 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1470 | 1474 |
1471 backing_store_.AddBlock(bytes); | 1475 backing_store_.AddBlock(bytes); |
1472 return backing_store_.EndSequence().start(); | 1476 return backing_store_.EndSequence().start(); |
1473 } | 1477 } |
1474 | 1478 |
1475 } } // namespace v8::internal | 1479 } } // namespace v8::internal |
OLD | NEW |