From 61ee63d842350fdb876683cb21c1fd92d9ad8444 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 14 Jan 2015 21:49:39 -0800 Subject: [PATCH] config/lang/ast: remove unused Eval --- config/lang/ast/ast.go | 12 ------------ config/lang/ast/call.go | 19 ------------------- config/lang/ast/call_test.go | 21 --------------------- config/lang/ast/concat.go | 14 -------------- config/lang/ast/concat_test.go | 18 ------------------ config/lang/ast/literal.go | 4 ---- config/lang/ast/literal_test.go | 13 ------------- config/lang/ast/variable_access.go | 9 --------- config/lang/ast/variable_access_test.go | 17 ----------------- 9 files changed, 127 deletions(-) diff --git a/config/lang/ast/ast.go b/config/lang/ast/ast.go index 7f88beaa3..fc6c966b0 100644 --- a/config/lang/ast/ast.go +++ b/config/lang/ast/ast.go @@ -15,10 +15,6 @@ type Node interface { // Type returns the type of this node for the given context. Type(Scope) (Type, error) - - // Eval evaluates this node, returning its final value. The type - // of the final value will match the result of Type with the same scope. - Eval(*EvalContext) (interface{}, error) } // Pos is the starting position of an AST node @@ -30,14 +26,6 @@ func (p Pos) String() string { return fmt.Sprintf("%d:%d", p.Line, p.Column) } -// EvalContext is the context given for evaluation. -// -// It is simple for now with just a Scope but we use a struct in case we -// plan on adding fields in the future. -type EvalContext struct { - Scope Scope -} - // Visitors are just implementations of this function. // // The function must return the Node to replace this node with. "nil" is diff --git a/config/lang/ast/call.go b/config/lang/ast/call.go index fda7d3e62..ace1147a6 100644 --- a/config/lang/ast/call.go +++ b/config/lang/ast/call.go @@ -41,22 +41,3 @@ func (n *Call) Type(s Scope) (Type, error) { return f.ReturnType, nil } - -func (n *Call) Eval(ctx *EvalContext) (interface{}, error) { - f, ok := ctx.Scope.LookupFunc(n.Func) - if !ok { - return TypeInvalid, fmt.Errorf("unknown function: %s", n.Func) - } - - args := make([]interface{}, len(n.Args)) - for i, arg := range n.Args { - result, err := arg.Eval(ctx) - if err != nil { - return nil, err - } - - args[i] = result - } - - return f.Callback(args) -} diff --git a/config/lang/ast/call_test.go b/config/lang/ast/call_test.go index b08a67d4b..ef63888d2 100644 --- a/config/lang/ast/call_test.go +++ b/config/lang/ast/call_test.go @@ -34,24 +34,3 @@ func TestCallType_invalid(t *testing.T) { t.Fatal("should error") } } - -func TestCallEval(t *testing.T) { - c := &Call{Func: "foo"} - scope := &BasicScope{ - FuncMap: map[string]Function{ - "foo": Function{ - Callback: func([]interface{}) (interface{}, error) { - return "42", nil - }, - }, - }, - } - - actual, err := c.Eval(&EvalContext{Scope: scope}) - if err != nil { - t.Fatalf("err: %s", err) - } - if actual != "42" { - t.Fatalf("bad: %s", actual) - } -} diff --git a/config/lang/ast/concat.go b/config/lang/ast/concat.go index 03d406d6b..0246a3bc1 100644 --- a/config/lang/ast/concat.go +++ b/config/lang/ast/concat.go @@ -40,17 +40,3 @@ func (n *Concat) String() string { func (n *Concat) Type(Scope) (Type, error) { return TypeString, nil } - -func (n *Concat) Eval(ctx *EvalContext) (interface{}, error) { - var b bytes.Buffer - for _, expr := range n.Exprs { - result, err := expr.Eval(ctx) - if err != nil { - return nil, err - } - - b.WriteString(result.(string)) - } - - return b.String(), nil -} diff --git a/config/lang/ast/concat_test.go b/config/lang/ast/concat_test.go index 111092270..65fa67601 100644 --- a/config/lang/ast/concat_test.go +++ b/config/lang/ast/concat_test.go @@ -14,21 +14,3 @@ func TestConcatType(t *testing.T) { t.Fatalf("bad: %s", actual) } } - -func TestConcatEval(t *testing.T) { - c := &Concat{ - Exprs: []Node{ - &LiteralNode{Value: "foo"}, - &LiteralNode{Value: "bar"}, - }, - } - scope := &BasicScope{} - - actual, err := c.Eval(&EvalContext{Scope: scope}) - if err != nil { - t.Fatalf("err: %s", err) - } - if actual != "foobar" { - t.Fatalf("bad: %s", actual) - } -} diff --git a/config/lang/ast/literal.go b/config/lang/ast/literal.go index da1985023..9da3ff3a3 100644 --- a/config/lang/ast/literal.go +++ b/config/lang/ast/literal.go @@ -31,7 +31,3 @@ func (n *LiteralNode) String() string { func (n *LiteralNode) Type(Scope) (Type, error) { return n.Typex, nil } - -func (n *LiteralNode) Eval(*EvalContext) (interface{}, error) { - return n.Value, nil -} diff --git a/config/lang/ast/literal_test.go b/config/lang/ast/literal_test.go index 51eedaf94..2759d7722 100644 --- a/config/lang/ast/literal_test.go +++ b/config/lang/ast/literal_test.go @@ -14,16 +14,3 @@ func TestLiteralNodeType(t *testing.T) { t.Fatalf("bad: %s", actual) } } - -func TestLiteralNodeEval(t *testing.T) { - c := &LiteralNode{Value: "42", Typex: TypeString} - scope := &BasicScope{} - - actual, err := c.Eval(&EvalContext{Scope: scope}) - if err != nil { - t.Fatalf("err: %s", err) - } - if actual != "42" { - t.Fatalf("bad: %s", actual) - } -} diff --git a/config/lang/ast/variable_access.go b/config/lang/ast/variable_access.go index 8ed150d87..4c1362d75 100644 --- a/config/lang/ast/variable_access.go +++ b/config/lang/ast/variable_access.go @@ -34,12 +34,3 @@ func (n *VariableAccess) Type(s Scope) (Type, error) { return v.Type, nil } - -func (n *VariableAccess) Eval(ctx *EvalContext) (interface{}, error) { - v, ok := ctx.Scope.LookupVar(n.Name) - if !ok { - return TypeInvalid, fmt.Errorf("unknown variable: %s", n.Name) - } - - return v.Value, nil -} diff --git a/config/lang/ast/variable_access_test.go b/config/lang/ast/variable_access_test.go index 4dde6da39..1880bc514 100644 --- a/config/lang/ast/variable_access_test.go +++ b/config/lang/ast/variable_access_test.go @@ -34,20 +34,3 @@ func TestVariableAccessType_invalid(t *testing.T) { t.Fatal("should error") } } - -func TestVariableAccessEval(t *testing.T) { - c := &VariableAccess{Name: "foo"} - scope := &BasicScope{ - VarMap: map[string]Variable{ - "foo": Variable{Value: "42", Type: TypeString}, - }, - } - - actual, err := c.Eval(&EvalContext{Scope: scope}) - if err != nil { - t.Fatalf("err: %s", err) - } - if actual != "42" { - t.Fatalf("bad: %s", actual) - } -}