moved scanner sources to package 'scan'

This commit is contained in:
2026-05-03 14:19:17 +02:00
parent f63ff5953e
commit 7f34ccf955
66 changed files with 1793 additions and 1726 deletions
+12 -11
View File
@@ -8,24 +8,25 @@ import (
"fmt"
"git.portale-stac.it/go-pkg/expr/kern"
"git.portale-stac.it/go-pkg/expr/scan"
)
//-------- fact term
func newFactTerm(tk *Token) (inst *term) {
return &term{
tk: *tk,
children: make([]*term, 0, 1),
position: posPostfix,
priority: priFact,
evalFunc: evalFact,
func newFactTerm(tk *scan.Token) (inst *scan.Term) {
return &scan.Term{
Tk: *tk,
Children: make([]*scan.Term, 0, 1),
Position: scan.PosPostfix,
Priority: scan.PriFact,
EvalFunc: evalFact,
}
}
func evalFact(ctx kern.ExprContext, opTerm *term) (v any, err error) {
func evalFact(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
var leftValue any
if leftValue, err = opTerm.evalPrefix(ctx); err != nil {
if leftValue, err = opTerm.Children[0].Compute(ctx); err != nil {
return
}
@@ -40,12 +41,12 @@ func evalFact(ctx kern.ExprContext, opTerm *term) (v any, err error) {
err = fmt.Errorf("factorial of a negative integer (%d) is not allowed", i)
}
} else {
err = opTerm.errIncompatiblePrefixPostfixType(leftValue)
err = opTerm.Errorf("incompatible type for factorial: %s", kern.TypeName(leftValue))
}
return
}
// init
func init() {
registerTermConstructor(SymExclamation, newFactTerm)
scan.RegisterTermConstructor(scan.SymExclamation, newFactTerm)
}