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

@@ -88,11 +88,19 @@ func (obj *Lang) Init() error {
obj.Logf("behold, the AST: %+v", ast)
}
// TODO: should we validate the structure of the AST?
// TODO: should we do this *after* interpolate, or trust it to behave?
//if err := ast.Validate(); err != nil {
// return errwrap.Wrapf(err, "could not validate AST")
//}
obj.Logf("init...")
// init and validate the structure of the AST
data := &interfaces.Data{
Debug: obj.Debug,
Logf: func(format string, v ...interface{}) {
// TODO: is this a sane prefix to use here?
obj.Logf("ast: "+format, v...)
},
}
// some of this might happen *after* interpolate in SetScope or Unify...
if err := ast.Init(data); err != nil {
return errwrap.Wrapf(err, "could not init and validate AST")
}
obj.Logf("interpolating...")
// interpolate strings and other expansionable nodes in AST