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