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

Method VisitIFieldInitializerList

parser/parser.go:647–681  ·  view source on GitHub ↗

Visit a parse tree of field initializers.

(ctx gen.IFieldInitializerListContext)

Source from the content-addressed store, hash-verified

645
646// Visit a parse tree of field initializers.
647func (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.
684func (p *parser) VisitIdent(ctx *gen.IdentContext) any {

Callers 1

VisitCreateMessageMethod · 0.95

Calls 10

reportErrorMethod · 0.95
normalizeIdentMethod · 0.95
VisitMethod · 0.95
idMethod · 0.80
newObjectFieldMethod · 0.80
GetFieldsMethod · 0.65
GetColsMethod · 0.65
GetValuesMethod · 0.65
GetOptMethod · 0.65
EscapeIdentMethod · 0.65

Tested by

no test coverage detected