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