new operator 'in': it returns true if a item belongs to a list or if a key belongs to a dict
This commit is contained in:
parent
a543360151
commit
9ea170e53b
@ -16,10 +16,10 @@ func newInTerm(tk *Token) (inst *term) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasKey(d map[any]any, target any) (ok bool) {
|
// func hasKey(d map[any]any, target any) (ok bool) {
|
||||||
_, ok = d[target]
|
// _, ok = d[target]
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
func evalIn(ctx ExprContext, self *term) (v any, err error) {
|
func evalIn(ctx ExprContext, self *term) (v any, err error) {
|
||||||
var leftValue, rightValue any
|
var leftValue, rightValue any
|
||||||
@ -32,8 +32,8 @@ func evalIn(ctx ExprContext, self *term) (v any, err error) {
|
|||||||
list, _ := rightValue.(*ListType)
|
list, _ := rightValue.(*ListType)
|
||||||
v = list.indexDeepCmp(leftValue) >= 0
|
v = list.indexDeepCmp(leftValue) >= 0
|
||||||
} else if IsDict(rightValue) {
|
} else if IsDict(rightValue) {
|
||||||
d, _ := rightValue.(map[any]any)
|
dict, _ := rightValue.(*DictType)
|
||||||
v = hasKey(d, leftValue)
|
v = dict.hasKey(leftValue)
|
||||||
} else {
|
} else {
|
||||||
err = self.errIncompatibleTypes(leftValue, rightValue)
|
err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user