/////////////////////////////////////////////////////////////////////////// Lexer::Type::number 0 [1-9]\d [ . \d+ ] [ e|E [ +|- ] \d+ [ . \d+ ] ] not followed by non-operator.
| 506 | // [ e|E [ +|- ] \d+ [ . \d+ ] ] |
| 507 | // not followed by non-operator. |
| 508 | bool Lexer::isNumber(std::string& token, Lexer::Type& type) { |
| 509 | std::size_t marker = _cursor; |
| 510 | |
| 511 | bool leading_zero = (_text[marker] == '0'); |
| 512 | |
| 513 | if (unicodeLatinDigit(_text[marker])) { |
| 514 | ++marker; |
| 515 | |
| 516 | // Two (or more) digit number with a leading zero are not allowed |
| 517 | if (leading_zero && unicodeLatinDigit(_text[marker])) return false; |
| 518 | |
| 519 | while (unicodeLatinDigit(_text[marker])) utf8_next_char(_text, marker); |
| 520 | |
| 521 | if (_text[marker] == '.') { |
| 522 | ++marker; |
| 523 | if (unicodeLatinDigit(_text[marker])) { |
| 524 | ++marker; |
| 525 | while (unicodeLatinDigit(_text[marker])) utf8_next_char(_text, marker); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | if (_text[marker] == 'e' || _text[marker] == 'E') { |
| 530 | ++marker; |
| 531 | |
| 532 | if (_text[marker] == '+' || _text[marker] == '-') ++marker; |
| 533 | |
| 534 | if (unicodeLatinDigit(_text[marker])) { |
| 535 | ++marker; |
| 536 | while (unicodeLatinDigit(_text[marker])) utf8_next_char(_text, marker); |
| 537 | |
| 538 | if (_text[marker] == '.') { |
| 539 | ++marker; |
| 540 | if (unicodeLatinDigit(_text[marker])) { |
| 541 | ++marker; |
| 542 | while (unicodeLatinDigit(_text[marker])) utf8_next_char(_text, marker); |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | // Lookahead: !<unicodeWhitespace> | !<isSingleCharOperator> |
| 549 | // If there is an immediately consecutive character, that is not an operator, fail. |
| 550 | if (_eos > marker && !unicodeWhitespace(_text[marker]) && !isSingleCharOperator(_text[marker])) |
| 551 | return false; |
| 552 | |
| 553 | token = _text.substr(_cursor, marker - _cursor); |
| 554 | type = Lexer::Type::number; |
| 555 | _cursor = marker; |
| 556 | return true; |
| 557 | } |
| 558 | |
| 559 | return false; |
| 560 | } |
| 561 | |
| 562 | //////////////////////////////////////////////////////////////////////////////// |
| 563 | // Lexer::Type::number |
nothing calls this directly
no outgoing calls
no test coverage detected