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

Method Parse

parser/parser.go:60–98  ·  view source on GitHub ↗
(input string, config *conf.Config)

Source from the content-addressed store, hash-verified

58}
59
60func (p *Parser) Parse(input string, config *conf.Config) (*Tree, error) {
61 if p.lexer == nil {
62 p.lexer = New()
63 }
64 p.config = config
65 // propagate config flags to lexer
66 if p.lexer != nil {
67 if config != nil {
68 p.lexer.DisableIfOperator = config.DisableIfOperator
69 } else {
70 p.lexer.DisableIfOperator = false
71 }
72 }
73 source := file.NewSource(input)
74 p.lexer.Reset(source)
75 p.next()
76 node := p.parseSequenceExpression()
77
78 if !p.current.Is(EOF) {
79 p.error("unexpected token %v", p.current)
80 }
81
82 tree := &Tree{
83 Node: node,
84 Source: source,
85 }
86 err := p.err
87
88 // cleanup non-reusable pointer values and reset state
89 p.err = nil
90 p.config = nil
91 p.lexer.Reset(file.Source{})
92
93 if err != nil {
94 return tree, err.Bind(source)
95 }
96
97 return tree, nil
98}
99
100func (p *Parser) checkNodeLimit() error {
101 p.nodeCount++

Callers 7

ParseWithConfigFunction · 0.80
BenchmarkParserFunction · 0.80
TestGeneratedFunction · 0.80
builtin.goFile · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 8

nextMethod · 0.95
errorMethod · 0.95
NewSourceFunction · 0.92
IsMethod · 0.80
BindMethod · 0.80
NewFunction · 0.50
ResetMethod · 0.45

Tested by 3

BenchmarkParserFunction · 0.64
TestGeneratedFunction · 0.64