-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
42 lines (39 loc) · 718 Bytes
/
Copy pathdebug.go
File metadata and controls
42 lines (39 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package fig
import (
"fmt"
"io"
"strings"
)
func Debug(r io.Reader, w io.Writer) error {
n, err := Parse(r)
if err != nil {
return err
}
debugNode(w, n, 0)
return nil
}
func debugNode(w io.Writer, n Node, level int) {
prefix := strings.Repeat(" ", level)
switch n := n.(type) {
case *object:
fmt.Fprint(w, prefix)
fmt.Fprint(w, n)
fmt.Fprintln(w, "[")
for _, n := range n.Nodes {
debugNode(w, n, level+2)
}
fmt.Fprint(w, prefix)
fmt.Fprintln(w, "]")
case *array:
fmt.Fprint(w, prefix)
fmt.Fprintln(w, "array[")
for _, n := range n.Nodes {
debugNode(w, n, level+2)
}
fmt.Fprint(w, prefix)
fmt.Fprintln(w, "]")
default:
fmt.Fprint(w, prefix)
fmt.Fprintln(w, n)
}
}