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

Method VisitIFieldInitializerList

parser/parser.go:639–673  ·  view source on GitHub ↗

Visit a parse tree of field initializers.

(ctx gen.IFieldInitializerListContext)

Source from the content-addressed store, hash-verified

637
638// Visit a parse tree of field initializers.
639func (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.
676func (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