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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Need to capture identifiers in order to recognize "get" and "set" | 82 // Need to capture identifiers in order to recognize "get" and "set" |
83 // in object literals. | 83 // in object literals. |
84 Init(); | 84 Init(); |
85 // Skip initial whitespace allowing HTML comment ends just like | 85 // Skip initial whitespace allowing HTML comment ends just like |
86 // after a newline and scan first token. | 86 // after a newline and scan first token. |
87 has_line_terminator_before_next_ = true; | 87 has_line_terminator_before_next_ = true; |
88 SkipWhiteSpace(); | 88 SkipWhiteSpace(); |
89 Scan(); | 89 Scan(); |
90 } | 90 } |
91 | 91 |
| 92 |
| 93 // Ensure that tokens can be stored in a byte. |
| 94 STATIC_ASSERT(Token::NUM_TOKENS <= 0x100); |
| 95 |
| 96 // Table of one-character tokens, by character (0x00..0x7f only). |
| 97 static byte one_char_tokens[] = { |
| 98 Token::ILLEGAL, |
| 99 Token::ILLEGAL, |
| 100 Token::ILLEGAL, |
| 101 Token::ILLEGAL, |
| 102 Token::ILLEGAL, |
| 103 Token::ILLEGAL, |
| 104 Token::ILLEGAL, |
| 105 Token::ILLEGAL, |
| 106 Token::ILLEGAL, |
| 107 Token::ILLEGAL, |
| 108 Token::ILLEGAL, |
| 109 Token::ILLEGAL, |
| 110 Token::ILLEGAL, |
| 111 Token::ILLEGAL, |
| 112 Token::ILLEGAL, |
| 113 Token::ILLEGAL, |
| 114 Token::ILLEGAL, |
| 115 Token::ILLEGAL, |
| 116 Token::ILLEGAL, |
| 117 Token::ILLEGAL, |
| 118 Token::ILLEGAL, |
| 119 Token::ILLEGAL, |
| 120 Token::ILLEGAL, |
| 121 Token::ILLEGAL, |
| 122 Token::ILLEGAL, |
| 123 Token::ILLEGAL, |
| 124 Token::ILLEGAL, |
| 125 Token::ILLEGAL, |
| 126 Token::ILLEGAL, |
| 127 Token::ILLEGAL, |
| 128 Token::ILLEGAL, |
| 129 Token::ILLEGAL, |
| 130 Token::ILLEGAL, |
| 131 Token::ILLEGAL, |
| 132 Token::ILLEGAL, |
| 133 Token::ILLEGAL, |
| 134 Token::ILLEGAL, |
| 135 Token::ILLEGAL, |
| 136 Token::ILLEGAL, |
| 137 Token::ILLEGAL, |
| 138 Token::LPAREN, // 0x28 |
| 139 Token::RPAREN, // 0x29 |
| 140 Token::ILLEGAL, |
| 141 Token::ILLEGAL, |
| 142 Token::COMMA, // 0x2c |
| 143 Token::ILLEGAL, |
| 144 Token::ILLEGAL, |
| 145 Token::ILLEGAL, |
| 146 Token::ILLEGAL, |
| 147 Token::ILLEGAL, |
| 148 Token::ILLEGAL, |
| 149 Token::ILLEGAL, |
| 150 Token::ILLEGAL, |
| 151 Token::ILLEGAL, |
| 152 Token::ILLEGAL, |
| 153 Token::ILLEGAL, |
| 154 Token::ILLEGAL, |
| 155 Token::ILLEGAL, |
| 156 Token::COLON, // 0x3a |
| 157 Token::SEMICOLON, // 0x3b |
| 158 Token::ILLEGAL, |
| 159 Token::ILLEGAL, |
| 160 Token::ILLEGAL, |
| 161 Token::CONDITIONAL, // 0x3f |
| 162 Token::ILLEGAL, |
| 163 Token::ILLEGAL, |
| 164 Token::ILLEGAL, |
| 165 Token::ILLEGAL, |
| 166 Token::ILLEGAL, |
| 167 Token::ILLEGAL, |
| 168 Token::ILLEGAL, |
| 169 Token::ILLEGAL, |
| 170 Token::ILLEGAL, |
| 171 Token::ILLEGAL, |
| 172 Token::ILLEGAL, |
| 173 Token::ILLEGAL, |
| 174 Token::ILLEGAL, |
| 175 Token::ILLEGAL, |
| 176 Token::ILLEGAL, |
| 177 Token::ILLEGAL, |
| 178 Token::ILLEGAL, |
| 179 Token::ILLEGAL, |
| 180 Token::ILLEGAL, |
| 181 Token::ILLEGAL, |
| 182 Token::ILLEGAL, |
| 183 Token::ILLEGAL, |
| 184 Token::ILLEGAL, |
| 185 Token::ILLEGAL, |
| 186 Token::ILLEGAL, |
| 187 Token::ILLEGAL, |
| 188 Token::ILLEGAL, |
| 189 Token::LBRACK, // 0x5b |
| 190 Token::ILLEGAL, |
| 191 Token::RBRACK, // 0x5d |
| 192 Token::ILLEGAL, |
| 193 Token::ILLEGAL, |
| 194 Token::ILLEGAL, |
| 195 Token::ILLEGAL, |
| 196 Token::ILLEGAL, |
| 197 Token::ILLEGAL, |
| 198 Token::ILLEGAL, |
| 199 Token::ILLEGAL, |
| 200 Token::ILLEGAL, |
| 201 Token::ILLEGAL, |
| 202 Token::ILLEGAL, |
| 203 Token::ILLEGAL, |
| 204 Token::ILLEGAL, |
| 205 Token::ILLEGAL, |
| 206 Token::ILLEGAL, |
| 207 Token::ILLEGAL, |
| 208 Token::ILLEGAL, |
| 209 Token::ILLEGAL, |
| 210 Token::ILLEGAL, |
| 211 Token::ILLEGAL, |
| 212 Token::ILLEGAL, |
| 213 Token::ILLEGAL, |
| 214 Token::ILLEGAL, |
| 215 Token::ILLEGAL, |
| 216 Token::ILLEGAL, |
| 217 Token::ILLEGAL, |
| 218 Token::ILLEGAL, |
| 219 Token::ILLEGAL, |
| 220 Token::ILLEGAL, |
| 221 Token::LBRACE, // 0x7b |
| 222 Token::ILLEGAL, |
| 223 Token::RBRACE, // 0x7d |
| 224 Token::BIT_NOT, // 0x7e |
| 225 Token::ILLEGAL |
| 226 }; |
| 227 |
| 228 |
92 Token::Value JavaScriptScanner::Next() { | 229 Token::Value JavaScriptScanner::Next() { |
93 current_ = next_; | 230 current_ = next_; |
94 has_line_terminator_before_next_ = false; | 231 has_line_terminator_before_next_ = false; |
95 has_multiline_comment_before_next_ = false; | 232 has_multiline_comment_before_next_ = false; |
| 233 if (static_cast<unsigned>(c0_) <= 0x7f) { |
| 234 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]); |
| 235 if (token != Token::ILLEGAL) { |
| 236 int pos = source_pos(); |
| 237 next_.token = token; |
| 238 next_.location.beg_pos = pos; |
| 239 next_.location.end_pos = pos + 1; |
| 240 Advance(); |
| 241 return current_.token; |
| 242 } |
| 243 } |
96 Scan(); | 244 Scan(); |
97 return current_.token; | 245 return current_.token; |
98 } | 246 } |
99 | 247 |
100 | 248 |
101 static inline bool IsByteOrderMark(uc32 c) { | 249 static inline bool IsByteOrderMark(uc32 c) { |
102 // The Unicode value U+FFFE is guaranteed never to be assigned as a | 250 // The Unicode value U+FFFE is guaranteed never to be assigned as a |
103 // Unicode character; this implies that in a Unicode context the | 251 // Unicode character; this implies that in a Unicode context the |
104 // 0xFF, 0xFE byte pattern can only be interpreted as the U+FEFF | 252 // 0xFF, 0xFE byte pattern can only be interpreted as the U+FEFF |
105 // character expressed in little-endian byte order (since it could | 253 // character expressed in little-endian byte order (since it could |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; | 1105 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; |
958 break; | 1106 break; |
959 case UNMATCHABLE: | 1107 case UNMATCHABLE: |
960 break; | 1108 break; |
961 } | 1109 } |
962 // On fallthrough, it's a failure. | 1110 // On fallthrough, it's a failure. |
963 state_ = UNMATCHABLE; | 1111 state_ = UNMATCHABLE; |
964 } | 1112 } |
965 | 1113 |
966 } } // namespace v8::internal | 1114 } } // namespace v8::internal |
OLD | NEW |