Lex scans and returns the next token from the source.
()
| 543 | |
| 544 | // Lex scans and returns the next token from the source. |
| 545 | func (l *lexer) Lex() token { |
| 546 | start := l.pos |
| 547 | if l.pos >= l.length { |
| 548 | return l.makeToken(tokEnd, start, start) |
| 549 | } |
| 550 | c := l.content.Get(int(l.pos)) |
| 551 | switch c { |
| 552 | case '\f', '\t', '\r', '\n', ' ': |
| 553 | l.consumeWhitespace() |
| 554 | return l.makeToken(tokWhitespace, start, l.pos) |
| 555 | case '.': |
| 556 | if l.pos+1 < l.length && isDigit(l.content.Get(int(l.pos+1))) { |
| 557 | return l.consumeNumericLiteral() |
| 558 | } |
| 559 | l.advance(1) |
| 560 | return l.makeToken(tokDot, start, l.pos) |
| 561 | case ',': |
| 562 | l.advance(1) |
| 563 | return l.makeToken(tokComma, start, l.pos) |
| 564 | case '!': |
| 565 | l.advance(1) |
| 566 | if l.consume('=') { |
| 567 | return l.makeToken(tokExclamationEqual, start, l.pos) |
| 568 | } |
| 569 | return l.makeToken(tokExclamation, start, l.pos) |
| 570 | case '?': |
| 571 | l.advance(1) |
| 572 | return l.makeToken(tokQuestion, start, l.pos) |
| 573 | case '(': |
| 574 | l.advance(1) |
| 575 | return l.makeToken(tokLeftParen, start, l.pos) |
| 576 | case ')': |
| 577 | l.advance(1) |
| 578 | return l.makeToken(tokRightParen, start, l.pos) |
| 579 | case '{': |
| 580 | l.advance(1) |
| 581 | return l.makeToken(tokLeftBrace, start, l.pos) |
| 582 | case '}': |
| 583 | l.advance(1) |
| 584 | return l.makeToken(tokRightBrace, start, l.pos) |
| 585 | case '[': |
| 586 | l.advance(1) |
| 587 | return l.makeToken(tokLeftBracket, start, l.pos) |
| 588 | case ']': |
| 589 | l.advance(1) |
| 590 | return l.makeToken(tokRightBracket, start, l.pos) |
| 591 | case '=': |
| 592 | l.advance(1) |
| 593 | if l.consume('=') { |
| 594 | return l.makeToken(tokEqualEqual, start, l.pos) |
| 595 | } |
| 596 | return l.makeToken(tokEqual, start, l.pos) |
| 597 | case '<': |
| 598 | l.advance(1) |
| 599 | if l.consume('=') { |
| 600 | return l.makeToken(tokLessEqual, start, l.pos) |
| 601 | } |
| 602 | return l.makeToken(tokLess, start, l.pos) |