lang: Add logging and debug info via a new Init method

This expands the Stmt and Expr interfaces to add an Init method. This
is used to pass in Debug and Logf values, but is also used to validate
the AST. This gets rid of standalone use of the "log" package.
This commit is contained in:
James Shubin
2018-06-19 16:49:02 -04:00
parent 75633817a7
commit 3f42e5f702
6 changed files with 417 additions and 65 deletions

View File

@@ -387,6 +387,19 @@ func TestAstFunc0(t *testing.T) {
}
t.Logf("test #%d: AST: %+v", index, ast)
data := &interfaces.Data{
Debug: true,
Logf: func(format string, v ...interface{}) {
t.Logf("ast: "+format, v...)
},
}
// some of this might happen *after* interpolate in SetScope or Unify...
if err := ast.Init(data); err != nil {
t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not init and validate AST: %+v", index, err)
return
}
iast, err := ast.Interpolate()
if err != nil {
t.Errorf("test #%d: FAIL", index)
@@ -600,6 +613,19 @@ func TestAstInterpret0(t *testing.T) {
}
t.Logf("test #%d: AST: %+v", index, ast)
data := &interfaces.Data{
Debug: true,
Logf: func(format string, v ...interface{}) {
t.Logf("ast: "+format, v...)
},
}
// some of this might happen *after* interpolate in SetScope or Unify...
if err := ast.Init(data); err != nil {
t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not init and validate AST: %+v", index, err)
return
}
// these tests only work in certain cases, since this does not
// perform type unification, run the function graph engine, and
// only gives you limited results... don't expect normal code to