Visit a parse tree of field initializers.
(ctx gen.IFieldInitializerListContext)
| 637 | |
| 638 | // Visit a parse tree of field initializers. |
| 639 | func (p *parser) VisitIFieldInitializerList(ctx gen.IFieldInitializerListContext) any { |
| 640 | if ctx == nil || ctx.GetFields() == nil { |
| 641 | // This is the result of a syntax error handled elswhere, return empty. |
| 642 | return []ast.EntryExpr{} |
| 643 | } |
| 644 | |
| 645 | result := make([]ast.EntryExpr, len(ctx.GetFields())) |
| 646 | cols := ctx.GetCols() |
| 647 | vals := ctx.GetValues() |
| 648 | for i, f := range ctx.GetFields() { |
| 649 | if i >= len(cols) || i >= len(vals) { |
| 650 | // This is the result of a syntax error detected elsewhere. |
| 651 | return []ast.EntryExpr{} |
| 652 | } |
| 653 | initID := p.helper.id(cols[i]) |
| 654 | optField := f.(*gen.OptFieldContext) |
| 655 | optional := optField.GetOpt() != nil |
| 656 | if !p.enableOptionalSyntax && optional { |
| 657 | p.reportError(optField, "unsupported syntax '?'") |
| 658 | continue |
| 659 | } |
| 660 | |
| 661 | // The field may be empty due to a prior error. |
| 662 | fieldName, err := p.normalizeIdent(optField.EscapeIdent()) |
| 663 | if err != nil { |
| 664 | p.reportError(ctx, "%v", err) |
| 665 | continue |
| 666 | } |
| 667 | |
| 668 | value := p.Visit(vals[i]).(ast.Expr) |
| 669 | field := p.helper.newObjectField(initID, fieldName, value, optional) |
| 670 | result[i] = field |
| 671 | } |
| 672 | return result |
| 673 | } |
| 674 | |
| 675 | // Visit a parse tree produced by CELParser#Ident. |
| 676 | func (p *parser) VisitIdent(ctx *gen.IdentContext) any { |
no test coverage detected