operator at for dict
This commit is contained in:
+13
-5
@@ -8,6 +8,7 @@ import (
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
"git.portale-stac.it/go-pkg/expr/scan"
|
||||
"git.portale-stac.it/go-pkg/expr/types/array"
|
||||
"git.portale-stac.it/go-pkg/expr/types/dict"
|
||||
"git.portale-stac.it/go-pkg/expr/types/list"
|
||||
)
|
||||
|
||||
@@ -37,13 +38,20 @@ func evalAt(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
|
||||
if array.IsArray(rightValue) {
|
||||
a, _ := rightValue.(*array.ArrayType)
|
||||
v = a.IndexDeepSameCmp(leftValue)
|
||||
// } else if dict.IsDict(rightValue) {
|
||||
// dict, _ := rightValue.(*dict.DictType)
|
||||
// v = dict.HasKey(leftValue)
|
||||
if index := a.IndexDeepSameCmp(leftValue); index >= 0 {
|
||||
v = index
|
||||
}
|
||||
} else if dict.IsDict(rightValue) {
|
||||
dict, _ := rightValue.(*dict.DictType)
|
||||
if k, exists := dict.FindKey(leftValue); exists {
|
||||
v = k
|
||||
}
|
||||
|
||||
} else if list.IsLinkedList(rightValue) {
|
||||
ls, _ := rightValue.(*list.LinkedList)
|
||||
v = ls.Index(leftValue)
|
||||
if index := ls.Index(leftValue); index >= 0 {
|
||||
v = index
|
||||
}
|
||||
} else {
|
||||
err = opTerm.ErrIncompatibleTypes(leftValue, rightValue)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user