DecodeAST can take any ast Node

This commit is contained in:
Mitchell Hashimoto 2014-08-03 13:19:20 -07:00
parent 96e92c5213
commit 6462211d14
1 changed files with 8 additions and 2 deletions

View File

@ -21,9 +21,9 @@ func Decode(out interface{}, in string) error {
// DecodeAST is a lower-level version of Decode. It decodes a
// raw AST into the given output.
func DecodeAST(out interface{}, obj *ast.ObjectNode) error {
func DecodeAST(out interface{}, n ast.Node) error {
var d decoder
return d.decode("root", *obj, reflect.ValueOf(out).Elem())
return d.decode("root", n, reflect.ValueOf(out).Elem())
}
type decoder struct{}
@ -40,6 +40,12 @@ func (d *decoder) decode(name string, n ast.Node, result reflect.Value) error {
}
}
// If we have a pointer, unpointer it
switch rn := n.(type) {
case *ast.ObjectNode:
n = *rn
}
switch k.Kind() {
case reflect.Int:
return d.decodeInt(name, n, result)