diff --git a/lang/interpret.go b/lang/interpret/interpret.go similarity index 97% rename from lang/interpret.go rename to lang/interpret/interpret.go index 3be3b74d..d436a195 100644 --- a/lang/interpret.go +++ b/lang/interpret/interpret.go @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -package lang // TODO: move this into a sub package of lang/$name? +package interpret import ( "fmt" @@ -27,11 +27,11 @@ import ( "github.com/purpleidea/mgmt/util/errwrap" ) -// interpret runs the program and causes a graph generation as a side effect. +// Interpret runs the program and causes a graph generation as a side effect. // You should not run this on the AST if you haven't previously run the function // graph engine so that output values have been produced! Type unification is // another important aspect which needs to have been completed. -func interpret(ast interfaces.Stmt) (*pgraph.Graph, error) { +func Interpret(ast interfaces.Stmt) (*pgraph.Graph, error) { output, err := ast.Output() // contains resList, edgeList, etc... if err != nil { return nil, err diff --git a/lang/interpret_test.go b/lang/interpret_test.go index e45eb0c4..c84b50df 100644 --- a/lang/interpret_test.go +++ b/lang/interpret_test.go @@ -36,6 +36,7 @@ import ( "github.com/purpleidea/mgmt/lang/funcs" "github.com/purpleidea/mgmt/lang/funcs/vars" "github.com/purpleidea/mgmt/lang/interfaces" + "github.com/purpleidea/mgmt/lang/interpret" "github.com/purpleidea/mgmt/lang/unification" "github.com/purpleidea/mgmt/pgraph" "github.com/purpleidea/mgmt/util" @@ -1534,7 +1535,7 @@ func TestAstFunc2(t *testing.T) { // run interpret! funcs.RLock() // in case something is actually changing - ograph, err := interpret(iast) + ograph, err := interpret.Interpret(iast) funcs.RUnlock() if (!fail || !failInterpret) && err != nil { @@ -1829,7 +1830,7 @@ func TestAstInterpret0(t *testing.T) { // perform type unification, run the function graph engine, and // only gives you limited results... don't expect normal code to // run and produce meaningful things in this test... - graph, err := interpret(ast) + graph, err := interpret.Interpret(ast) if !fail && err != nil { t.Errorf("test #%d: interpret failed with: %+v", index, err) diff --git a/lang/lang.go b/lang/lang.go index 6c0c5fc9..eef6a5cb 100644 --- a/lang/lang.go +++ b/lang/lang.go @@ -27,6 +27,7 @@ import ( _ "github.com/purpleidea/mgmt/lang/funcs/core" // import so the funcs register "github.com/purpleidea/mgmt/lang/funcs/vars" "github.com/purpleidea/mgmt/lang/interfaces" + "github.com/purpleidea/mgmt/lang/interpret" "github.com/purpleidea/mgmt/lang/unification" "github.com/purpleidea/mgmt/pgraph" "github.com/purpleidea/mgmt/util" @@ -331,7 +332,7 @@ func (obj *Lang) Interpret() (*pgraph.Graph, error) { obj.funcs.RLock() } // this call returns the graph - graph, err := interpret(obj.ast) + graph, err := interpret.Interpret(obj.ast) if obj.funcs != nil { obj.funcs.RUnlock() }