-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpr_function.go
35 lines (32 loc) · 912 Bytes
/
expr_function.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
package lure
// ExprFunction represents an identity node in the AST
type ExprFunction struct {
left Expr
list *ExprList
}
// evaluate resolves function expression against the context
// Use left node string to search (case sensitive) for the functional in the extensions.
// If hit miss, return false, else use the functional to eval.
func (me ExprFunction) evaluate(context map[string]IData) IData {
if me.left == nil || context == nil {
return boolDataFalse
}
// return true for "<left> like <right>" if
var params []IData
if me.list != nil {
for _, xp := range me.list.exprs {
if xp.isResolvable() {
params = append(params, xp.evaluate(context))
}
}
}
leftData := me.left.evaluate(context)
funcName := leftData.toString()
if f, ok := getFunctions()[funcName]; ok {
return f.derive(params)
}
return boolDataFalse
}
func (me ExprFunction) isResolvable() bool {
return true
}