dict: implemented sub-field access, e.g D=["sub-dict"]["sub-field"]
This commit is contained in:
@@ -6,6 +6,7 @@ package expr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"git.portale-stac.it/go-pkg/expr/scan"
|
"git.portale-stac.it/go-pkg/expr/scan"
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
@@ -401,7 +402,8 @@ func couldBeACollection(t *scan.Term) bool {
|
|||||||
if t != nil {
|
if t != nil {
|
||||||
sym = t.Symbol()
|
sym = t.Symbol()
|
||||||
}
|
}
|
||||||
return sym == scan.SymList || sym == scan.SymString || sym == scan.SymDict || sym == scan.SymExpression || sym == scan.SymVariable
|
// return sym == scan.SymList || sym == scan.SymString || sym == scan.SymDict || sym == scan.SymExpression || sym == scan.SymVariable
|
||||||
|
return slices.Contains([]scan.Symbol{scan.SymList, scan.SymString, scan.SymDict, scan.SymExpression, scan.SymVariable, scan.SymIndex}, sym)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listSubTree(tree *scan.Ast, listTerm *scan.Term, allowIndeces bool) (root *scan.Term, err error) {
|
func listSubTree(tree *scan.Ast, listTerm *scan.Term, allowIndeces bool) (root *scan.Term, err error) {
|
||||||
|
|||||||
+4
-4
@@ -46,7 +46,7 @@ func TestDictParser(t *testing.T) {
|
|||||||
runTestSuite(t, section, inputs)
|
runTestSuite(t, section, inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _TestPoc(t *testing.T) {
|
func TestPoc(t *testing.T) {
|
||||||
section := "Dict-Assign-Item"
|
section := "Dict-Assign-Item"
|
||||||
ctx := NewSimpleStore()
|
ctx := NewSimpleStore()
|
||||||
ctx.UnsafeSetVar(
|
ctx.UnsafeSetVar(
|
||||||
@@ -62,10 +62,10 @@ func _TestPoc(t *testing.T) {
|
|||||||
inputs := []inputType{
|
inputs := []inputType{
|
||||||
/* 1 */ {`D.a.uno`, int64(10), nil},
|
/* 1 */ {`D.a.uno`, int64(10), nil},
|
||||||
/* 2 */ {`D.a.uno = 111; D.a."uno"`, int64(111), nil},
|
/* 2 */ {`D.a.uno = 111; D.a."uno"`, int64(111), nil},
|
||||||
/* 3 */ {`D["a"]["uno"]`, int64(111), nil},
|
/* 3 */ {`D.a.uno = 111; D["a"]["uno"]`, int64(111), nil},
|
||||||
}
|
}
|
||||||
runCtxTestSuiteSpec(t, ctx, section, inputs, 3)
|
// runCtxTestSuiteSpec(t, ctx, section, inputs, 3)
|
||||||
// runCtxTestSuite(t, ctx, section, inputs)
|
runCtxTestSuite(t, ctx, section, inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDictToStringMultiLine(t *testing.T) {
|
func TestDictToStringMultiLine(t *testing.T) {
|
||||||
|
|||||||
+4
-2
@@ -6,19 +6,21 @@ package expr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCollections(t *testing.T) {
|
func TestCollections(t *testing.T) {
|
||||||
section := "Collection"
|
section := "Index"
|
||||||
inputs := []inputType{
|
inputs := []inputType{
|
||||||
/* 1 */ {`"abcdef"[1:3]`, "bc", nil},
|
/* 1 */ {`"abcdef"[1:3]`, "bc", nil},
|
||||||
/* 2 */ {`"abcdef"[:3]`, "abc", nil},
|
/* 2 */ {`"abcdef"[:3]`, "abc", nil},
|
||||||
/* 3 */ {`"abcdef"[1:]`, "bcdef", nil},
|
/* 3 */ {`"abcdef"[1:]`, "bcdef", nil},
|
||||||
/* 4 */ {`"abcdef"[:]`, "abcdef", nil},
|
/* 4 */ {`"abcdef"[:]`, "abcdef", nil},
|
||||||
// /* 5 */ {`[0,1,2,3,4][:]`, ListType{int64(0), int64(1), int64(2), int64(3), int64(4)}, nil},
|
|
||||||
/* 5 */ {`"abcdef"[1:2:3]`, nil, `[1:14] invalid range specification`},
|
/* 5 */ {`"abcdef"[1:2:3]`, nil, `[1:14] invalid range specification`},
|
||||||
/* 6 */ {`"abcdef"[((1>0)?{1}:{0}):3]`, "bc", nil},
|
/* 6 */ {`"abcdef"[((1>0)?{1}:{0}):3]`, "bc", nil},
|
||||||
/* 7 */ {`"abcdef"[[0,1][0]:1]`, "a", nil},
|
/* 7 */ {`"abcdef"[[0,1][0]:1]`, "a", nil},
|
||||||
|
/* 8 */ {`[0,1,2,3,4][:]`, kern.NewListA(int64(0), int64(1), int64(2), int64(3), int64(4)), nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Setenv("EXPR_PATH", ".")
|
t.Setenv("EXPR_PATH", ".")
|
||||||
|
|||||||
Reference in New Issue
Block a user