moved scanner sources to package 'scan'
This commit is contained in:
+32
-31
@@ -8,31 +8,32 @@ import (
|
||||
"errors"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
"git.portale-stac.it/go-pkg/expr/scan"
|
||||
)
|
||||
|
||||
// -------- function call term
|
||||
func newFuncCallTerm(tk *Token, args []*term) *term {
|
||||
var pos termPosition = posLeaf
|
||||
func newFuncCallTerm(tk *scan.Token, args []*scan.Term) *scan.Term {
|
||||
var pos scan.TermPosition = scan.PosLeaf
|
||||
if len(args) > 0 {
|
||||
pos = posMultifix
|
||||
pos = scan.PosMultifix
|
||||
}
|
||||
return &term{
|
||||
tk: *tk,
|
||||
parent: nil,
|
||||
children: args,
|
||||
position: pos,
|
||||
priority: priValue,
|
||||
evalFunc: evalFuncCall,
|
||||
return &scan.Term{
|
||||
Tk: *tk,
|
||||
Parent: nil,
|
||||
Children: args,
|
||||
Position: pos,
|
||||
Priority: scan.PriValue,
|
||||
EvalFunc: evalFuncCall,
|
||||
}
|
||||
}
|
||||
|
||||
// -------- eval func call
|
||||
// func _evalFuncCall(ctx ExprContext, opTerm *term) (v any, err error) {
|
||||
// name, _ := opTerm.tk.Value.(string)
|
||||
// params := make([]any, len(opTerm.children), len(opTerm.children)+5)
|
||||
// for i, tree := range opTerm.children {
|
||||
// name, _ := opTerm.Tk.Value.(string)
|
||||
// params := make([]any, len(opTerm.Children), len(opTerm.Children)+5)
|
||||
// for i, tree := range opTerm.Children {
|
||||
// var param any
|
||||
// if param, err = tree.compute(ctx); err != nil {
|
||||
// if param, err = tree.Compute(ctx); err != nil {
|
||||
// break
|
||||
// }
|
||||
// params[i] = param
|
||||
@@ -44,35 +45,35 @@ func newFuncCallTerm(tk *Token, args []*term) *term {
|
||||
// return
|
||||
// }
|
||||
|
||||
func evalFuncCall(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
name, _ := opTerm.tk.Value.(string)
|
||||
func evalFuncCall(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
name, _ := opTerm.Tk.Value.(string)
|
||||
v, err = kern.CallFunctionByTerm(ctx, name, opTerm)
|
||||
return
|
||||
}
|
||||
|
||||
// -------- function definition term
|
||||
func newFuncDefTerm(tk *Token, args []*term) *term {
|
||||
return &term{
|
||||
tk: *tk, // value is the expression body
|
||||
parent: nil,
|
||||
children: args, // function params
|
||||
position: posLeaf,
|
||||
priority: priValue,
|
||||
evalFunc: evalFuncDef,
|
||||
func newFuncDefTerm(tk *scan.Token, args []*scan.Term) *scan.Term {
|
||||
return &scan.Term{
|
||||
Tk: *tk, // value is the expression body
|
||||
Parent: nil,
|
||||
Children: args, // function params
|
||||
Position: scan.PosLeaf,
|
||||
Priority: scan.PriValue,
|
||||
EvalFunc: evalFuncDef,
|
||||
}
|
||||
}
|
||||
|
||||
// -------- eval func def
|
||||
func evalFuncDef(ctx kern.ExprContext, opTerm *term) (v any, err error) {
|
||||
bodySpec := opTerm.value()
|
||||
if ast, ok := bodySpec.(*ast); ok {
|
||||
paramList := make([]kern.ExprFuncParam, 0, len(opTerm.children))
|
||||
for _, param := range opTerm.children {
|
||||
func evalFuncDef(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
bodySpec := opTerm.Value()
|
||||
if ast, ok := bodySpec.(*scan.Ast); ok {
|
||||
paramList := make([]kern.ExprFuncParam, 0, len(opTerm.Children))
|
||||
for _, param := range opTerm.Children {
|
||||
var defValue any
|
||||
flags := paramFlags(0)
|
||||
if len(param.children) > 0 {
|
||||
if len(param.Children) > 0 {
|
||||
flags |= PfDefault
|
||||
if defValue, err = param.children[0].Compute(ctx); err != nil {
|
||||
if defValue, err = param.Children[0].Compute(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user