MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Lex

Method Lex

parser/lexer.go:545–664  ·  view source on GitHub ↗

Lex scans and returns the next token from the source.

()

Source from the content-addressed store, hash-verified

543
544// Lex scans and returns the next token from the source.
545func (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)

Callers 7

TestLexerFunction · 0.80
TestLexerErrorsFunction · 0.80
TestLexerErrorRecoveryFunction · 0.80
BenchmarkLexerFunction · 0.80
nextSignificantTokenMethod · 0.80

Calls 14

makeTokenMethod · 0.95
consumeWhitespaceMethod · 0.95
consumeNumericLiteralMethod · 0.95
advanceMethod · 0.95
consumeMethod · 0.95
consumeLineMethod · 0.95
setErrorMethod · 0.95
consumeIdentMethod · 0.95
consumeQuotedIdentMethod · 0.95
consumeStringLiteralMethod · 0.95
isDigitFunction · 0.70

Tested by 5

TestLexerFunction · 0.64
TestLexerErrorsFunction · 0.64
TestLexerErrorRecoveryFunction · 0.64
BenchmarkLexerFunction · 0.64