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 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 } else if (c0_ == '\\') { | 1259 } else if (c0_ == '\\') { |
1260 // Scan identifier start character. | 1260 // Scan identifier start character. |
1261 uc32 c = ScanIdentifierUnicodeEscape(); | 1261 uc32 c = ScanIdentifierUnicodeEscape(); |
1262 // Only allow legal identifier start characters. | 1262 // Only allow legal identifier start characters. |
1263 if (c < 0 || | 1263 if (c < 0 || |
1264 c == '\\' || // No recursive escapes. | 1264 c == '\\' || // No recursive escapes. |
1265 !unicode_cache_->IsIdentifierStart(c)) { | 1265 !unicode_cache_->IsIdentifierStart(c)) { |
1266 return Token::ILLEGAL; | 1266 return Token::ILLEGAL; |
1267 } | 1267 } |
1268 AddLiteralChar(c); | 1268 AddLiteralChar(c); |
1269 return ScanIdentifierSuffix(&literal); | 1269 return ScanIdentifierOrKeywordSuffix(&literal); |
1270 } else { | 1270 } else { |
1271 uc32 first_char = c0_; | 1271 uc32 first_char = c0_; |
1272 Advance(); | 1272 Advance(); |
1273 AddLiteralChar(first_char); | 1273 AddLiteralChar(first_char); |
1274 } | 1274 } |
1275 | 1275 |
1276 // Scan the rest of the identifier characters. | 1276 // Scan the rest of the identifier characters. |
1277 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { | 1277 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { |
1278 if (c0_ != '\\') { | 1278 if (c0_ != '\\') { |
1279 uc32 next_char = c0_; | 1279 uc32 next_char = c0_; |
1280 Advance(); | 1280 Advance(); |
1281 AddLiteralChar(next_char); | 1281 AddLiteralChar(next_char); |
1282 continue; | 1282 continue; |
1283 } | 1283 } |
1284 // Fallthrough if no longer able to complete keyword. | 1284 // Fallthrough if a unicode escape is found. |
1285 return ScanIdentifierSuffix(&literal); | 1285 return ScanIdentifierOrKeywordSuffix(&literal); |
1286 } | 1286 } |
1287 | 1287 |
1288 literal.Complete(); | 1288 literal.Complete(); |
1289 | 1289 |
1290 if (next_.literal_chars->is_one_byte()) { | 1290 if (next_.literal_chars->is_one_byte()) { |
1291 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); | 1291 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); |
1292 return KeywordOrIdentifierToken(chars.start(), chars.length()); | 1292 return KeywordOrIdentifierToken(chars.start(), chars.length()); |
1293 } | 1293 } |
1294 return Token::IDENTIFIER; | 1294 return Token::IDENTIFIER; |
1295 } | 1295 } |
1296 | 1296 |
1297 | 1297 |
1298 Token::Value Scanner::ScanIdentifierSuffix(LiteralScope* literal) { | 1298 Token::Value Scanner::ScanIdentifierOrKeywordSuffix(LiteralScope* literal) { |
1299 // Scan the rest of the identifier characters. | 1299 // Scan the rest of the identifier characters. |
1300 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { | 1300 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { |
1301 if (c0_ == '\\') { | 1301 if (c0_ == '\\') { |
1302 uc32 c = ScanIdentifierUnicodeEscape(); | 1302 uc32 c = ScanIdentifierUnicodeEscape(); |
1303 // Only allow legal identifier part characters. | 1303 // Only allow legal identifier part characters. |
1304 if (c < 0 || | 1304 if (c < 0 || |
1305 c == '\\' || | 1305 c == '\\' || |
1306 !unicode_cache_->IsIdentifierPart(c)) { | 1306 !unicode_cache_->IsIdentifierPart(c)) { |
1307 return Token::ILLEGAL; | 1307 return Token::ILLEGAL; |
1308 } | 1308 } |
1309 AddLiteralChar(c); | 1309 AddLiteralChar(c); |
1310 } else { | 1310 } else { |
1311 AddLiteralChar(c0_); | 1311 AddLiteralChar(c0_); |
1312 Advance(); | 1312 Advance(); |
1313 } | 1313 } |
1314 } | 1314 } |
1315 literal->Complete(); | 1315 literal->Complete(); |
1316 | 1316 |
| 1317 if (next_.literal_chars->is_one_byte()) { |
| 1318 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); |
| 1319 return KeywordOrIdentifierToken(chars.start(), chars.length()); |
| 1320 } |
| 1321 |
1317 return Token::IDENTIFIER; | 1322 return Token::IDENTIFIER; |
1318 } | 1323 } |
1319 | 1324 |
1320 | 1325 |
1321 bool Scanner::ScanRegExpPattern(bool seen_equal) { | 1326 bool Scanner::ScanRegExpPattern(bool seen_equal) { |
1322 // Scan: ('/' | '/=') RegularExpressionBody '/' RegularExpressionFlags | 1327 // Scan: ('/' | '/=') RegularExpressionBody '/' RegularExpressionFlags |
1323 bool in_character_class = false; | 1328 bool in_character_class = false; |
1324 | 1329 |
1325 // Previous token is either '/' or '/=', in the second case, the | 1330 // Previous token is either '/' or '/=', in the second case, the |
1326 // pattern starts at =. | 1331 // pattern starts at =. |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1620 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1616 } | 1621 } |
1617 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1622 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1618 | 1623 |
1619 backing_store_.AddBlock(bytes); | 1624 backing_store_.AddBlock(bytes); |
1620 return backing_store_.EndSequence().start(); | 1625 return backing_store_.EndSequence().start(); |
1621 } | 1626 } |
1622 | 1627 |
1623 } // namespace internal | 1628 } // namespace internal |
1624 } // namespace v8 | 1629 } // namespace v8 |
OLD | NEW |