DecodeAST can take any ast Node
This commit is contained in:
parent
96e92c5213
commit
6462211d14
10
decoder.go
10
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)
|
||||
|
Loading…
Reference in New Issue
Block a user