(meh ExprHelper, target ast.Expr, args []ast.Expr)
| 3860 | var optMapMacro = NewReceiverMacro("optMap", 2, optMapExpander) |
| 3861 | |
| 3862 | func optMapExpander(meh ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *common.Error) { |
| 3863 | varIdent := args[0] |
| 3864 | varName := "" |
| 3865 | switch varIdent.Kind() { |
| 3866 | case ast.IdentKind: |
| 3867 | varName = varIdent.AsIdent() |
| 3868 | default: |
| 3869 | return nil, meh.NewError(varIdent.ID(), "optMap() variable name must be a simple identifier") |
| 3870 | } |
| 3871 | mapExpr := args[1] |
| 3872 | return meh.NewCall( |
| 3873 | operators.Conditional, |
| 3874 | meh.NewMemberCall("hasValue", target), |
| 3875 | meh.NewCall("optional.of", |
| 3876 | meh.NewComprehension( |
| 3877 | meh.NewList(), |
| 3878 | "#unused", |
| 3879 | varName, |
| 3880 | meh.NewMemberCall("value", meh.Copy(target)), |
| 3881 | meh.NewLiteral(types.False), |
| 3882 | meh.NewIdent(varName), |
| 3883 | mapExpr, |
| 3884 | ), |
| 3885 | ), |
| 3886 | meh.NewCall("optional.none"), |
| 3887 | ), nil |
| 3888 | } |
| 3889 | |
| 3890 | func newBenchmarkCategoryParser(tb testing.TB, options ...Option) *Parser { |
| 3891 | tb.Helper() |
nothing calls this directly
no test coverage detected