lang: Move interpret function to a separate package
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user