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

Method parse

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

Source from the content-addressed store, hash-verified

247}
248
249func (p *antlrVisitor) parse(expr runes.Buffer, desc string) ast.Expr {
250 lexer := gen.NewCELLexer(newCharStream(expr, desc))
251 lexer.RemoveErrorListeners()
252 lexer.AddErrorListener(p)
253
254 prsr := gen.NewCELParser(antlr.NewCommonTokenStream(lexer, 0))
255 prsr.RemoveErrorListeners()
256
257 prsrListener := &recursionListener{
258 maxDepth: p.maxRecursionDepth,
259 ruleTypeDepth: map[int]*int{},
260 }
261
262 prsr.AddErrorListener(p)
263 prsr.AddParseListener(prsrListener)
264
265 prsr.SetErrorHandler(&recoveryLimitErrorStrategy{
266 DefaultErrorStrategy: antlr.NewDefaultErrorStrategy(),
267 errorRecoveryLimit: p.errorRecoveryLimit,
268 errorRecoveryTokenLookaheadLimit: p.errorRecoveryLookaheadTokenLimit,
269 })
270
271 defer func() {
272 if val := recover(); val != nil {
273 switch err := val.(type) {
274 case *lookaheadLimitError:
275 p.errors.internalError(err.Error())
276 case *recursionError:
277 p.errors.internalError(err.Error())
278 case *tooManyErrors:
279 // do nothing
280 case *recoveryLimitError:
281 // do nothing, listeners already notified and error reported.
282 default:
283 panic(val)
284 }
285 }
286 }()
287
288 return p.Visit(prsr.Start_()).(ast.Expr)
289}
290
291// Visitor implementations.
292func (p *antlrVisitor) 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