operator at for dict

This commit is contained in:
2026-07-14 06:50:56 +02:00
parent bf2c7df0f0
commit 8c55f4ac4b
3 changed files with 38 additions and 5 deletions
+13 -5
View File
@@ -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)
}