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

Function optMapExpander

parser/parser_test.go:2597–2623  ·  view source on GitHub ↗
(meh ExprHelper, target ast.Expr, args []ast.Expr)

Source from the content-addressed store, hash-verified

2595var optMapMacro = NewReceiverMacro("optMap", 2, optMapExpander)
2596
2597func optMapExpander(meh ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *common.Error) {
2598 varIdent := args[0]
2599 varName := ""
2600 switch varIdent.Kind() {
2601 case ast.IdentKind:
2602 varName = varIdent.AsIdent()
2603 default:
2604 return nil, meh.NewError(varIdent.ID(), "optMap() variable name must be a simple identifier")
2605 }
2606 mapExpr := args[1]
2607 return meh.NewCall(
2608 operators.Conditional,
2609 meh.NewMemberCall("hasValue", target),
2610 meh.NewCall("optional.of",
2611 meh.NewComprehension(
2612 meh.NewList(),
2613 "#unused",
2614 varName,
2615 meh.NewMemberCall("value", meh.Copy(target)),
2616 meh.NewLiteral(types.False),
2617 meh.NewIdent(varName),
2618 mapExpr,
2619 ),
2620 ),
2621 meh.NewCall("optional.none"),
2622 ), nil
2623}
2624
2625func newBenchmarkCategoryParser(tb testing.TB) *Parser {
2626 tb.Helper()

Callers

nothing calls this directly

Calls 11

KindMethod · 0.65
AsIdentMethod · 0.65
NewErrorMethod · 0.65
IDMethod · 0.65
NewCallMethod · 0.65
NewMemberCallMethod · 0.65
NewComprehensionMethod · 0.65
NewListMethod · 0.65
CopyMethod · 0.65
NewLiteralMethod · 0.65
NewIdentMethod · 0.65

Tested by

no test coverage detected