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 "src/scanner.h" | 7 #include "src/scanner.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 } | 1386 } |
1387 } | 1387 } |
1388 Advance(); // consume '/' | 1388 Advance(); // consume '/' |
1389 | 1389 |
1390 literal.Complete(); | 1390 literal.Complete(); |
1391 | 1391 |
1392 return true; | 1392 return true; |
1393 } | 1393 } |
1394 | 1394 |
1395 | 1395 |
1396 bool Scanner::ScanRegExpFlags() { | 1396 Maybe<RegExp::Flags> Scanner::ScanRegExpFlags() { |
1397 // Scan regular expression flags. | 1397 // Scan regular expression flags. |
1398 LiteralScope literal(this); | 1398 LiteralScope literal(this); |
| 1399 int flags = 0; |
1399 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { | 1400 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { |
1400 if (c0_ != '\\') { | 1401 RegExp::Flags flag = RegExp::kNone; |
1401 AddLiteralCharAdvance(); | 1402 switch (c0_) { |
1402 } else { | 1403 case 'g': |
1403 return false; | 1404 flag = RegExp::kGlobal; |
| 1405 break; |
| 1406 case 'i': |
| 1407 flag = RegExp::kIgnoreCase; |
| 1408 break; |
| 1409 case 'm': |
| 1410 flag = RegExp::kMultiline; |
| 1411 break; |
| 1412 case 'u': |
| 1413 if (!FLAG_harmony_unicode_regexps) return Nothing<RegExp::Flags>(); |
| 1414 flag = RegExp::kUnicode; |
| 1415 break; |
| 1416 case 'y': |
| 1417 if (!FLAG_harmony_regexps) return Nothing<RegExp::Flags>(); |
| 1418 flag = RegExp::kSticky; |
| 1419 break; |
| 1420 default: |
| 1421 return Nothing<RegExp::Flags>(); |
1404 } | 1422 } |
| 1423 if (flags & flag) return Nothing<RegExp::Flags>(); |
| 1424 AddLiteralCharAdvance(); |
| 1425 flags |= flag; |
1405 } | 1426 } |
1406 literal.Complete(); | 1427 literal.Complete(); |
1407 | 1428 |
1408 next_.location.end_pos = source_pos(); | 1429 next_.location.end_pos = source_pos(); |
1409 return true; | 1430 return Just(RegExp::Flags(flags)); |
1410 } | 1431 } |
1411 | 1432 |
1412 | 1433 |
1413 const AstRawString* Scanner::CurrentSymbol(AstValueFactory* ast_value_factory) { | 1434 const AstRawString* Scanner::CurrentSymbol(AstValueFactory* ast_value_factory) { |
1414 if (is_literal_one_byte()) { | 1435 if (is_literal_one_byte()) { |
1415 return ast_value_factory->GetOneByteString(literal_one_byte_string()); | 1436 return ast_value_factory->GetOneByteString(literal_one_byte_string()); |
1416 } | 1437 } |
1417 return ast_value_factory->GetTwoByteString(literal_two_byte_string()); | 1438 return ast_value_factory->GetTwoByteString(literal_two_byte_string()); |
1418 } | 1439 } |
1419 | 1440 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1643 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1664 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1644 } | 1665 } |
1645 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1666 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1646 | 1667 |
1647 backing_store_.AddBlock(bytes); | 1668 backing_store_.AddBlock(bytes); |
1648 return backing_store_.EndSequence().start(); | 1669 return backing_store_.EndSequence().start(); |
1649 } | 1670 } |
1650 | 1671 |
1651 } // namespace internal | 1672 } // namespace internal |
1652 } // namespace v8 | 1673 } // namespace v8 |
OLD | NEW |