-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpr_list.go
49 lines (42 loc) · 1.04 KB
/
expr_list.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
package lure
// ExprList manages a list of Expr for related operations
// - exprs is the overall expressions added
// - unresolved tracks the exprs that need context for resolution
// - resolved tracks all the nonresolvable nodes (like literals)
type ExprList struct {
exprs []Expr
unresolved []Expr
resolved map[string]IData
}
func newExprList() ExprList {
return ExprList{
exprs: nil,
unresolved: nil,
resolved: make(map[string]IData),
}
}
func (me *ExprList) get(i int) Expr {
if i < len(me.exprs) {
return me.exprs[i]
}
return nil
}
func (me *ExprList) getResolvedSet() map[string]IData {
return me.resolved
}
func (me *ExprList) getUnResolvedList() []Expr {
return me.unresolved
}
func (me *ExprList) add(xp Expr) {
me.exprs = append(me.exprs, xp)
if xp.isResolvable() {
me.unresolved = append(me.unresolved, xp)
} else {
data := xp.evaluate(nil)
me.resolved[data.toString()] = data
}
}
// isResolvable tells if any expr is resolvable
func (me *ExprList) isResolvable() bool {
return len(me.unresolved) > 0
}