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

Method parse

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

Source from the content-addressed store, hash-verified

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