/
walker.go
69 lines (51 loc) · 1.29 KB
/
walker.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
package symbolic
import (
pprint "github.com/inoxlang/inox/internal/prettyprint"
)
var (
ANY_WALKABLE = &AnyWalkable{}
ANY_WALKER = &Walker{}
_ = []Walkable{(*Path)(nil), (*Treedata)(nil)}
)
// An Walkable represents a symbolic Walkable.
type Walkable interface {
Value
WalkerElement() Value
WalkerNodeMeta() Value
}
// An AnyWalkable represents a symbolic Walkable we do not know the concrete type.
type AnyWalkable struct {
_ int
}
func (r *AnyWalkable) Test(v Value, state RecTestCallState) bool {
state.StartCall()
defer state.FinishCall()
_, ok := v.(*AnyWalkable)
return ok
}
func (r *AnyWalkable) PrettyPrint(w pprint.PrettyPrintWriter, config *pprint.PrettyPrintConfig) {
w.WriteName("walkable")
}
func (r *AnyWalkable) WidestOfType() Value {
return ANY_WALKABLE
}
func (r *AnyWalkable) WalkerElement() Value {
return ANY
}
// A Walker represents a symbolic Walker.
type Walker struct {
//after any update make sure ANY_WALKER is still valid
_ int
}
func (r *Walker) Test(v Value, state RecTestCallState) bool {
state.StartCall()
defer state.FinishCall()
_, ok := v.(*Walker)
return ok
}
func (r *Walker) PrettyPrint(w pprint.PrettyPrintWriter, config *pprint.PrettyPrintConfig) {
w.WriteName("walker")
}
func (r *Walker) WidestOfType() Value {
return ANY_WALKER
}