OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 | 91 |
92 // ---------------------------------------------------------------------------- | 92 // ---------------------------------------------------------------------------- |
93 // JavaScriptScanner | 93 // JavaScriptScanner |
94 | 94 |
95 JavaScriptScanner::JavaScriptScanner(UnicodeCache* scanner_contants) | 95 JavaScriptScanner::JavaScriptScanner(UnicodeCache* scanner_contants) |
96 : Scanner(scanner_contants), | 96 : Scanner(scanner_contants), |
97 octal_pos_(Location::invalid()), | 97 octal_pos_(Location::invalid()), |
98 harmony_block_scoping_(false) { } | 98 harmony_scoping_(false) { } |
99 | 99 |
100 | 100 |
101 void JavaScriptScanner::Initialize(UC16CharacterStream* source) { | 101 void JavaScriptScanner::Initialize(UC16CharacterStream* source) { |
102 source_ = source; | 102 source_ = source; |
103 // Need to capture identifiers in order to recognize "get" and "set" | 103 // Need to capture identifiers in order to recognize "get" and "set" |
104 // in object literals. | 104 // in object literals. |
105 Init(); | 105 Init(); |
106 // Skip initial whitespace allowing HTML comment ends just like | 106 // Skip initial whitespace allowing HTML comment ends just like |
107 // after a newline and scan first token. | 107 // after a newline and scan first token. |
108 has_line_terminator_before_next_ = true; | 108 has_line_terminator_before_next_ = true; |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 KEYWORD("for", Token::FOR) \ | 865 KEYWORD("for", Token::FOR) \ |
866 KEYWORD("function", Token::FUNCTION) \ | 866 KEYWORD("function", Token::FUNCTION) \ |
867 KEYWORD_GROUP('i') \ | 867 KEYWORD_GROUP('i') \ |
868 KEYWORD("if", Token::IF) \ | 868 KEYWORD("if", Token::IF) \ |
869 KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \ | 869 KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \ |
870 KEYWORD("import", Token::FUTURE_RESERVED_WORD) \ | 870 KEYWORD("import", Token::FUTURE_RESERVED_WORD) \ |
871 KEYWORD("in", Token::IN) \ | 871 KEYWORD("in", Token::IN) \ |
872 KEYWORD("instanceof", Token::INSTANCEOF) \ | 872 KEYWORD("instanceof", Token::INSTANCEOF) \ |
873 KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \ | 873 KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \ |
874 KEYWORD_GROUP('l') \ | 874 KEYWORD_GROUP('l') \ |
875 KEYWORD("let", harmony_block_scoping \ | 875 KEYWORD("let", harmony_scoping \ |
876 ? Token::LET : Token::FUTURE_STRICT_RESERVED_WORD) \ | 876 ? Token::LET : Token::FUTURE_STRICT_RESERVED_WORD) \ |
877 KEYWORD_GROUP('n') \ | 877 KEYWORD_GROUP('n') \ |
878 KEYWORD("new", Token::NEW) \ | 878 KEYWORD("new", Token::NEW) \ |
879 KEYWORD("null", Token::NULL_LITERAL) \ | 879 KEYWORD("null", Token::NULL_LITERAL) \ |
880 KEYWORD_GROUP('p') \ | 880 KEYWORD_GROUP('p') \ |
881 KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \ | 881 KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \ |
882 KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \ | 882 KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \ |
883 KEYWORD("protected", Token::FUTURE_STRICT_RESERVED_WORD) \ | 883 KEYWORD("protected", Token::FUTURE_STRICT_RESERVED_WORD) \ |
884 KEYWORD("public", Token::FUTURE_STRICT_RESERVED_WORD) \ | 884 KEYWORD("public", Token::FUTURE_STRICT_RESERVED_WORD) \ |
885 KEYWORD_GROUP('r') \ | 885 KEYWORD_GROUP('r') \ |
(...skipping 13 matching lines...) Expand all Loading... |
899 KEYWORD("void", Token::VOID) \ | 899 KEYWORD("void", Token::VOID) \ |
900 KEYWORD_GROUP('w') \ | 900 KEYWORD_GROUP('w') \ |
901 KEYWORD("while", Token::WHILE) \ | 901 KEYWORD("while", Token::WHILE) \ |
902 KEYWORD("with", Token::WITH) \ | 902 KEYWORD("with", Token::WITH) \ |
903 KEYWORD_GROUP('y') \ | 903 KEYWORD_GROUP('y') \ |
904 KEYWORD("yield", Token::FUTURE_STRICT_RESERVED_WORD) | 904 KEYWORD("yield", Token::FUTURE_STRICT_RESERVED_WORD) |
905 | 905 |
906 | 906 |
907 static Token::Value KeywordOrIdentifierToken(const char* input, | 907 static Token::Value KeywordOrIdentifierToken(const char* input, |
908 int input_length, | 908 int input_length, |
909 bool harmony_block_scoping) { | 909 bool harmony_scoping) { |
910 ASSERT(input_length >= 1); | 910 ASSERT(input_length >= 1); |
911 const int kMinLength = 2; | 911 const int kMinLength = 2; |
912 const int kMaxLength = 10; | 912 const int kMaxLength = 10; |
913 if (input_length < kMinLength || input_length > kMaxLength) { | 913 if (input_length < kMinLength || input_length > kMaxLength) { |
914 return Token::IDENTIFIER; | 914 return Token::IDENTIFIER; |
915 } | 915 } |
916 switch (input[0]) { | 916 switch (input[0]) { |
917 default: | 917 default: |
918 #define KEYWORD_GROUP_CASE(ch) \ | 918 #define KEYWORD_GROUP_CASE(ch) \ |
919 break; \ | 919 break; \ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 // Fallthrough if no longer able to complete keyword. | 975 // Fallthrough if no longer able to complete keyword. |
976 return ScanIdentifierSuffix(&literal); | 976 return ScanIdentifierSuffix(&literal); |
977 } | 977 } |
978 | 978 |
979 literal.Complete(); | 979 literal.Complete(); |
980 | 980 |
981 if (next_.literal_chars->is_ascii()) { | 981 if (next_.literal_chars->is_ascii()) { |
982 Vector<const char> chars = next_.literal_chars->ascii_literal(); | 982 Vector<const char> chars = next_.literal_chars->ascii_literal(); |
983 return KeywordOrIdentifierToken(chars.start(), | 983 return KeywordOrIdentifierToken(chars.start(), |
984 chars.length(), | 984 chars.length(), |
985 harmony_block_scoping_); | 985 harmony_scoping_); |
986 } | 986 } |
987 | 987 |
988 return Token::IDENTIFIER; | 988 return Token::IDENTIFIER; |
989 } | 989 } |
990 | 990 |
991 | 991 |
992 Token::Value JavaScriptScanner::ScanIdentifierSuffix(LiteralScope* literal) { | 992 Token::Value JavaScriptScanner::ScanIdentifierSuffix(LiteralScope* literal) { |
993 // Scan the rest of the identifier characters. | 993 // Scan the rest of the identifier characters. |
994 while (unicode_cache_->IsIdentifierPart(c0_)) { | 994 while (unicode_cache_->IsIdentifierPart(c0_)) { |
995 if (c0_ == '\\') { | 995 if (c0_ == '\\') { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 } | 1101 } |
1102 } | 1102 } |
1103 } | 1103 } |
1104 literal.Complete(); | 1104 literal.Complete(); |
1105 | 1105 |
1106 next_.location.end_pos = source_pos() - 1; | 1106 next_.location.end_pos = source_pos() - 1; |
1107 return true; | 1107 return true; |
1108 } | 1108 } |
1109 | 1109 |
1110 } } // namespace v8::internal | 1110 } } // namespace v8::internal |
OLD | NEW |