-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.go
94 lines (90 loc) · 1.86 KB
/
print.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package jsqr
import (
"fmt"
"io"
"os"
)
func print(a ast) {
writeast(os.Stdout, a)
}
func writeast(w io.Writer, a ast) {
write(w, a, 0)
}
func write(w io.Writer, a ast, depth int) {
for i := 0; i < depth; i++ {
fmt.Fprint(w, " ")
}
switch t := a.(type) {
case astOr:
fmt.Fprintln(w, "[Or]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astAnd:
fmt.Fprintln(w, "[And]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astEQ:
fmt.Fprintln(w, "[EQ]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astEQI:
fmt.Fprintln(w, "[EQI]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astNE:
fmt.Fprintln(w, "[NE]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astNEI:
fmt.Fprintln(w, "[NEI]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astGTE:
fmt.Fprintln(w, "[GTE]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astGT:
fmt.Fprintln(w, "[GT]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astLTE:
fmt.Fprintln(w, "[LTE]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astLT:
fmt.Fprintln(w, "[LT]")
write(w, t.A, depth+1)
write(w, t.B, depth+1)
case astPath:
fmt.Fprintln(w, "[Path]")
for _, v := range t.V {
write(w, v, depth+1)
}
case astNumFloat:
fmt.Fprintf(w, "[Num] %v\n", t.V)
case astKey:
fmt.Fprintf(w, "[Key]\n")
write(w, t.V, depth+1)
case astIdent:
fmt.Fprintf(w, "[Idn] %s\n", t.V)
case astStr:
fmt.Fprintf(w, "[Str] %s\n", t.V)
case astBool:
fmt.Fprintf(w, "[Bool] %t\n", t.V)
case astNil:
fmt.Fprintln(w, "[Null]")
case astThis:
fmt.Fprintln(w, "[This]")
case astArr:
fmt.Fprintln(w, "[Array]")
write(w, t.V, depth+1)
case astArrIdx:
fmt.Fprintf(w, "[Index] %v\n", t.V)
case astUpper:
fmt.Fprintln(w, "[Fun] upper")
case astLower:
fmt.Fprintln(w, "[Fun] lower")
case astExists:
fmt.Fprintln(w, "[Fun] exists")
}
}