OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 } | 509 } |
510 } | 510 } |
511 literal.Complete(); | 511 literal.Complete(); |
512 Advance(); | 512 Advance(); |
513 return Token::STRING; | 513 return Token::STRING; |
514 } | 514 } |
515 | 515 |
516 | 516 |
517 Token::Value JsonScanner::ScanJsonNumber() { | 517 Token::Value JsonScanner::ScanJsonNumber() { |
518 LiteralScope literal(this); | 518 LiteralScope literal(this); |
519 if (c0_ == '-') AddLiteralCharAdvance(); | 519 bool negative = false; |
| 520 |
| 521 if (c0_ == '-') { |
| 522 AddLiteralCharAdvance(); |
| 523 negative = true; |
| 524 } |
520 if (c0_ == '0') { | 525 if (c0_ == '0') { |
521 AddLiteralCharAdvance(); | 526 AddLiteralCharAdvance(); |
522 // Prefix zero is only allowed if it's the only digit before | 527 // Prefix zero is only allowed if it's the only digit before |
523 // a decimal point or exponent. | 528 // a decimal point or exponent. |
524 if ('0' <= c0_ && c0_ <= '9') return Token::ILLEGAL; | 529 if ('0' <= c0_ && c0_ <= '9') return Token::ILLEGAL; |
525 } else { | 530 } else { |
| 531 int i = 0; |
| 532 int digits = 0; |
526 if (c0_ < '1' || c0_ > '9') return Token::ILLEGAL; | 533 if (c0_ < '1' || c0_ > '9') return Token::ILLEGAL; |
527 do { | 534 do { |
| 535 i = i * 10 + c0_ - '0'; |
| 536 digits++; |
528 AddLiteralCharAdvance(); | 537 AddLiteralCharAdvance(); |
529 } while (c0_ >= '0' && c0_ <= '9'); | 538 } while (c0_ >= '0' && c0_ <= '9'); |
| 539 if (c0_ != '.' && c0_ != 'e' && c0_ != 'E' && digits < 10) { |
| 540 number_ = (negative ? -i : i); |
| 541 return Token::NUMBER; |
| 542 } |
530 } | 543 } |
531 if (c0_ == '.') { | 544 if (c0_ == '.') { |
532 AddLiteralCharAdvance(); | 545 AddLiteralCharAdvance(); |
533 if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; | 546 if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; |
534 do { | 547 do { |
535 AddLiteralCharAdvance(); | 548 AddLiteralCharAdvance(); |
536 } while (c0_ >= '0' && c0_ <= '9'); | 549 } while (c0_ >= '0' && c0_ <= '9'); |
537 } | 550 } |
538 if (AsciiAlphaToLower(c0_) == 'e') { | 551 if (AsciiAlphaToLower(c0_) == 'e') { |
539 AddLiteralCharAdvance(); | 552 AddLiteralCharAdvance(); |
540 if (c0_ == '-' || c0_ == '+') AddLiteralCharAdvance(); | 553 if (c0_ == '-' || c0_ == '+') AddLiteralCharAdvance(); |
541 if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; | 554 if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; |
542 do { | 555 do { |
543 AddLiteralCharAdvance(); | 556 AddLiteralCharAdvance(); |
544 } while (c0_ >= '0' && c0_ <= '9'); | 557 } while (c0_ >= '0' && c0_ <= '9'); |
545 } | 558 } |
546 literal.Complete(); | 559 literal.Complete(); |
| 560 ASSERT_NOT_NULL(next_.literal_chars); |
| 561 number_ = StringToDouble(next_.literal_chars->ascii_literal(), |
| 562 NO_FLAGS, // Hex, octal or trailing junk. |
| 563 OS::nan_value()); |
547 return Token::NUMBER; | 564 return Token::NUMBER; |
548 } | 565 } |
549 | 566 |
550 | 567 |
551 Token::Value JsonScanner::ScanJsonIdentifier(const char* text, | 568 Token::Value JsonScanner::ScanJsonIdentifier(const char* text, |
552 Token::Value token) { | 569 Token::Value token) { |
553 LiteralScope literal(this); | 570 LiteralScope literal(this); |
554 while (*text != '\0') { | 571 while (*text != '\0') { |
555 if (c0_ != *text) return Token::ILLEGAL; | 572 if (c0_ != *text) return Token::ILLEGAL; |
556 Advance(); | 573 Advance(); |
557 text++; | 574 text++; |
558 } | 575 } |
559 if (ScannerConstants::kIsIdentifierPart.get(c0_)) return Token::ILLEGAL; | 576 if (ScannerConstants::kIsIdentifierPart.get(c0_)) return Token::ILLEGAL; |
560 literal.Complete(); | 577 literal.Complete(); |
561 return token; | 578 return token; |
562 } | 579 } |
563 | 580 |
564 | 581 |
565 | 582 |
566 } } // namespace v8::internal | 583 } } // namespace v8::internal |
OLD | NEW |