exported some identifier
This commit is contained in:
parent
29bc2c62a3
commit
34dc828ead
@ -5,17 +5,17 @@
|
|||||||
package expr
|
package expr
|
||||||
|
|
||||||
const (
|
const (
|
||||||
paramCount = "count"
|
ParamCount = "count"
|
||||||
paramItem = "item"
|
ParamItem = "item"
|
||||||
paramParts = "parts"
|
ParamParts = "parts"
|
||||||
paramSeparator = "separator"
|
ParamSeparator = "separator"
|
||||||
paramSource = "source"
|
ParamSource = "source"
|
||||||
paramSuffix = "suffix"
|
ParamSuffix = "suffix"
|
||||||
paramPrefix = "prefix"
|
ParamPrefix = "prefix"
|
||||||
paramStart = "start"
|
ParamStart = "start"
|
||||||
paramEnd = "end"
|
ParamEnd = "end"
|
||||||
paramValue = "value"
|
ParamValue = "value"
|
||||||
paramEllipsis = "..."
|
ParamEllipsis = "..."
|
||||||
paramFilepath = "filepath"
|
ParamFilepath = "filepath"
|
||||||
paramDirpath = "dirpath"
|
ParamDirpath = "dirpath"
|
||||||
)
|
)
|
||||||
|
@ -159,7 +159,7 @@ func iteratorFunc(ctx ExprContext, name string, args []any) (result any, err err
|
|||||||
|
|
||||||
func ImportBuiltinsFuncs(ctx ExprContext) {
|
func ImportBuiltinsFuncs(ctx ExprContext) {
|
||||||
anyParams := []ExprFuncParam{
|
anyParams := []ExprFuncParam{
|
||||||
NewFuncParam(paramValue),
|
NewFuncParam(ParamValue),
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.RegisterFunc("isNil", NewGolangFunctor(isNilFunc), TypeBoolean, anyParams)
|
ctx.RegisterFunc("isNil", NewGolangFunctor(isNilFunc), TypeBoolean, anyParams)
|
||||||
@ -176,11 +176,11 @@ func ImportBuiltinsFuncs(ctx ExprContext) {
|
|||||||
ctx.RegisterFunc("int", NewGolangFunctor(intFunc), TypeInt, anyParams)
|
ctx.RegisterFunc("int", NewGolangFunctor(intFunc), TypeInt, anyParams)
|
||||||
ctx.RegisterFunc("dec", NewGolangFunctor(decFunc), TypeFloat, anyParams)
|
ctx.RegisterFunc("dec", NewGolangFunctor(decFunc), TypeFloat, anyParams)
|
||||||
ctx.RegisterFunc("fract", NewGolangFunctor(fractFunc), TypeFraction, []ExprFuncParam{
|
ctx.RegisterFunc("fract", NewGolangFunctor(fractFunc), TypeFraction, []ExprFuncParam{
|
||||||
NewFuncParam(paramValue),
|
NewFuncParam(ParamValue),
|
||||||
NewFuncParamFlagDef("denominator", PfDefault, 1),
|
NewFuncParamFlagDef("denominator", PfDefault, 1),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerImport("base", ImportBuiltinsFuncs, "Base expression tools like isNil(), int(), etc.")
|
RegisterImport("base", ImportBuiltinsFuncs, "Base expression tools like isNil(), int(), etc.")
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,13 @@ func doImport(ctx ExprContext, name string, dirList []string, it Iterator) (resu
|
|||||||
|
|
||||||
func ImportImportFuncs(ctx ExprContext) {
|
func ImportImportFuncs(ctx ExprContext) {
|
||||||
ctx.RegisterFunc("import", NewGolangFunctor(importFunc), TypeAny, []ExprFuncParam{
|
ctx.RegisterFunc("import", NewGolangFunctor(importFunc), TypeAny, []ExprFuncParam{
|
||||||
NewFuncParamFlag(paramFilepath, PfRepeat),
|
NewFuncParamFlag(ParamFilepath, PfRepeat),
|
||||||
})
|
})
|
||||||
ctx.RegisterFunc("importAll", NewGolangFunctor(importAllFunc), TypeAny, []ExprFuncParam{
|
ctx.RegisterFunc("importAll", NewGolangFunctor(importAllFunc), TypeAny, []ExprFuncParam{
|
||||||
NewFuncParamFlag(paramFilepath, PfRepeat),
|
NewFuncParamFlag(ParamFilepath, PfRepeat),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerImport("import", ImportImportFuncs, "Functions import() and include()")
|
RegisterImport("import", ImportImportFuncs, "Functions import() and include()")
|
||||||
}
|
}
|
||||||
|
@ -168,14 +168,14 @@ func mulFunc(ctx ExprContext, name string, args []any) (result any, err error) {
|
|||||||
|
|
||||||
func ImportMathFuncs(ctx ExprContext) {
|
func ImportMathFuncs(ctx ExprContext) {
|
||||||
ctx.RegisterFunc("add", &golangFunctor{f: addFunc}, TypeNumber, []ExprFuncParam{
|
ctx.RegisterFunc("add", &golangFunctor{f: addFunc}, TypeNumber, []ExprFuncParam{
|
||||||
NewFuncParamFlagDef(paramValue, PfDefault|PfRepeat, int64(0)),
|
NewFuncParamFlagDef(ParamValue, PfDefault|PfRepeat, int64(0)),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("mul", &golangFunctor{f: mulFunc}, TypeNumber, []ExprFuncParam{
|
ctx.RegisterFunc("mul", &golangFunctor{f: mulFunc}, TypeNumber, []ExprFuncParam{
|
||||||
NewFuncParamFlagDef(paramValue, PfDefault|PfRepeat, int64(1)),
|
NewFuncParamFlagDef(ParamValue, PfDefault|PfRepeat, int64(1)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerImport("math.arith", ImportMathFuncs, "Functions add() and mul()")
|
RegisterImport("math.arith", ImportMathFuncs, "Functions add() and mul()")
|
||||||
}
|
}
|
||||||
|
@ -188,13 +188,13 @@ func readFileFunc(ctx ExprContext, name string, args []any) (result any, err err
|
|||||||
|
|
||||||
func ImportOsFuncs(ctx ExprContext) {
|
func ImportOsFuncs(ctx ExprContext) {
|
||||||
ctx.RegisterFunc("openFile", NewGolangFunctor(openFileFunc), TypeHandle, []ExprFuncParam{
|
ctx.RegisterFunc("openFile", NewGolangFunctor(openFileFunc), TypeHandle, []ExprFuncParam{
|
||||||
NewFuncParam(paramFilepath),
|
NewFuncParam(ParamFilepath),
|
||||||
})
|
})
|
||||||
ctx.RegisterFunc("appendFile", NewGolangFunctor(appendFileFunc), TypeHandle, []ExprFuncParam{
|
ctx.RegisterFunc("appendFile", NewGolangFunctor(appendFileFunc), TypeHandle, []ExprFuncParam{
|
||||||
NewFuncParam(paramFilepath),
|
NewFuncParam(ParamFilepath),
|
||||||
})
|
})
|
||||||
ctx.RegisterFunc("createFile", NewGolangFunctor(createFileFunc), TypeHandle, []ExprFuncParam{
|
ctx.RegisterFunc("createFile", NewGolangFunctor(createFileFunc), TypeHandle, []ExprFuncParam{
|
||||||
NewFuncParam(paramFilepath),
|
NewFuncParam(ParamFilepath),
|
||||||
})
|
})
|
||||||
ctx.RegisterFunc("writeFile", NewGolangFunctor(writeFileFunc), TypeInt, []ExprFuncParam{
|
ctx.RegisterFunc("writeFile", NewGolangFunctor(writeFileFunc), TypeInt, []ExprFuncParam{
|
||||||
NewFuncParam(TypeHandle),
|
NewFuncParam(TypeHandle),
|
||||||
@ -210,5 +210,5 @@ func ImportOsFuncs(ctx ExprContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerImport("os.file", ImportOsFuncs, "Operating system file functions")
|
RegisterImport("os.file", ImportOsFuncs, "Operating system file functions")
|
||||||
}
|
}
|
||||||
|
@ -45,13 +45,13 @@ func joinStrFunc(ctx ExprContext, name string, args []any) (result any, err erro
|
|||||||
} else if it, ok := args[1].(Iterator); ok {
|
} else if it, ok := args[1].(Iterator); ok {
|
||||||
result, err = doJoinStr(name, sep, it)
|
result, err = doJoinStr(name, sep, it)
|
||||||
} else {
|
} else {
|
||||||
err = errInvalidParameterValue(name, paramParts, args[1])
|
err = errInvalidParameterValue(name, ParamParts, args[1])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result, err = doJoinStr(name, sep, NewArrayIterator(args[1:]))
|
result, err = doJoinStr(name, sep, NewArrayIterator(args[1:]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = errWrongParamType(name, paramSeparator, TypeString, args[0])
|
err = errWrongParamType(name, ParamSeparator, TypeString, args[0])
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func subStrFunc(ctx ExprContext, name string, args []any) (result any, err error
|
|||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if source, ok = args[0].(string); !ok {
|
if source, ok = args[0].(string); !ok {
|
||||||
return nil, errWrongParamType(name, paramSource, TypeString, args[0])
|
return nil, errWrongParamType(name, ParamSource, TypeString, args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
if start, err = toInt(args[1], name+"()"); err != nil {
|
if start, err = toInt(args[1], name+"()"); err != nil {
|
||||||
@ -91,7 +91,7 @@ func trimStrFunc(ctx ExprContext, name string, args []any) (result any, err erro
|
|||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if source, ok = args[0].(string); !ok {
|
if source, ok = args[0].(string); !ok {
|
||||||
return nil, errWrongParamType(name, paramSource, TypeString, args[0])
|
return nil, errWrongParamType(name, ParamSource, TypeString, args[0])
|
||||||
}
|
}
|
||||||
result = strings.TrimSpace(source)
|
result = strings.TrimSpace(source)
|
||||||
return
|
return
|
||||||
@ -104,7 +104,7 @@ func startsWithStrFunc(ctx ExprContext, name string, args []any) (result any, er
|
|||||||
result = false
|
result = false
|
||||||
|
|
||||||
if source, ok = args[0].(string); !ok {
|
if source, ok = args[0].(string); !ok {
|
||||||
return result, errWrongParamType(name, paramSource, TypeString, args[0])
|
return result, errWrongParamType(name, ParamSource, TypeString, args[0])
|
||||||
}
|
}
|
||||||
for i, targetSpec := range args[1:] {
|
for i, targetSpec := range args[1:] {
|
||||||
if target, ok := targetSpec.(string); ok {
|
if target, ok := targetSpec.(string); ok {
|
||||||
@ -127,7 +127,7 @@ func endsWithStrFunc(ctx ExprContext, name string, args []any) (result any, err
|
|||||||
result = false
|
result = false
|
||||||
|
|
||||||
if source, ok = args[0].(string); !ok {
|
if source, ok = args[0].(string); !ok {
|
||||||
return result, errWrongParamType(name, paramSource, TypeString, args[0])
|
return result, errWrongParamType(name, ParamSource, TypeString, args[0])
|
||||||
}
|
}
|
||||||
for i, targetSpec := range args[1:] {
|
for i, targetSpec := range args[1:] {
|
||||||
if target, ok := targetSpec.(string); ok {
|
if target, ok := targetSpec.(string); ok {
|
||||||
@ -150,7 +150,7 @@ func splitStrFunc(ctx ExprContext, name string, args []any) (result any, err err
|
|||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if source, ok = args[0].(string); !ok {
|
if source, ok = args[0].(string); !ok {
|
||||||
return result, errWrongParamType(name, paramSource, TypeString, args[0])
|
return result, errWrongParamType(name, ParamSource, TypeString, args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
if sep, ok = args[1].(string); !ok {
|
if sep, ok = args[1].(string); !ok {
|
||||||
@ -183,41 +183,41 @@ func splitStrFunc(ctx ExprContext, name string, args []any) (result any, err err
|
|||||||
// Import above functions in the context
|
// Import above functions in the context
|
||||||
func ImportStringFuncs(ctx ExprContext) {
|
func ImportStringFuncs(ctx ExprContext) {
|
||||||
ctx.RegisterFunc("joinStr", NewGolangFunctor(joinStrFunc), TypeString, []ExprFuncParam{
|
ctx.RegisterFunc("joinStr", NewGolangFunctor(joinStrFunc), TypeString, []ExprFuncParam{
|
||||||
NewFuncParam(paramSeparator),
|
NewFuncParam(ParamSeparator),
|
||||||
NewFuncParamFlag(paramItem, PfRepeat),
|
NewFuncParamFlag(ParamItem, PfRepeat),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("subStr", NewGolangFunctor(subStrFunc), TypeString, []ExprFuncParam{
|
ctx.RegisterFunc("subStr", NewGolangFunctor(subStrFunc), TypeString, []ExprFuncParam{
|
||||||
NewFuncParam(paramSource),
|
NewFuncParam(ParamSource),
|
||||||
NewFuncParamFlagDef(paramStart, PfDefault, int64(0)),
|
NewFuncParamFlagDef(ParamStart, PfDefault, int64(0)),
|
||||||
NewFuncParamFlagDef(paramCount, PfDefault, int64(-1)),
|
NewFuncParamFlagDef(ParamCount, PfDefault, int64(-1)),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("splitStr", NewGolangFunctor(splitStrFunc), "list of "+TypeString, []ExprFuncParam{
|
ctx.RegisterFunc("splitStr", NewGolangFunctor(splitStrFunc), "list of "+TypeString, []ExprFuncParam{
|
||||||
NewFuncParam(paramSource),
|
NewFuncParam(ParamSource),
|
||||||
NewFuncParamFlagDef(paramSeparator, PfDefault, ""),
|
NewFuncParamFlagDef(ParamSeparator, PfDefault, ""),
|
||||||
NewFuncParamFlagDef(paramCount, PfDefault, int64(-1)),
|
NewFuncParamFlagDef(ParamCount, PfDefault, int64(-1)),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("trimStr", NewGolangFunctor(trimStrFunc), TypeString, []ExprFuncParam{
|
ctx.RegisterFunc("trimStr", NewGolangFunctor(trimStrFunc), TypeString, []ExprFuncParam{
|
||||||
NewFuncParam(paramSource),
|
NewFuncParam(ParamSource),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("startsWithStr", NewGolangFunctor(startsWithStrFunc), TypeBoolean, []ExprFuncParam{
|
ctx.RegisterFunc("startsWithStr", NewGolangFunctor(startsWithStrFunc), TypeBoolean, []ExprFuncParam{
|
||||||
NewFuncParam(paramSource),
|
NewFuncParam(ParamSource),
|
||||||
NewFuncParam(paramPrefix),
|
NewFuncParam(ParamPrefix),
|
||||||
NewFuncParamFlag("other "+paramPrefix, PfRepeat),
|
NewFuncParamFlag("other "+ParamPrefix, PfRepeat),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("endsWithStr", NewGolangFunctor(endsWithStrFunc), TypeBoolean, []ExprFuncParam{
|
ctx.RegisterFunc("endsWithStr", NewGolangFunctor(endsWithStrFunc), TypeBoolean, []ExprFuncParam{
|
||||||
NewFuncParam(paramSource),
|
NewFuncParam(ParamSource),
|
||||||
NewFuncParam(paramSuffix),
|
NewFuncParam(ParamSuffix),
|
||||||
NewFuncParamFlag("other "+paramSuffix, PfRepeat),
|
NewFuncParamFlag("other "+ParamSuffix, PfRepeat),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the import function in the import-register.
|
// Register the import function in the import-register.
|
||||||
// That will allow to import all function of this module by the "builtin" operator."
|
// That will allow to import all function of this module by the "builtin" operator."
|
||||||
func init() {
|
func init() {
|
||||||
registerImport("string", ImportStringFuncs, "string utilities")
|
RegisterImport("string", ImportStringFuncs, "string utilities")
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func EvalStringV(source string, args []Arg) (result any, err error) {
|
|||||||
functor := NewGolangFunctor(f)
|
functor := NewGolangFunctor(f)
|
||||||
// ctx.RegisterFunc(arg.Name, functor, 0, -1)
|
// ctx.RegisterFunc(arg.Name, functor, 0, -1)
|
||||||
ctx.RegisterFunc(arg.Name, functor, TypeAny, []ExprFuncParam{
|
ctx.RegisterFunc(arg.Name, functor, TypeAny, []ExprFuncParam{
|
||||||
NewFuncParamFlagDef(paramValue, PfDefault|PfRepeat, 0),
|
NewFuncParamFlagDef(ParamValue, PfDefault|PfRepeat, 0),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("invalid function specification: %q", arg.Name)
|
err = fmt.Errorf("invalid function specification: %q", arg.Name)
|
||||||
|
@ -20,7 +20,7 @@ func newModule(importFunc func(ExprContext), description string) *module {
|
|||||||
|
|
||||||
var moduleRegister map[string]*module
|
var moduleRegister map[string]*module
|
||||||
|
|
||||||
func registerImport(name string, importFunc func(ExprContext), description string) {
|
func RegisterImport(name string, importFunc func(ExprContext), description string) {
|
||||||
if moduleRegister == nil {
|
if moduleRegister == nil {
|
||||||
moduleRegister = make(map[string]*module)
|
moduleRegister = make(map[string]*module)
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func evalAssignCoalesce(ctx ExprContext, self *term) (v any, err error) {
|
|||||||
if functor, ok := rightValue.(Functor); ok {
|
if functor, ok := rightValue.(Functor); ok {
|
||||||
//ctx.RegisterFunc(leftTerm.source(), functor, 0, -1)
|
//ctx.RegisterFunc(leftTerm.source(), functor, 0, -1)
|
||||||
ctx.RegisterFunc(leftTerm.source(), functor, TypeAny, []ExprFuncParam{
|
ctx.RegisterFunc(leftTerm.source(), functor, TypeAny, []ExprFuncParam{
|
||||||
NewFuncParamFlag(paramValue, PfDefault|PfRepeat),
|
NewFuncParamFlag(ParamValue, PfDefault|PfRepeat),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
v = rightValue
|
v = rightValue
|
||||||
|
Loading…
Reference in New Issue
Block a user