Compare commits
No commits in common. "b76481bbf24f6f4d1f003547cb3f32ded365f647" and "54bc759f7007844d3663e4eb9a89711e513323c5" have entirely different histories.
b76481bbf2
...
54bc759f70
@ -108,7 +108,3 @@ func ImportMathFuncs(ctx ExprContext) {
|
|||||||
ctx.RegisterFunc("add", &simpleFunctor{f: addFunc}, 0, -1)
|
ctx.RegisterFunc("add", &simpleFunctor{f: addFunc}, 0, -1)
|
||||||
ctx.RegisterFunc("mul", &simpleFunctor{f: mulFunc}, 0, -1)
|
ctx.RegisterFunc("mul", &simpleFunctor{f: mulFunc}, 0, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
registerImport("math.arith", ImportMathFuncs)
|
|
||||||
}
|
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
||||||
// All rights reserved.
|
|
||||||
|
|
||||||
// function-register.go
|
|
||||||
package expr
|
|
||||||
|
|
||||||
import (
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
var functionRegister map[string]func(ExprContext)
|
|
||||||
|
|
||||||
func registerImport(name string, importFunc func(ExprContext)) {
|
|
||||||
if functionRegister == nil {
|
|
||||||
functionRegister = make(map[string]func(ExprContext))
|
|
||||||
}
|
|
||||||
functionRegister[name] = importFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
func ImportInContext(ctx ExprContext, name string) (exists bool) {
|
|
||||||
var importFunc func(ExprContext)
|
|
||||||
if importFunc, exists = functionRegister[name]; exists {
|
|
||||||
importFunc(ctx)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func ImportInContextByGlobPattern(ctx ExprContext, pattern string) (count int, err error) {
|
|
||||||
var matched bool
|
|
||||||
for name, importFunc := range functionRegister {
|
|
||||||
if matched, err = filepath.Match(pattern, name); err == nil {
|
|
||||||
if matched {
|
|
||||||
count++
|
|
||||||
importFunc(ctx)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
if functionRegister == nil {
|
|
||||||
functionRegister = make(map[string]func(ExprContext))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
||||||
// All rights reserved.
|
|
||||||
|
|
||||||
// operator-length.go
|
|
||||||
package expr
|
|
||||||
|
|
||||||
//-------- builtin term
|
|
||||||
|
|
||||||
func newBuiltinTerm(tk *Token) (inst *term) {
|
|
||||||
return &term{
|
|
||||||
tk: *tk,
|
|
||||||
children: make([]*term, 0, 1),
|
|
||||||
position: posPrefix,
|
|
||||||
priority: priSign,
|
|
||||||
evalFunc: evalBuiltin,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func evalBuiltin(ctx ExprContext, self *term) (v any, err error) {
|
|
||||||
var rightValue any
|
|
||||||
|
|
||||||
if rightValue, err = self.evalPrefix(ctx); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
count := 0
|
|
||||||
if isList(rightValue) {
|
|
||||||
list, _ := rightValue.([]any)
|
|
||||||
for i, moduleSpec := range list {
|
|
||||||
if module, ok := moduleSpec.(string); ok {
|
|
||||||
if ImportInContext(ctx, module) {
|
|
||||||
count++
|
|
||||||
} else {
|
|
||||||
err = self.Errorf("unknown module %q", module)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = self.Errorf("expected string at item nr %d, got %T", i+1, moduleSpec)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if isString(rightValue) {
|
|
||||||
module, _ := rightValue.(string)
|
|
||||||
count, err = ImportInContextByGlobPattern(ctx, module)
|
|
||||||
} else {
|
|
||||||
err = self.errIncompatibleType(rightValue)
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
v = count
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// init
|
|
||||||
func init() {
|
|
||||||
registerTermConstructor(SymKwBuiltin, newBuiltinTerm)
|
|
||||||
}
|
|
12
symbol.go
12
symbol.go
@ -89,7 +89,6 @@ const (
|
|||||||
SymKwOr
|
SymKwOr
|
||||||
SymKwBut
|
SymKwBut
|
||||||
SymKwFunc
|
SymKwFunc
|
||||||
SymKwBuiltin
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var keywords map[string]Symbol
|
var keywords map[string]Symbol
|
||||||
@ -97,11 +96,10 @@ var keywords map[string]Symbol
|
|||||||
func init() {
|
func init() {
|
||||||
//keywords = make(map[string]Symbol)
|
//keywords = make(map[string]Symbol)
|
||||||
keywords = map[string]Symbol{
|
keywords = map[string]Symbol{
|
||||||
"AND": SymKwAnd,
|
"AND": SymKwAnd,
|
||||||
"BUILTIN": SymKwBuiltin,
|
"BUT": SymKwBut,
|
||||||
"BUT": SymKwBut,
|
"FUNC": SymKwFunc,
|
||||||
"FUNC": SymKwFunc,
|
"NOT": SymKwNot,
|
||||||
"NOT": SymKwNot,
|
"OR": SymKwOr,
|
||||||
"OR": SymKwOr,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user