Skip to content

Commit 89370fb

Browse files
committed
fix: change Macro.Expand() signature
1 parent c1c612f commit 89370fb

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

dsl/op/array.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ func (*arrayOp) String() string {
2121
}
2222

2323
// Execute executes "$array" operation
24-
func (*arrayOp) Expand(args []types.Value) (types.Value, error) {
25-
return types.NewArray(args, types.AnyValue), nil
24+
func (*arrayOp) Expand(args []types.Value) (types.Value, func(), error) {
25+
return types.NewArray(args, types.AnyValue), noRollback, nil
2626
}

dsl/op/invert.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ func (*invertOp) String() string {
2121
}
2222

2323
// Execute executes "$invert" operation
24-
func (*invertOp) Expand(args []types.Value) (types.Value, error) {
24+
func (*invertOp) Expand(args []types.Value) (types.Value, func(), error) {
2525
if err := signature(types.AnyValue).check(args); err != nil {
26-
return nil, err
26+
return nil, noRollback, err
2727
}
28-
return args[0].Invert()
28+
val, err := args[0].Invert()
29+
return val, noRollback, err
2930
}

dsl/op/rollback.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package op
2+
3+
var noRollback = func() {}

dsl/parse.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ func parseArray(array []interface{}) (types.Value, error) {
5252
args = append(args, v)
5353
}
5454
if macro, exists := op.LookupMacro(opName); exists {
55-
return macro.Expand(args)
55+
val, _, err := macro.Expand(args)
56+
return val, err
5657
}
5758
if fn, exists := op.LookupFunc(opName); exists {
5859
return fn.Bind(args...)

dsl/types/op.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ type Macro interface {
2424

2525
// Expand expands this expression (operator + args).
2626
// If argument type or arity is different, this returns non-nil error.
27-
Expand(args []Value) (Value, error)
27+
Expand(args []Value) (val Value, rollback func(), err error)
2828
}

0 commit comments

Comments
 (0)