From 6462211d14333b7c8bd0c701f3899c07018e1f44 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 3 Aug 2014 13:19:20 -0700 Subject: [PATCH] DecodeAST can take any ast Node --- decoder.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/decoder.go b/decoder.go index 61d3ade..ebde944 100644 --- a/decoder.go +++ b/decoder.go @@ -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)