moved scanner sources to package 'scan'
This commit is contained in:
+12
-12
@@ -10,27 +10,27 @@ import (
|
||||
"fmt"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
"git.portale-stac.it/go-pkg/expr/scan"
|
||||
)
|
||||
|
||||
// -------- fraction term
|
||||
func newFractionTerm(tk *Token) *term {
|
||||
return &term{
|
||||
tk: *tk,
|
||||
parent: nil,
|
||||
children: make([]*term, 0, 2),
|
||||
position: posInfix,
|
||||
priority: priFraction,
|
||||
evalFunc: evalFraction,
|
||||
func newFractionTerm(tk *scan.Token) *scan.Term {
|
||||
return &scan.Term{
|
||||
Tk: *tk,
|
||||
Children: make([]*scan.Term, 0, 2),
|
||||
Position: scan.PosInfix,
|
||||
Priority: scan.PriFraction,
|
||||
EvalFunc: evalFraction,
|
||||
}
|
||||
}
|
||||
|
||||
// -------- eval func
|
||||
func evalFraction(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
func evalFraction(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
var numValue, denValue any
|
||||
var num, den int64
|
||||
var ok bool
|
||||
|
||||
if numValue, denValue, err = opTerm.evalInfix(ctx); err != nil {
|
||||
if numValue, denValue, err = opTerm.EvalInfix(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if num, ok = numValue.(int64); !ok {
|
||||
@@ -42,7 +42,7 @@ func evalFraction(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
return
|
||||
}
|
||||
if den == 0 {
|
||||
err = opTerm.errDivisionByZero()
|
||||
err = opTerm.Errorf("division by zero")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -71,5 +71,5 @@ func evalFraction(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
// init
|
||||
func init() {
|
||||
// registerTermConstructor(SymVertBar, newFractionTerm)
|
||||
registerTermConstructor(SymColon, newFractionTerm)
|
||||
scan.RegisterTermConstructor(scan.SymColon, newFractionTerm)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user