MCPcopy
hub / github.com/expr-lang/expr / Lex

Function Lex

parser/lexer/lexer.go:16–31  ·  view source on GitHub ↗

Lex will buffer and return the tokens of a disposable *[Lexer].

(source file.Source)

Source from the content-addressed store, hash-verified

14
15// Lex will buffer and return the tokens of a disposable *[Lexer].
16func Lex(source file.Source) ([]Token, error) {
17 tokens := make([]Token, 0, ringChunkSize)
18 l := New()
19 l.Reset(source)
20 for {
21 t, err := l.Next()
22 switch err {
23 case nil:
24 tokens = append(tokens, t)
25 case io.EOF:
26 return tokens, nil
27 default:
28 return nil, err
29 }
30 }
31}
32
33// New returns a reusable lexer.
34func New() *Lexer {

Callers 3

TestLexFunction · 0.85
TestLex_locationFunction · 0.85
TestLex_errorFunction · 0.85

Calls 3

NextMethod · 0.80
NewFunction · 0.70
ResetMethod · 0.45

Tested by 3

TestLexFunction · 0.68
TestLex_locationFunction · 0.68
TestLex_errorFunction · 0.68