| 482 | } |
| 483 | |
| 484 | private tryReadDigits(hasLeftSpacing: boolean): Token | undefined { |
| 485 | let wholeNumber = ''; |
| 486 | let fractional = ''; |
| 487 | |
| 488 | const pos = this.stream.getPos(); |
| 489 | |
| 490 | while (!this.stream.eof && digit.test(this.stream.char)) { |
| 491 | wholeNumber += this.stream.char; |
| 492 | this.stream.next(); |
| 493 | } |
| 494 | if (wholeNumber.length === 0) { |
| 495 | return; |
| 496 | } |
| 497 | if (!this.stream.eof && this.stream.char === '.') { |
| 498 | this.stream.next(); |
| 499 | while (!this.stream.eof as boolean && digit.test(this.stream.char as string)) { |
| 500 | fractional += this.stream.char; |
| 501 | this.stream.next(); |
| 502 | } |
| 503 | if (fractional.length === 0) { |
| 504 | throw new AiScriptSyntaxError('digit expected', pos); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | // 指数表記仕様が必要になった段階で有効化する |
| 509 | //let exponentIndicator = ''; |
| 510 | //let exponentSign = ''; |
| 511 | //let exponentAbsolute = ''; |
| 512 | //if (!this.stream.eof && exponentIndicatorPattern.test(this.stream.char as string)) { |
| 513 | // exponentIndicator = this.stream.char as string; |
| 514 | // this.stream.next(); |
| 515 | // if (!this.stream.eof && (this.stream.char as string) === '-') { |
| 516 | // exponentSign = '-'; |
| 517 | // this.stream.next(); |
| 518 | // } else if (!this.stream.eof && (this.stream.char as string) === '+') { |
| 519 | // exponentSign = '+'; |
| 520 | // this.stream.next(); |
| 521 | // } |
| 522 | // while (!this.stream.eof && digit.test(this.stream.char)) { |
| 523 | // exponentAbsolute += this.stream.char; |
| 524 | // this.stream.next(); |
| 525 | // } |
| 526 | // if (exponentAbsolute.length === 0) { |
| 527 | // throw new AiScriptSyntaxError('exponent expected', pos); |
| 528 | // } |
| 529 | //} |
| 530 | |
| 531 | let value: string; |
| 532 | if (fractional.length > 0) { |
| 533 | value = wholeNumber + '.' + fractional; |
| 534 | } else { |
| 535 | value = wholeNumber; |
| 536 | } |
| 537 | //if (exponentIndicator.length > 0) { |
| 538 | // value += exponentIndicator + exponentSign + exponentAbsolute; |
| 539 | //} |
| 540 | return TOKEN(TokenKind.NumberLiteral, pos, { hasLeftSpacing, value }); |
| 541 | } |