moved a subset of source file to the kern package

This commit is contained in:
2026-04-27 19:43:37 +02:00
parent f100adead3
commit 4d910dd069
107 changed files with 2080 additions and 1380 deletions
+32 -27
View File
@@ -4,7 +4,11 @@
// operator-bool.go
package expr
import "fmt"
import (
"fmt"
"git.portale-stac.it/go-pkg/expr/kern"
)
//-------- NOT term
@@ -18,17 +22,17 @@ func newNotTerm(tk *Token) (inst *term) {
}
}
func evalNot(ctx ExprContext, opTerm *term) (v any, err error) {
func evalNot(ctx kern.ExprContext, opTerm *term) (v any, err error) {
var rightValue any
if rightValue, err = opTerm.evalPrefix(ctx); err != nil {
return
}
if b, ok := ToBool(rightValue); ok {
if b, ok := kern.ToBool(rightValue); ok {
v = !b
} else {
err = opTerm.errIncompatibleType(rightValue)
err = opTerm.errIncompatiblePrefixPostfixType(rightValue)
}
return
}
@@ -45,8 +49,8 @@ func newAndTerm(tk *Token) (inst *term) {
}
}
func evalAnd(ctx ExprContext, self *term) (v any, err error) {
if CtrlIsEnabled(ctx, ControlBoolShortcut) {
func evalAnd(ctx kern.ExprContext, self *term) (v any, err error) {
if kern.CtrlIsEnabled(ctx, kern.ControlBoolShortcut) {
v, err = evalAndWithShortcut(ctx, self)
} else {
v, err = evalAndWithoutShortcut(ctx, self)
@@ -54,7 +58,7 @@ func evalAnd(ctx ExprContext, self *term) (v any, err error) {
return
}
func evalAndWithoutShortcut(ctx ExprContext, self *term) (v any, err error) {
func evalAndWithoutShortcut(ctx kern.ExprContext, self *term) (v any, err error) {
var leftValue, rightValue any
var leftBool, rightBool bool
var lok, rok bool
@@ -63,8 +67,8 @@ func evalAndWithoutShortcut(ctx ExprContext, self *term) (v any, err error) {
return
}
leftBool, lok = ToBool(leftValue)
rightBool, rok = ToBool(rightValue)
leftBool, lok = kern.ToBool(leftValue)
rightBool, rok = kern.ToBool(rightValue)
if lok && rok {
v = leftBool && rightBool
@@ -74,24 +78,25 @@ func evalAndWithoutShortcut(ctx ExprContext, self *term) (v any, err error) {
return
}
func evalAndWithShortcut(ctx ExprContext, self *term) (v any, err error) {
func evalAndWithShortcut(ctx kern.ExprContext, self *term) (v any, err error) {
var leftValue, rightValue any
if err = self.checkOperands(); err != nil {
return
}
if leftValue, err = self.children[0].compute(ctx); err != nil {
if leftValue, err = self.children[0].Compute(ctx); err != nil {
return
}
if leftBool, lok := ToBool(leftValue); !lok {
err = fmt.Errorf("got %s as left operand type of 'AND' operator, it must be bool", TypeName(leftValue))
return
if leftBool, lok := kern.ToBool(leftValue); !lok {
// err = fmt.Errorf("got %s as left operand type of 'AND' operator, it must be bool", expr.TypeName(leftValue))
// return
err = self.errIncompatibleType(leftValue, "left")
} else if !leftBool {
v = false
} else if rightValue, err = self.children[1].compute(ctx); err == nil {
if rightBool, rok := ToBool(rightValue); rok {
} else if rightValue, err = self.children[1].Compute(ctx); err == nil {
if rightBool, rok := kern.ToBool(rightValue); rok {
v = rightBool
} else {
err = self.errIncompatibleTypes(leftValue, rightValue)
@@ -112,8 +117,8 @@ func newOrTerm(tk *Token) (inst *term) {
}
}
func evalOr(ctx ExprContext, self *term) (v any, err error) {
if CtrlIsEnabled(ctx, ControlBoolShortcut) {
func evalOr(ctx kern.ExprContext, self *term) (v any, err error) {
if kern.CtrlIsEnabled(ctx, kern.ControlBoolShortcut) {
v, err = evalOrWithShortcut(ctx, self)
} else {
v, err = evalOrWithoutShortcut(ctx, self)
@@ -121,7 +126,7 @@ func evalOr(ctx ExprContext, self *term) (v any, err error) {
return
}
func evalOrWithoutShortcut(ctx ExprContext, self *term) (v any, err error) {
func evalOrWithoutShortcut(ctx kern.ExprContext, self *term) (v any, err error) {
var leftValue, rightValue any
var leftBool, rightBool bool
var lok, rok bool
@@ -130,8 +135,8 @@ func evalOrWithoutShortcut(ctx ExprContext, self *term) (v any, err error) {
return
}
leftBool, lok = ToBool(leftValue)
rightBool, rok = ToBool(rightValue)
leftBool, lok = kern.ToBool(leftValue)
rightBool, rok = kern.ToBool(rightValue)
if lok && rok {
v = leftBool || rightBool
@@ -141,24 +146,24 @@ func evalOrWithoutShortcut(ctx ExprContext, self *term) (v any, err error) {
return
}
func evalOrWithShortcut(ctx ExprContext, self *term) (v any, err error) {
func evalOrWithShortcut(ctx kern.ExprContext, self *term) (v any, err error) {
var leftValue, rightValue any
if err = self.checkOperands(); err != nil {
return
}
if leftValue, err = self.children[0].compute(ctx); err != nil {
if leftValue, err = self.children[0].Compute(ctx); err != nil {
return
}
if leftBool, lok := ToBool(leftValue); !lok {
err = fmt.Errorf("got %s as left operand type of 'OR' operator, it must be bool", TypeName(leftValue))
if leftBool, lok := kern.ToBool(leftValue); !lok {
err = fmt.Errorf("got %s as left operand type of 'OR' operator, it must be bool", kern.TypeName(leftValue))
return
} else if leftBool {
v = true
} else if rightValue, err = self.children[1].compute(ctx); err == nil {
if rightBool, rok := ToBool(rightValue); rok {
} else if rightValue, err = self.children[1].Compute(ctx); err == nil {
if rightBool, rok := kern.ToBool(rightValue); rok {
v = rightBool
} else {
err = self.errIncompatibleTypes(leftValue, rightValue)