(expr runes.Buffer, desc string)
| 331 | var _ gen.CELVisitor = (*parser)(nil) |
| 332 | |
| 333 | func (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. |
| 376 | func (p *parser) Visit(tree antlr.ParseTree) any { |
no test coverage detected