-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: unify Func,Macro interfaces to Op interface
- Loading branch information
Showing
10 changed files
with
106 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
package op | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/vim-volt/volt/dsl/types" | ||
) | ||
|
||
func init() { | ||
s := arrayOp("$array") | ||
ArrayOp = &s | ||
macroMap[string(*ArrayOp)] = ArrayOp | ||
opsMap[ArrayOp.String()] = ArrayOp | ||
} | ||
|
||
type arrayOp struct { | ||
macroBase | ||
} | ||
|
||
type arrayOp string | ||
// ArrayOp is "$array" operator | ||
var ArrayOp = &arrayOp{macroBase("$array")} | ||
|
||
// ArrayOp is "$array" operation | ||
var ArrayOp *arrayOp | ||
func (op *arrayOp) InvertExpr(args []types.Value) (types.Value, error) { | ||
return op.macroInvertExpr(op.Execute(context.Background(), args)) | ||
} | ||
|
||
// String returns "$array" | ||
func (*arrayOp) String() string { | ||
return string(*ArrayOp) | ||
func (*arrayOp) Bind(args ...types.Value) (*types.Expr, error) { | ||
expr := types.NewExpr(ArrayOp, args, types.NewArrayType(types.AnyValue)) | ||
return expr, nil | ||
} | ||
|
||
// Execute executes "$array" operation | ||
func (*arrayOp) Expand(args []types.Value) (types.Value, func(), error) { | ||
func (*arrayOp) Execute(ctx context.Context, args []types.Value) (types.Value, func(), error) { | ||
return types.NewArray(args, types.AnyValue), NoRollback, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package op | ||
|
||
import ( | ||
"github.com/vim-volt/volt/dsl/types" | ||
) | ||
|
||
type macroBase string | ||
|
||
// String returns "$array" | ||
func (m *macroBase) String() string { | ||
return string(*m) | ||
} | ||
|
||
func (*macroBase) IsMacro() bool { | ||
return true | ||
} | ||
|
||
// Invert the result of op.Execute() which expands an expression | ||
func (*macroBase) macroInvertExpr(val types.Value, _ func(), err error) (types.Value, error) { | ||
if err != nil { | ||
return nil, err | ||
} | ||
return val.Invert() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters