refactored data-types to reduce plugin sizes
This commit is contained in:
+29
-21
@@ -12,6 +12,14 @@ 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"
|
||||
"git.portale-stac.it/go-pkg/expr/types/array"
|
||||
"git.portale-stac.it/go-pkg/expr/types/boolean"
|
||||
"git.portale-stac.it/go-pkg/expr/types/dict"
|
||||
"git.portale-stac.it/go-pkg/expr/types/float"
|
||||
"git.portale-stac.it/go-pkg/expr/types/fract"
|
||||
"git.portale-stac.it/go-pkg/expr/types/list"
|
||||
"git.portale-stac.it/go-pkg/expr/types/str"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,42 +32,42 @@ func isNilFunc(ctx kern.ExprContext, name string, args map[string]any) (result a
|
||||
}
|
||||
|
||||
func isIntFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
result = kern.IsInteger(args[kern.ParamValue])
|
||||
result = types.IsInteger(args[kern.ParamValue])
|
||||
return
|
||||
}
|
||||
|
||||
func isFloatFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
result = kern.IsFloat(args[kern.ParamValue])
|
||||
result = float.IsFloat(args[kern.ParamValue])
|
||||
return
|
||||
}
|
||||
|
||||
func isBoolFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
result = kern.IsBool(args[kern.ParamValue])
|
||||
result = boolean.IsBool(args[kern.ParamValue])
|
||||
return
|
||||
}
|
||||
|
||||
func isStringFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
result = kern.IsString(args[kern.ParamValue])
|
||||
result = str.IsString(args[kern.ParamValue])
|
||||
return
|
||||
}
|
||||
|
||||
func isFractionFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
result = kern.IsFraction(args[kern.ParamValue])
|
||||
result = fract.IsFraction(args[kern.ParamValue])
|
||||
return
|
||||
}
|
||||
|
||||
func isRationalFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
result = kern.IsRational(args[kern.ParamValue])
|
||||
result = fract.IsRational(args[kern.ParamValue])
|
||||
return
|
||||
}
|
||||
|
||||
func isListFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
result = kern.IsList(args[kern.ParamValue])
|
||||
result = array.IsList(args[kern.ParamValue])
|
||||
return
|
||||
}
|
||||
|
||||
func isDictionaryFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
result = kern.IsDict(args[kern.ParamValue])
|
||||
result = dict.IsDict(args[kern.ParamValue])
|
||||
return
|
||||
}
|
||||
|
||||
@@ -67,7 +75,7 @@ func boolFunc(ctx kern.ExprContext, name string, args map[string]any) (result an
|
||||
switch v := args[kern.ParamValue].(type) {
|
||||
case int64:
|
||||
result = (v != 0)
|
||||
case *kern.FractionType:
|
||||
case *fract.FractionType:
|
||||
result = v.N() != 0
|
||||
case float64:
|
||||
result = v != 0.0
|
||||
@@ -75,9 +83,9 @@ func boolFunc(ctx kern.ExprContext, name string, args map[string]any) (result an
|
||||
result = v
|
||||
case string:
|
||||
result = len(v) > 0
|
||||
case *kern.ListType:
|
||||
case *array.ListType:
|
||||
result = len(*v) > 0
|
||||
case *kern.DictType:
|
||||
case *dict.DictType:
|
||||
result = len(*v) > 0
|
||||
default:
|
||||
err = kern.ErrCantConvert(name, v, "bool")
|
||||
@@ -102,7 +110,7 @@ func intFunc(ctx kern.ExprContext, name string, args map[string]any) (result any
|
||||
if i, err = strconv.Atoi(v); err == nil {
|
||||
result = int64(i)
|
||||
}
|
||||
case *kern.FractionType:
|
||||
case *fract.FractionType:
|
||||
result = int64(v.N() / v.D())
|
||||
default:
|
||||
err = kern.ErrCantConvert(name, v, "int")
|
||||
@@ -127,7 +135,7 @@ func decFunc(ctx kern.ExprContext, name string, args map[string]any) (result any
|
||||
if f, err = strconv.ParseFloat(v, 64); err == nil {
|
||||
result = f
|
||||
}
|
||||
case *kern.FractionType:
|
||||
case *fract.FractionType:
|
||||
result = v.ToFloat()
|
||||
default:
|
||||
err = kern.ErrCantConvert(name, v, "float")
|
||||
@@ -149,7 +157,7 @@ func stringFunc(ctx kern.ExprContext, name string, args map[string]any) (result
|
||||
}
|
||||
case string:
|
||||
result = v
|
||||
case *kern.FractionType:
|
||||
case *fract.FractionType:
|
||||
result = v.ToString(0)
|
||||
case kern.Formatter:
|
||||
result = v.ToString(0)
|
||||
@@ -174,19 +182,19 @@ func fractFunc(ctx kern.ExprContext, name string, args map[string]any) (result a
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
result = kern.NewFraction(v, den)
|
||||
result = fract.NewFraction(v, den)
|
||||
}
|
||||
case float64:
|
||||
result, err = kern.Float64ToFraction(v)
|
||||
result, err = fract.Float64ToFraction(v)
|
||||
case bool:
|
||||
if v {
|
||||
result = kern.NewFraction(1, 1)
|
||||
result = fract.NewFraction(1, 1)
|
||||
} else {
|
||||
result = kern.NewFraction(0, 1)
|
||||
result = fract.NewFraction(0, 1)
|
||||
}
|
||||
case string:
|
||||
result, err = kern.MakeGeneratingFraction(v)
|
||||
case *kern.FractionType:
|
||||
result, err = fract.MakeGeneratingFraction(v)
|
||||
case *fract.FractionType:
|
||||
result = v
|
||||
default:
|
||||
err = kern.ErrCantConvert(name, v, "float")
|
||||
@@ -276,7 +284,7 @@ func charFunc(ctx kern.ExprContext, name string, args map[string]any) (result an
|
||||
}
|
||||
|
||||
func seqFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||
list := kern.NewLinkedList()
|
||||
list := list.NewLinkedList()
|
||||
items := args[kern.ParamValue].([]any)
|
||||
for _, arg := range items {
|
||||
list.PushBack(arg)
|
||||
|
||||
Reference in New Issue
Block a user