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

Method parse

parser/parser.go:341–381  ·  view source on GitHub ↗
(expr runes.Buffer, desc string)

Source from the content-addressed store, hash-verified

339var _ gen.CELVisitor = (*parser)(nil)
340
341func (p *parser) parse(expr runes.Buffer, desc string) ast.Expr {
342 lexer := gen.NewCELLexer(newCharStream(expr, desc))
343 lexer.RemoveErrorListeners()
344 lexer.AddErrorListener(p)
345
346 prsr := gen.NewCELParser(antlr.NewCommonTokenStream(lexer, 0))
347 prsr.RemoveErrorListeners()
348
349 prsrListener := &recursionListener{
350 maxDepth: p.maxRecursionDepth,
351 ruleTypeDepth: map[int]*int{},
352 }
353
354 prsr.AddErrorListener(p)
355 prsr.AddParseListener(prsrListener)
356
357 prsr.SetErrorHandler(&recoveryLimitErrorStrategy{
358 DefaultErrorStrategy: antlr.NewDefaultErrorStrategy(),
359 errorRecoveryLimit: p.errorRecoveryLimit,
360 errorRecoveryTokenLookaheadLimit: p.errorRecoveryLookaheadTokenLimit,
361 })
362
363 defer func() {
364 if val := recover(); val != nil {
365 switch err := val.(type) {
366 case *lookaheadLimitError:
367 p.errors.internalError(err.Error())
368 case *recursionError:
369 p.errors.internalError(err.Error())
370 case *tooManyErrors:
371 // do nothing
372 case *recoveryLimitError:
373 // do nothing, listeners already notified and error reported.
374 default:
375 panic(val)
376 }
377 }
378 }()
379
380 return p.Visit(prsr.Start_()).(ast.Expr)
381}
382
383// Visitor implementations.
384func (p *parser) Visit(tree antlr.ParseTree) any {

Callers 1

ParseMethod · 0.95

Calls 7

VisitMethod · 0.95
Start_Method · 0.95
NewCELLexerFunction · 0.92
NewCELParserFunction · 0.92
newCharStreamFunction · 0.85
internalErrorMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected