Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5950630cf7 | |||
| 78e431f2b9 | |||
| c7dce8288f | |||
| c10053253c | |||
| a3c7cf2efa | |||
| dfa1491093 | |||
| 99c1adc434 | |||
| 5585b496fb | |||
| acd4f8487d |
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// function.go
|
// function.go
|
||||||
|
|||||||
+30
-24
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtin-base.go
|
// builtin-base.go
|
||||||
@@ -255,24 +255,31 @@ func setFunc(ctx kern.ExprContext, name string, args map[string]any) (result any
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// func unsetFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func charFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
// var varName string
|
var ord int
|
||||||
// var ok bool
|
|
||||||
|
|
||||||
// if varName, ok = args[kern.ParamName].(string); !ok {
|
if n, ok := args[kern.ParamValue].(byte); ok {
|
||||||
// return nil, kern.ErrWrongParamType(name, kern.ParamName, kern.TypeString, args[kern.ParamName])
|
ord = int(n)
|
||||||
// } else {
|
} else if n, ok := args[kern.ParamValue].(int64); ok {
|
||||||
// ctx.GetParent().DeleteVar(varName)
|
ord = int(n)
|
||||||
// result = nil
|
} else if n, ok := args[kern.ParamValue].(int); ok {
|
||||||
// }
|
ord = n
|
||||||
// return
|
} else {
|
||||||
// }
|
return nil, kern.ErrWrongParamType(name, kern.ParamName, kern.TypeString, args[kern.ParamName])
|
||||||
|
}
|
||||||
|
if ord < 0 || ord > 255 {
|
||||||
|
err = kern.ErrFuncInvalidArg(name, fmt.Sprintf("character code must be in range 0-255, got %d", ord))
|
||||||
|
} else {
|
||||||
|
result = string(rune(ord))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//// import
|
//// import
|
||||||
|
|
||||||
func ImportBuiltinsFuncs(ctx kern.ExprContext) {
|
func ImportBuiltinsFuncs(ctx kern.ExprContext) {
|
||||||
anyParams := []kern.ExprFuncParam{
|
anyParams := []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamValue),
|
kern.NewFuncParam(kern.ParamValue),
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.RegisterFunc("isNil", kern.NewGolangFunctor(isNilFunc), kern.TypeBoolean, anyParams)
|
ctx.RegisterFunc("isNil", kern.NewGolangFunctor(isNilFunc), kern.TypeBoolean, anyParams)
|
||||||
@@ -290,28 +297,27 @@ func ImportBuiltinsFuncs(ctx kern.ExprContext) {
|
|||||||
ctx.RegisterFunc("dec", kern.NewGolangFunctor(decFunc), kern.TypeFloat, anyParams)
|
ctx.RegisterFunc("dec", kern.NewGolangFunctor(decFunc), kern.TypeFloat, anyParams)
|
||||||
ctx.RegisterFunc("string", kern.NewGolangFunctor(stringFunc), kern.TypeString, anyParams)
|
ctx.RegisterFunc("string", kern.NewGolangFunctor(stringFunc), kern.TypeString, anyParams)
|
||||||
ctx.RegisterFunc("fract", kern.NewGolangFunctor(fractFunc), kern.TypeFraction, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fract", kern.NewGolangFunctor(fractFunc), kern.TypeFraction, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamValue),
|
kern.NewFuncParam(kern.ParamValue),
|
||||||
NewFuncParamFlagDef(ParamDenominator, PfDefault, int64(1)),
|
kern.NewFuncParamFlagDef(ParamDenominator, kern.PfDefault, int64(1)),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("eval", kern.NewGolangFunctor(evalFunc), kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc("eval", kern.NewGolangFunctor(evalFunc), kern.TypeAny, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSource),
|
kern.NewFuncParam(kern.ParamSource),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("var", kern.NewGolangFunctor(varFunc), kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc("var", kern.NewGolangFunctor(varFunc), kern.TypeAny, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamName),
|
kern.NewFuncParam(kern.ParamName),
|
||||||
NewFuncParamFlagDef(kern.ParamValue, PfDefault, nil),
|
kern.NewFuncParamFlagDef(kern.ParamValue, kern.PfDefault, nil),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("set", kern.NewGolangFunctor(setFunc), kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc("set", kern.NewGolangFunctor(setFunc), kern.TypeAny, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamName),
|
kern.NewFuncParam(kern.ParamName),
|
||||||
NewFuncParam(kern.ParamValue),
|
kern.NewFuncParam(kern.ParamValue),
|
||||||
})
|
})
|
||||||
|
|
||||||
// ctx.RegisterFunc("unset", kern.NewGolangFunctor(unsetFunc), kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc("char", kern.NewGolangFunctor(charFunc), kern.TypeString, []kern.ExprFuncParam{
|
||||||
// NewFuncParam(kern.ParamName),
|
kern.NewFuncParam(kern.ParamValue),
|
||||||
// NewFuncParam(kern.ParamValue),
|
})
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtin-fmt.go
|
// builtin-fmt.go
|
||||||
@@ -47,10 +47,10 @@ func printLnFunc(ctx kern.ExprContext, name string, args map[string]any) (result
|
|||||||
|
|
||||||
func ImportFmtFuncs(ctx kern.ExprContext) {
|
func ImportFmtFuncs(ctx kern.ExprContext) {
|
||||||
ctx.RegisterFunc("print", kern.NewGolangFunctor(printFunc), kern.TypeInt, []kern.ExprFuncParam{
|
ctx.RegisterFunc("print", kern.NewGolangFunctor(printFunc), kern.TypeInt, []kern.ExprFuncParam{
|
||||||
NewFuncParamFlag(kern.ParamItem, PfRepeat),
|
kern.NewFuncParamFlag(kern.ParamItem, kern.PfRepeat),
|
||||||
})
|
})
|
||||||
ctx.RegisterFunc("println", kern.NewGolangFunctor(printLnFunc), kern.TypeInt, []kern.ExprFuncParam{
|
ctx.RegisterFunc("println", kern.NewGolangFunctor(printLnFunc), kern.TypeInt, []kern.ExprFuncParam{
|
||||||
NewFuncParamFlag(kern.ParamItem, PfRepeat),
|
kern.NewFuncParamFlag(kern.ParamItem, kern.PfRepeat),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtin-import.go
|
// builtin-import.go
|
||||||
@@ -69,10 +69,10 @@ func doImport(ctx kern.ExprContext, name string, dirList []string, it kern.Itera
|
|||||||
|
|
||||||
func ImportImportFuncs(ctx kern.ExprContext) {
|
func ImportImportFuncs(ctx kern.ExprContext) {
|
||||||
ctx.RegisterFunc("import", kern.NewGolangFunctor(importFunc), kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc("import", kern.NewGolangFunctor(importFunc), kern.TypeAny, []kern.ExprFuncParam{
|
||||||
NewFuncParamFlag(kern.ParamFilepath, PfRepeat),
|
kern.NewFuncParamFlag(kern.ParamFilepath, kern.PfRepeat),
|
||||||
})
|
})
|
||||||
ctx.RegisterFunc("importAll", kern.NewGolangFunctor(importAllFunc), kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc("importAll", kern.NewGolangFunctor(importAllFunc), kern.TypeAny, []kern.ExprFuncParam{
|
||||||
NewFuncParamFlag(kern.ParamFilepath, PfRepeat),
|
kern.NewFuncParamFlag(kern.ParamFilepath, kern.PfRepeat),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtin-iterator.go
|
// builtin-iterator.go
|
||||||
@@ -94,9 +94,9 @@ func runFunc(ctx kern.ExprContext, name string, args map[string]any) (result any
|
|||||||
|
|
||||||
func ImportIterFuncs(ctx kern.ExprContext) {
|
func ImportIterFuncs(ctx kern.ExprContext) {
|
||||||
ctx.RegisterFunc("run", kern.NewGolangFunctor(runFunc), kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc("run", kern.NewGolangFunctor(runFunc), kern.TypeAny, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamIterator),
|
kern.NewFuncParam(kern.ParamIterator),
|
||||||
NewFuncParamFlag(iterParamOperator, PfOptional),
|
kern.NewFuncParamFlag(iterParamOperator, kern.PfOptional),
|
||||||
NewFuncParamFlag(iterParamVars, PfOptional),
|
kern.NewFuncParamFlag(iterParamVars, kern.PfOptional),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtin-math-arith.go
|
// builtin-math-arith.go
|
||||||
@@ -172,11 +172,11 @@ func mulFunc(ctx kern.ExprContext, name string, args map[string]any) (result any
|
|||||||
|
|
||||||
func ImportMathFuncs(ctx kern.ExprContext) {
|
func ImportMathFuncs(ctx kern.ExprContext) {
|
||||||
ctx.RegisterFunc("add", kern.NewGolangFunctor(addFunc), kern.TypeNumber, []kern.ExprFuncParam{
|
ctx.RegisterFunc("add", kern.NewGolangFunctor(addFunc), kern.TypeNumber, []kern.ExprFuncParam{
|
||||||
NewFuncParamFlagDef(kern.ParamValue, PfDefault|PfRepeat, int64(0)),
|
kern.NewFuncParamFlagDef(kern.ParamValue, kern.PfDefault|kern.PfRepeat, int64(0)),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("mul", kern.NewGolangFunctor(mulFunc), kern.TypeNumber, []kern.ExprFuncParam{
|
ctx.RegisterFunc("mul", kern.NewGolangFunctor(mulFunc), kern.TypeNumber, []kern.ExprFuncParam{
|
||||||
NewFuncParamFlagDef(kern.ParamValue, PfDefault|PfRepeat, int64(1)),
|
kern.NewFuncParamFlagDef(kern.ParamValue, kern.PfDefault|kern.PfRepeat, int64(1)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// builtin-os-file.go
|
||||||
|
package expr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.portale-stac.it/go-pkg/expr/file"
|
||||||
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
|
)
|
||||||
|
|
||||||
|
const fileByteIteratorType = "fileByteIterator"
|
||||||
|
|
||||||
|
type fileFileByteIterator struct {
|
||||||
|
fileIterBase
|
||||||
|
b byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFileByteIterator(r *file.Reader, autoClose bool) *fileFileByteIterator {
|
||||||
|
return &fileFileByteIterator{
|
||||||
|
fileIterBase: fileIterBase{reader: r, index: -1, count: 0, autoClose: autoClose},
|
||||||
|
b: 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileByteIterator) TypeName() string {
|
||||||
|
return fileByteIteratorType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileByteIterator) String() string {
|
||||||
|
return it.repr(fileByteIteratorType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileByteIterator) Next() (item any, err error) { // must return io.EOF after the last item
|
||||||
|
if it.b, err = it.reader.ReadByte(); err == nil {
|
||||||
|
it.increment()
|
||||||
|
item = it.b
|
||||||
|
} else if it.autoClose {
|
||||||
|
it.Clean()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileByteIterator) Current() (item any, err error) {
|
||||||
|
item = it.b
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileByteIterator) Reset() (err error) {
|
||||||
|
if err = it.reader.Reset(); err == nil {
|
||||||
|
it.reset()
|
||||||
|
it.b = 0
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileByteIterator) Clean() (err error) {
|
||||||
|
if it.reader.Valid() {
|
||||||
|
if err = it.reader.GetFile().Close(); err == nil {
|
||||||
|
it.reader = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it.reset()
|
||||||
|
it.b = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileByteIterator) CallOperation(name string, args map[string]any) (v any, err error) {
|
||||||
|
switch name {
|
||||||
|
case kern.NextName:
|
||||||
|
v, err = it.Next()
|
||||||
|
case kern.ResetName:
|
||||||
|
err = it.Reset()
|
||||||
|
case kern.CleanName:
|
||||||
|
err = it.Clean()
|
||||||
|
case kern.IndexName:
|
||||||
|
v = int64(it.Index())
|
||||||
|
case kern.CurrentName:
|
||||||
|
v, err = it.Current()
|
||||||
|
case kern.CountName:
|
||||||
|
v = it.count
|
||||||
|
default:
|
||||||
|
err = kern.ErrNoOperation(name)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func fileByteIteratorFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
|
var handle *file.Reader
|
||||||
|
var invalidFileHandle any
|
||||||
|
var autoClose bool
|
||||||
|
|
||||||
|
if handle, invalidFileHandle, autoClose, err = initFileHandle(ctx, name, args); err == nil {
|
||||||
|
if handle != nil {
|
||||||
|
result = newFileByteIterator(handle, autoClose)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil && (handle == nil || invalidFileHandle != nil) {
|
||||||
|
err = errInvalidFileHandle(name, invalidFileHandle)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// builtin-os-file.go
|
||||||
|
package expr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.portale-stac.it/go-pkg/expr/file"
|
||||||
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
|
)
|
||||||
|
|
||||||
|
const fileLineIteratorType = "fileLineIterator"
|
||||||
|
|
||||||
|
type fileFileLineIterator struct {
|
||||||
|
fileIterBase
|
||||||
|
line string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFileLineIterator(r *file.Reader, autoClose bool) *fileFileLineIterator {
|
||||||
|
return &fileFileLineIterator{
|
||||||
|
fileIterBase: fileIterBase{reader: r, index: -1, count: 0, autoClose: autoClose},
|
||||||
|
line: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileLineIterator) TypeName() string {
|
||||||
|
return fileLineIteratorType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileLineIterator) String() string {
|
||||||
|
return it.repr(fileLineIteratorType)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileLineIterator) Next() (item any, err error) { // must return io.EOF after the last item
|
||||||
|
if it.line, err = it.reader.ReadString('\n'); err == nil {
|
||||||
|
it.increment()
|
||||||
|
item = it.line[0 : len(it.line)-1]
|
||||||
|
} else if it.autoClose {
|
||||||
|
it.Clean()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileLineIterator) Current() (item any, err error) {
|
||||||
|
if len(it.line) > 0 {
|
||||||
|
item = it.line[0 : len(it.line)-1]
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileLineIterator) Reset() (err error) {
|
||||||
|
if err = it.reader.Reset(); err == nil {
|
||||||
|
it.reset()
|
||||||
|
it.line = ""
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileLineIterator) Clean() (err error) {
|
||||||
|
if it.reader != nil {
|
||||||
|
if err = it.reader.Close(); err == nil {
|
||||||
|
it.reader = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it.reset()
|
||||||
|
it.line = ""
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *fileFileLineIterator) CallOperation(name string, args map[string]any) (v any, err error) {
|
||||||
|
switch name {
|
||||||
|
case kern.NextName:
|
||||||
|
v, err = it.Next()
|
||||||
|
case kern.ResetName:
|
||||||
|
err = it.Reset()
|
||||||
|
case kern.CleanName:
|
||||||
|
err = it.Clean()
|
||||||
|
case kern.IndexName:
|
||||||
|
v = int64(it.Index())
|
||||||
|
case kern.CurrentName:
|
||||||
|
v, err = it.Current()
|
||||||
|
case kern.CountName:
|
||||||
|
v = it.count
|
||||||
|
default:
|
||||||
|
err = kern.ErrNoOperation(name)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func fileLineIteratorFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
|
var handle *file.Reader
|
||||||
|
var invalidFileHandle any
|
||||||
|
var autoClose bool
|
||||||
|
|
||||||
|
if handle, invalidFileHandle, autoClose, err = initFileHandle(ctx, name, args); err == nil {
|
||||||
|
if handle != nil {
|
||||||
|
result = newFileLineIterator(handle, autoClose)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil && (handle == nil || invalidFileHandle != nil) {
|
||||||
|
err = errInvalidFileHandle(name, invalidFileHandle)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
+24
-104
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtin-os-file.go
|
// builtin-os-file.go
|
||||||
@@ -6,146 +6,66 @@ package expr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
|
"git.portale-stac.it/go-pkg/expr/file"
|
||||||
"git.portale-stac.it/go-pkg/expr/kern"
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
)
|
)
|
||||||
|
|
||||||
const paramHandleOrPath = "handle-or-path"
|
const paramHandleOrPath = "handle-or-path"
|
||||||
const fileReadTextIteratorType = "fileReadTextIterator"
|
|
||||||
|
|
||||||
type fileReadTextIterator struct {
|
type fileIterBase struct {
|
||||||
osReader *osReader
|
reader *file.Reader
|
||||||
index int64
|
index int64
|
||||||
count int64
|
count int64
|
||||||
line string
|
|
||||||
autoClose bool
|
autoClose bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReadTextIterator(r *osReader, autoClose bool) *fileReadTextIterator {
|
func (it *fileIterBase) Count() int64 {
|
||||||
return &fileReadTextIterator{osReader: r, index: -1, autoClose: autoClose}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (it *fileReadTextIterator) TypeName() string {
|
|
||||||
return fileReadTextIteratorType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (it *fileReadTextIterator) String() string {
|
|
||||||
if it.osReader != nil && it.osReader.fh != nil {
|
|
||||||
return fmt.Sprintf("$(%s@%q)", fileReadTextIteratorType, it.osReader.fh.Name())
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("$(%s@<nil>)", fileReadTextIteratorType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (it *fileReadTextIterator) Count() int64 {
|
|
||||||
return it.count
|
return it.count
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *fileReadTextIterator) Next() (item any, err error) { // must return io.EOF after the last item
|
func (it *fileIterBase) Index() int64 {
|
||||||
if it.osReader.fh != nil {
|
|
||||||
if it.line, err = it.osReader.reader.ReadString('\n'); err == nil {
|
|
||||||
it.index++
|
|
||||||
it.count++
|
|
||||||
item = it.line[0 : len(it.line)-1]
|
|
||||||
} else if it.autoClose {
|
|
||||||
it.Clean()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (it *fileReadTextIterator) Current() (item any, err error) {
|
|
||||||
if len(it.line) > 0 {
|
|
||||||
item = it.line[0 : len(it.line)-1]
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (it *fileReadTextIterator) Index() int64 {
|
|
||||||
return it.index
|
return it.index
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *fileReadTextIterator) Reset() (err error) {
|
func (it *fileIterBase) HasOperation(name string) bool {
|
||||||
if _, err = it.osReader.fh.Seek(0, io.SeekStart); err == nil {
|
|
||||||
it.index = -1
|
|
||||||
it.count = 0
|
|
||||||
it.line = ""
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (it *fileReadTextIterator) HasOperation(name string) bool {
|
|
||||||
return slices.Contains([]string{kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName}, name)
|
return slices.Contains([]string{kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName}, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *fileReadTextIterator) Clean() (err error) {
|
func (it *fileIterBase) reset() {
|
||||||
if it.osReader.fh != nil {
|
it.index = -1
|
||||||
if err = it.osReader.fh.Close(); err == nil {
|
it.count = 0
|
||||||
it.osReader = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *fileReadTextIterator) CallOperation(name string, args map[string]any) (v any, err error) {
|
func (it *fileIterBase) increment() {
|
||||||
switch name {
|
it.index++
|
||||||
case kern.NextName:
|
it.count++
|
||||||
v, err = it.Next()
|
|
||||||
case kern.ResetName:
|
|
||||||
err = it.Reset()
|
|
||||||
case kern.CleanName:
|
|
||||||
err = it.Clean()
|
|
||||||
case kern.IndexName:
|
|
||||||
v = int64(it.Index())
|
|
||||||
case kern.CurrentName:
|
|
||||||
v, err = it.Current()
|
|
||||||
case kern.CountName:
|
|
||||||
v = it.count
|
|
||||||
default:
|
|
||||||
err = kern.ErrNoOperation(name)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileReadIteratorFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func (it *fileIterBase) repr(typeName string) string {
|
||||||
var handle *osReader
|
if it.reader.Valid() {
|
||||||
var invalidFileHandle any
|
return fmt.Sprintf("$(%s@%q)", typeName, it.reader.GetName())
|
||||||
var ok, autoClose bool
|
}
|
||||||
|
return fmt.Sprintf("$(%s@<nil>)", typeName)
|
||||||
|
}
|
||||||
|
|
||||||
result = nil
|
func initFileHandle(ctx kern.ExprContext, name string, args map[string]any) (handle *file.Reader, invalidFileHandle any, autoClose bool, err error) {
|
||||||
if handle, ok = args[paramHandleOrPath].(*osReader); !ok {
|
var ok bool
|
||||||
|
|
||||||
|
if handle, ok = args[paramHandleOrPath].(*file.Reader); !ok {
|
||||||
if fileName, ok := args[paramHandleOrPath].(string); ok && len(fileName) > 0 {
|
if fileName, ok := args[paramHandleOrPath].(string); ok && len(fileName) > 0 {
|
||||||
var handleAny any
|
var handleAny any
|
||||||
if handleAny, err = openFileFunc(ctx, name, map[string]any{kern.ParamFilepath: fileName}); err != nil {
|
if handleAny, err = openFileFunc(ctx, name, map[string]any{kern.ParamFilepath: fileName}); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if handleAny != nil {
|
if handleAny != nil {
|
||||||
handle = handleAny.(*osReader)
|
handle = handleAny.(*file.Reader)
|
||||||
autoClose = true
|
autoClose = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
invalidFileHandle = args[paramHandleOrPath]
|
invalidFileHandle = args[paramHandleOrPath]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if handle != nil {
|
|
||||||
result = newReadTextIterator(handle, autoClose)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if err == nil && (handle == nil || invalidFileHandle != nil) {
|
|
||||||
err = errInvalidFileHandle(name, invalidFileHandle)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// func ImportOsIterFuncs(ctx ExprContext) {
|
|
||||||
// ctx.RegisterFunc("fileReadIterator", NewGolangFunctor(fileReadIteratorFunc), TypeIterator, []ExprFuncParam{
|
|
||||||
// NewFuncParam(paramHandleOrPath),
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func init() {
|
|
||||||
// RegisterBuiltinModule("os.file", ImportOsIterFuncs, "Operating system file iterator functions")
|
|
||||||
// }
|
|
||||||
|
|||||||
+53
-83
@@ -1,15 +1,14 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtin-os-file.go
|
// builtin-os-file.go
|
||||||
package expr
|
package expr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
|
|
||||||
|
"git.portale-stac.it/go-pkg/expr/file"
|
||||||
"git.portale-stac.it/go-pkg/expr/kern"
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,44 +16,6 @@ const (
|
|||||||
osLimitCh = "limitCh"
|
osLimitCh = "limitCh"
|
||||||
)
|
)
|
||||||
|
|
||||||
type osHandle interface {
|
|
||||||
getFile() *os.File
|
|
||||||
}
|
|
||||||
|
|
||||||
type osWriter struct {
|
|
||||||
fh *os.File
|
|
||||||
writer *bufio.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *osWriter) TypeName() string {
|
|
||||||
return "osWriter"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *osWriter) String() string {
|
|
||||||
return "writer"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *osWriter) getFile() *os.File {
|
|
||||||
return h.fh
|
|
||||||
}
|
|
||||||
|
|
||||||
type osReader struct {
|
|
||||||
fh *os.File
|
|
||||||
reader *bufio.Reader
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *osReader) TypeName() string {
|
|
||||||
return "osReader"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *osReader) String() string {
|
|
||||||
return "reader"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *osReader) getFile() *os.File {
|
|
||||||
return h.fh
|
|
||||||
}
|
|
||||||
|
|
||||||
func errMissingFilePath(funcName string) error {
|
func errMissingFilePath(funcName string) error {
|
||||||
return fmt.Errorf("%s(): missing or invalid file path", funcName)
|
return fmt.Errorf("%s(): missing or invalid file path", funcName)
|
||||||
}
|
}
|
||||||
@@ -67,24 +28,26 @@ func errInvalidFileHandle(funcName string, v any) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFileFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func openFileFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
if filePath, ok := args[kern.ParamFilepath].(string); ok && len(filePath) > 0 {
|
if filePath, ok := args[kern.ParamFilepath].(string); ok && len(filePath) > 0 {
|
||||||
var fh *os.File
|
// var fh *os.File
|
||||||
if fh, err = os.Create(filePath); err == nil {
|
// if fh, err = os.Open(filePath); err == nil {
|
||||||
result = &osWriter{fh: fh, writer: bufio.NewWriter(fh)}
|
// result = file.NewReader(fh)
|
||||||
}
|
// }
|
||||||
|
result, err = file.OpenReader(filePath)
|
||||||
} else {
|
} else {
|
||||||
err = errMissingFilePath(name)
|
err = errMissingFilePath(name)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func openFileFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func createFileFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
if filePath, ok := args[kern.ParamFilepath].(string); ok && len(filePath) > 0 {
|
if filePath, ok := args[kern.ParamFilepath].(string); ok && len(filePath) > 0 {
|
||||||
var fh *os.File
|
// var fh *os.File
|
||||||
if fh, err = os.Open(filePath); err == nil {
|
// if fh, err = os.Create(filePath); err == nil {
|
||||||
result = &osReader{fh: fh, reader: bufio.NewReader(fh)}
|
// result = file.NewWriter(fh)
|
||||||
}
|
// }
|
||||||
|
result, err = file.CreateWriter(filePath)
|
||||||
} else {
|
} else {
|
||||||
err = errMissingFilePath(name)
|
err = errMissingFilePath(name)
|
||||||
}
|
}
|
||||||
@@ -93,10 +56,11 @@ func openFileFunc(ctx kern.ExprContext, name string, args map[string]any) (resul
|
|||||||
|
|
||||||
func appendFileFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func appendFileFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
if filePath, ok := args[kern.ParamFilepath].(string); ok && len(filePath) > 0 {
|
if filePath, ok := args[kern.ParamFilepath].(string); ok && len(filePath) > 0 {
|
||||||
var fh *os.File
|
// var fh *os.File
|
||||||
if fh, err = os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0660); err == nil {
|
// if fh, err = os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0660); err == nil {
|
||||||
result = &osWriter{fh: fh, writer: bufio.NewWriter(fh)}
|
// result = file.NewWriter(fh)
|
||||||
}
|
// }
|
||||||
|
result, err = file.AppendWriter(filePath)
|
||||||
} else {
|
} else {
|
||||||
err = errMissingFilePath(name)
|
err = errMissingFilePath(name)
|
||||||
}
|
}
|
||||||
@@ -104,18 +68,18 @@ func appendFileFunc(ctx kern.ExprContext, name string, args map[string]any) (res
|
|||||||
}
|
}
|
||||||
|
|
||||||
func closeFileFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func closeFileFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
var handle osHandle
|
var handle file.Handle
|
||||||
var invalidFileHandle any
|
var invalidFileHandle any
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if handle, ok = args[kern.ParamHandle].(osHandle); !ok {
|
if handle, ok = args[kern.ParamHandle].(file.Handle); !ok {
|
||||||
invalidFileHandle = args[kern.ParamHandle]
|
invalidFileHandle = args[kern.ParamHandle]
|
||||||
}
|
}
|
||||||
|
|
||||||
if handle != nil {
|
if handle != nil {
|
||||||
if fh := handle.getFile(); fh != nil {
|
if fh := handle.GetFile(); fh != nil {
|
||||||
if w, ok := handle.(*osWriter); ok {
|
if w, ok := handle.(*file.Writer); ok {
|
||||||
err = w.writer.Flush()
|
err = w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -131,19 +95,20 @@ func closeFileFunc(ctx kern.ExprContext, name string, args map[string]any) (resu
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fileWriteTextFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func fileWriteTextFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
var handle osHandle
|
var handle file.Handle
|
||||||
var invalidFileHandle any
|
var invalidFileHandle any
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if handle, ok = args[kern.ParamHandle].(osHandle); !ok {
|
if handle, ok = args[kern.ParamHandle].(file.Handle); !ok {
|
||||||
invalidFileHandle = args[kern.ParamHandle]
|
invalidFileHandle = args[kern.ParamHandle]
|
||||||
}
|
}
|
||||||
|
|
||||||
if handle != nil {
|
if handle != nil {
|
||||||
if w, ok := handle.(*osWriter); ok {
|
if w, ok := handle.(*file.Writer); ok {
|
||||||
if v, exists := args[kern.ParamItem]; exists {
|
if v, exists := args[kern.ParamItem]; exists {
|
||||||
argv := v.([]any)
|
argv := v.([]any)
|
||||||
result, err = fmt.Fprint(w.writer, argv...)
|
// result, err = fmt.Fprint(w.writer, argv...)
|
||||||
|
result, err = w.Write(argv...)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
invalidFileHandle = handle
|
invalidFileHandle = handle
|
||||||
@@ -157,24 +122,24 @@ func fileWriteTextFunc(ctx kern.ExprContext, name string, args map[string]any) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fileReadTextFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func fileReadTextFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
var handle osHandle
|
var handle file.Handle
|
||||||
var invalidFileHandle any
|
var invalidFileHandle any
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
result = nil
|
result = nil
|
||||||
if handle, ok = args[kern.ParamHandle].(osHandle); !ok || args[kern.ParamHandle] == nil {
|
if handle, ok = args[kern.ParamHandle].(file.Handle); !ok || args[kern.ParamHandle] == nil {
|
||||||
invalidFileHandle = args[kern.ParamHandle]
|
invalidFileHandle = args[kern.ParamHandle]
|
||||||
}
|
}
|
||||||
|
|
||||||
if handle != nil {
|
if handle != nil {
|
||||||
if r, ok := handle.(*osReader); ok {
|
if r, ok := handle.(*file.Reader); ok {
|
||||||
var limit byte = '\n'
|
var limit byte = '\n'
|
||||||
var v string
|
var v string
|
||||||
if s, ok := args[osLimitCh].(string); ok && len(s) > 0 {
|
if s, ok := args[osLimitCh].(string); ok && len(s) > 0 {
|
||||||
limit = s[0]
|
limit = s[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
v, err = r.reader.ReadString(limit)
|
v, err = r.ReadString(limit)
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
@@ -197,19 +162,19 @@ func fileReadTextFunc(ctx kern.ExprContext, name string, args map[string]any) (r
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fileReadTextAllFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
func fileReadTextAllFunc(ctx kern.ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
var handle osHandle
|
var handle file.Handle
|
||||||
var invalidFileHandle any
|
var invalidFileHandle any
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
result = nil
|
result = nil
|
||||||
if handle, ok = args[kern.ParamHandle].(osHandle); !ok || args[kern.ParamHandle] == nil {
|
if handle, ok = args[kern.ParamHandle].(file.Handle); !ok || args[kern.ParamHandle] == nil {
|
||||||
invalidFileHandle = args[kern.ParamHandle]
|
invalidFileHandle = args[kern.ParamHandle]
|
||||||
}
|
}
|
||||||
|
|
||||||
if handle != nil {
|
if handle != nil {
|
||||||
if r, ok := handle.(*osReader); ok {
|
if r, ok := handle.(*file.Reader); ok {
|
||||||
var b []byte
|
var b []byte
|
||||||
b, err = io.ReadAll(r.reader)
|
b, err = r.ReadAll()
|
||||||
result = string(b)
|
result = string(b)
|
||||||
} else {
|
} else {
|
||||||
invalidFileHandle = handle
|
invalidFileHandle = handle
|
||||||
@@ -224,38 +189,43 @@ func fileReadTextAllFunc(ctx kern.ExprContext, name string, args map[string]any)
|
|||||||
|
|
||||||
func ImportOsFuncs(ctx kern.ExprContext) {
|
func ImportOsFuncs(ctx kern.ExprContext) {
|
||||||
ctx.RegisterFunc("fileOpen", kern.NewGolangFunctor(openFileFunc), kern.TypeFileHandle, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fileOpen", kern.NewGolangFunctor(openFileFunc), kern.TypeFileHandle, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamFilepath),
|
kern.NewFuncParam(kern.ParamFilepath),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("fileAppend", kern.NewGolangFunctor(appendFileFunc), kern.TypeFileHandle, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fileAppend", kern.NewGolangFunctor(appendFileFunc), kern.TypeFileHandle, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamFilepath),
|
kern.NewFuncParam(kern.ParamFilepath),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("fileCreate", kern.NewGolangFunctor(createFileFunc), kern.TypeFileHandle, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fileCreate", kern.NewGolangFunctor(createFileFunc), kern.TypeFileHandle, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamFilepath),
|
kern.NewFuncParam(kern.ParamFilepath),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("fileClose", kern.NewGolangFunctor(closeFileFunc), kern.TypeBoolean, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fileClose", kern.NewGolangFunctor(closeFileFunc), kern.TypeBoolean, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamHandle),
|
kern.NewFuncParam(kern.ParamHandle),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("fileWriteText", kern.NewGolangFunctor(fileWriteTextFunc), kern.TypeInt, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fileWriteText", kern.NewGolangFunctor(fileWriteTextFunc), kern.TypeInt, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamHandle),
|
kern.NewFuncParam(kern.ParamHandle),
|
||||||
NewFuncParamFlagDef(kern.ParamItem, PfDefault|PfRepeat, ""),
|
kern.NewFuncParamFlagDef(kern.ParamItem, kern.PfDefault|kern.PfRepeat, ""),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("fileReadText", kern.NewGolangFunctor(fileReadTextFunc), kern.TypeString, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fileReadText", kern.NewGolangFunctor(fileReadTextFunc), kern.TypeString, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamHandle),
|
kern.NewFuncParam(kern.ParamHandle),
|
||||||
NewFuncParamFlagDef(osLimitCh, PfDefault, "\n"),
|
kern.NewFuncParamFlagDef(osLimitCh, kern.PfDefault, "\n"),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("fileReadTextAll", kern.NewGolangFunctor(fileReadTextAllFunc), kern.TypeString, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fileReadTextAll", kern.NewGolangFunctor(fileReadTextAllFunc), kern.TypeString, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamHandle),
|
kern.NewFuncParam(kern.ParamHandle),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("fileReadIterator", kern.NewGolangFunctor(fileReadIteratorFunc), kern.TypeIterator, []kern.ExprFuncParam{
|
ctx.RegisterFunc("fileLineIterator", kern.NewGolangFunctor(fileLineIteratorFunc), kern.TypeIterator, []kern.ExprFuncParam{
|
||||||
NewFuncParam(paramHandleOrPath),
|
kern.NewFuncParam(paramHandleOrPath),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ctx.RegisterFunc("fileByteIterator", kern.NewGolangFunctor(fileByteIteratorFunc), kern.TypeIterator, []kern.ExprFuncParam{
|
||||||
|
kern.NewFuncParam(paramHandleOrPath),
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
+18
-18
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtin-string.go
|
// builtin-string.go
|
||||||
@@ -225,44 +225,44 @@ func lowerStrFunc(ctx kern.ExprContext, name string, args map[string]any) (resul
|
|||||||
// Import above functions in the context
|
// Import above functions in the context
|
||||||
func ImportStringFuncs(ctx kern.ExprContext) {
|
func ImportStringFuncs(ctx kern.ExprContext) {
|
||||||
ctx.RegisterFunc("strJoin", kern.NewGolangFunctor(joinStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
ctx.RegisterFunc("strJoin", kern.NewGolangFunctor(joinStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSeparator),
|
kern.NewFuncParam(kern.ParamSeparator),
|
||||||
NewFuncParamFlag(kern.ParamItem, PfRepeat),
|
kern.NewFuncParamFlag(kern.ParamItem, kern.PfRepeat),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("strSub", kern.NewGolangFunctor(subStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
ctx.RegisterFunc("strSub", kern.NewGolangFunctor(subStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSource),
|
kern.NewFuncParam(kern.ParamSource),
|
||||||
NewFuncParamFlagDef(kern.ParamStart, PfDefault, int64(0)),
|
kern.NewFuncParamFlagDef(kern.ParamStart, kern.PfDefault, int64(0)),
|
||||||
NewFuncParamFlagDef(kern.ParamCount, PfDefault, int64(-1)),
|
kern.NewFuncParamFlagDef(kern.ParamCount, kern.PfDefault, int64(-1)),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("strSplit", kern.NewGolangFunctor(splitStrFunc), "list of "+kern.TypeString, []kern.ExprFuncParam{
|
ctx.RegisterFunc("strSplit", kern.NewGolangFunctor(splitStrFunc), "list of "+kern.TypeString, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSource),
|
kern.NewFuncParam(kern.ParamSource),
|
||||||
NewFuncParamFlagDef(kern.ParamSeparator, PfDefault, ""),
|
kern.NewFuncParamFlagDef(kern.ParamSeparator, kern.PfDefault, ""),
|
||||||
NewFuncParamFlagDef(kern.ParamCount, PfDefault, int64(-1)),
|
kern.NewFuncParamFlagDef(kern.ParamCount, kern.PfDefault, int64(-1)),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("strTrim", kern.NewGolangFunctor(trimStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
ctx.RegisterFunc("strTrim", kern.NewGolangFunctor(trimStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSource),
|
kern.NewFuncParam(kern.ParamSource),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("strStartsWith", kern.NewGolangFunctor(startsWithStrFunc), kern.TypeBoolean, []kern.ExprFuncParam{
|
ctx.RegisterFunc("strStartsWith", kern.NewGolangFunctor(startsWithStrFunc), kern.TypeBoolean, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSource),
|
kern.NewFuncParam(kern.ParamSource),
|
||||||
NewFuncParam(kern.ParamPrefix),
|
kern.NewFuncParam(kern.ParamPrefix),
|
||||||
NewFuncParamFlag(strParamOther, PfRepeat),
|
kern.NewFuncParamFlag(strParamOther, kern.PfRepeat),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("strEndsWith", kern.NewGolangFunctor(endsWithStrFunc), kern.TypeBoolean, []kern.ExprFuncParam{
|
ctx.RegisterFunc("strEndsWith", kern.NewGolangFunctor(endsWithStrFunc), kern.TypeBoolean, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSource),
|
kern.NewFuncParam(kern.ParamSource),
|
||||||
NewFuncParam(kern.ParamSuffix),
|
kern.NewFuncParam(kern.ParamSuffix),
|
||||||
NewFuncParamFlag(strParamOther, PfRepeat),
|
kern.NewFuncParamFlag(strParamOther, kern.PfRepeat),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("strUpper", kern.NewGolangFunctor(upperStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
ctx.RegisterFunc("strUpper", kern.NewGolangFunctor(upperStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSource),
|
kern.NewFuncParam(kern.ParamSource),
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.RegisterFunc("strLower", kern.NewGolangFunctor(lowerStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
ctx.RegisterFunc("strLower", kern.NewGolangFunctor(lowerStrFunc), kern.TypeString, []kern.ExprFuncParam{
|
||||||
NewFuncParam(kern.ParamSource),
|
kern.NewFuncParam(kern.ParamSource),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// builtins-register.go
|
// builtins-register.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// data-cursors.go
|
// data-cursors.go
|
||||||
|
|||||||
+6
-4
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// dict-iterator.go
|
// dict-iterator.go
|
||||||
@@ -116,8 +116,11 @@ func NewDictIterator(dict *kern.DictType, args []any) (it *DictIterator, err err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dictIt.makeKeys(*dict, sortType)
|
if err == nil {
|
||||||
return dictIt, err
|
dictIt.makeKeys(*dict, sortType)
|
||||||
|
it = dictIt
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMapIterator(m map[any]any) (it *DictIterator) {
|
func NewMapIterator(m map[any]any) (it *DictIterator) {
|
||||||
@@ -139,7 +142,6 @@ func (it *DictIterator) TypeName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (it *DictIterator) HasOperation(name string) bool {
|
func (it *DictIterator) HasOperation(name string) bool {
|
||||||
// yes := name == NextName || name == ResetName || name == IndexName || name == CountName || name == CurrentName
|
|
||||||
yes := slices.Contains([]string{kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName, kern.KeyName, kern.ValueName}, name)
|
yes := slices.Contains([]string{kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName, kern.KeyName, kern.ValueName}, name)
|
||||||
return yes
|
return yes
|
||||||
}
|
}
|
||||||
|
|||||||
+87
-38
@@ -34,7 +34,7 @@ Expressions calculator
|
|||||||
|
|
||||||
toc::[]
|
toc::[]
|
||||||
|
|
||||||
#TODO: Work in progress (last update on 2026/04/21, 6:49 p.m.)#
|
#TODO: Work in progress (last update on 2026/05/08)#
|
||||||
|
|
||||||
== Expr
|
== Expr
|
||||||
_Expr_ is a GO package that can analyze, interpret and calculate expressions.
|
_Expr_ is a GO package that can analyze, interpret and calculate expressions.
|
||||||
@@ -698,9 +698,9 @@ The value on the left side of [blue]`=` must be a variable identifier or an expr
|
|||||||
=== Selector operator [blue]`? : ::`
|
=== Selector operator [blue]`? : ::`
|
||||||
The _selector operator_ is very similar to the _switch/case/default_ statement available in many programming languages.
|
The _selector operator_ is very similar to the _switch/case/default_ statement available in many programming languages.
|
||||||
|
|
||||||
.Selector literal Syntax
|
.Selector literal syntax
|
||||||
====
|
====
|
||||||
_selector-operator_ = _select-expression_ "*?*" _selector-case_ { "*:*" _selector-case_ } ["*::*" _default-multi-expression_] +
|
*_selector-operator_* = _select-expression_ "*?*" _selector-case_ { "*:*" _selector-case_ } ["*::*" _default-multi-expression_] +
|
||||||
_selector-case_ = [_match-list_] _case-value_ +
|
_selector-case_ = [_match-list_] _case-value_ +
|
||||||
_match-list_ = "*[*" _item_ {"*,*" _items_} "*]*" +
|
_match-list_ = "*[*" _item_ {"*,*" _items_} "*]*" +
|
||||||
_item_ = _expression_ +
|
_item_ = _expression_ +
|
||||||
@@ -737,19 +737,38 @@ The [blue]`:` symbol (colon) is the separator of the selector-cases. Note that i
|
|||||||
`>>>` [blue]`10 ? {"a"} : {"b"}` +
|
`>>>` [blue]`10 ? {"a"} : {"b"}` +
|
||||||
[red]`Eval Error: [1:3] no case catches the value (10) of the selection expression`
|
[red]`Eval Error: [1:3] no case catches the value (10) of the selection expression`
|
||||||
|
|
||||||
|
==== Triple special case of the selector operator
|
||||||
|
If the _select-expression_ is a boolean expression, the selector operator can be used as a sort of _if-then-else_ statement. In this case, the first case is evaluated if the _select-expression_ is true, and the second case is evaluated if the _select-expression_ is false. In this special case, the _match-list_ of both cases must be empty.
|
||||||
|
|
||||||
|
.Example
|
||||||
|
`>>>` [blue]`(true) ? {"T"}: {"F"}` +
|
||||||
|
[green]`T` +
|
||||||
|
`>>>` [blue]`(2 > 1) ? {"a"} : {"b"}` +
|
||||||
|
[green]`a` +
|
||||||
|
`>>>` [blue]`(2 < 1) ? {"a"} : {"b"}` +
|
||||||
|
[green]`b`
|
||||||
|
|
||||||
|
[WARNING]
|
||||||
|
====
|
||||||
|
The triple special case of the selector operator is very useful, but it only works with boolean expressions.
|
||||||
|
|
||||||
|
.Example of confusion
|
||||||
|
`>>>` [blue]`int(true) ? {"T"}: {"F"}` +
|
||||||
|
[green]`F`
|
||||||
|
====
|
||||||
|
|
||||||
=== Variable default value [blue]`??`, [blue]`?=`, and [blue]`?!`
|
=== Variable default value [blue]`??`, [blue]`?=`, and [blue]`?!`
|
||||||
The left operand of the first two operators, [blue]`??` and [blue]`?=`, must be a variable. The right operator can be any expression. They return the value of the variable if this is defined; otherwise they return the value of the right expression.
|
The left operand of the first two operators, [blue]`??` and [blue]`?=`, must be a variable. The right operatand can be any expression. They return the value of the variable if this is defined; otherwise they return the value of the right expression.
|
||||||
|
|
||||||
IMPORTANT: If the left variable is defined, the right expression is not evaluated at all.
|
IMPORTANT: If the left variable is defined, the right expression is not evaluated at all.
|
||||||
|
|
||||||
The [blue]`??` operator do not change the status of the left variable.
|
The [blue]`??` operator do not change the status of the left variable.
|
||||||
|
|
||||||
The [blue]`?=` assigns the calculated value of the right expression to the left variable.
|
The [blue]`?=` assigns the calculated value of the right expression to the variable on the left side.
|
||||||
|
|
||||||
The third one, [blue]`?!`, is the alternate operator. If the variable on the left size is not defined, it returns [blue]_nil_. Otherwise it returns the result of the expressione on the right side.
|
The third one, [blue]`?!`, is the alternate operator. If the variable on the left size is not defined, it returns [blue]_nil_. Otherwise it returns the result of the expressione on the right side.
|
||||||
|
|
||||||
IMPORTANT: If the left variable is NOT defined, the right expression is not evaluated at all.
|
IMPORTANT: If the variable [blue]`?!` is NOT defined, the expression is not evaluated at all.
|
||||||
|
|
||||||
.Examples
|
.Examples
|
||||||
`>>>` [blue]`var ?? (1+2)` +
|
`>>>` [blue]`var ?? (1+2)` +
|
||||||
@@ -836,8 +855,14 @@ The table below shows all supported operators by decreasing priorities.
|
|||||||
.2+|*INSERT*| [blue]`+>` | _Infix_ | _Prepend_ | _any_ `+>` _list_ -> _list_
|
.2+|*INSERT*| [blue]`+>` | _Infix_ | _Prepend_ | _any_ `+>` _list_ -> _list_
|
||||||
| [blue]`<+` | _Infix_ | _Append_ | _list_ `<+` _any_ -> _list_
|
| [blue]`<+` | _Infix_ | _Append_ | _list_ `<+` _any_ -> _list_
|
||||||
.2+|*ASSIGN*| [blue]`=` | _Infix_ | _Assignment_ | _identifier_ `=` _any_ -> _any_
|
.2+|*ASSIGN*| [blue]`=` | _Infix_ | _Assignment_ | _identifier_ `=` _any_ -> _any_
|
||||||
4+| _See also the table of special allocation operators below_
|
4+| _See also the table of special assignment operators below_
|
||||||
.1+|*BUT*| [blue]`but` | _Infix_ | _But_ | _any_ `but` _any_ -> _any_
|
.1+|*BUT*| [blue]`but` | _Infix_ | _But_ | _any_ `but` _any_ -> _any_
|
||||||
|
.6+|*ITER-OP*| [blue]`digest` | _Infix_ | _Item-digesting_ | _iterable_ `digest` _expr_ -> _any_
|
||||||
|
| [blue]`filter` | _Infix_ | _Item-filtering_ | _iterable_ `filter` _expr_ -> _list_
|
||||||
|
| [blue]`groupby` | _Infix_ | _Dict-grouping_ | _iterable_ `groupby` _key-expr_ -> _dict_
|
||||||
|
| [blue]`join` | _Infix_ | _Item-joining_ | _iterable_ `join` _iterable_ -> _list_
|
||||||
|
| [blue]`map` | _Infix_ | _Item-mapping_ | _iterable_ `map` _-expr_ -> _list_
|
||||||
|
4+| _See iterators section for examples_
|
||||||
.1+|*RANGE*| [blue]`:` | _Infix_ | _Index-range_ | _integer_ `:` _integer_ -> _integer-pair_
|
.1+|*RANGE*| [blue]`:` | _Infix_ | _Index-range_ | _integer_ `:` _integer_ -> _integer-pair_
|
||||||
|===
|
|===
|
||||||
|
|
||||||
@@ -921,12 +946,12 @@ _param-name_ = _identifier_
|
|||||||
[green]`fib(n):any{}`
|
[green]`fib(n):any{}`
|
||||||
|
|
||||||
`>>>` [gray]_// Required and optional parameters_ +
|
`>>>` [gray]_// Required and optional parameters_ +
|
||||||
`>>>` [blue]`measure = func(value, unit="meter"){ value + " " + unit + (value > 1) ? [true] {"s"} :: {""}}` +
|
`>>>` [blue]`measure = func(value, unit="meter"){ value + " " + unit + (value > 1) ? {"s"} :: {""}}` +
|
||||||
[green]`measure(value, unit="meter"):any{}`
|
[green]`measure(value, unit="meter"):any{}`
|
||||||
|
|
||||||
|
|
||||||
=== _Golang_ function definition
|
=== _Golang_ function definition
|
||||||
Description of how to define Golang functions and how to bind them to _Expr_ are topics covered in another document that I'll write, one day, maybe.
|
Description of how to define Golang functions and how to bind them to _Expr_ are topics covered in another documents that I'll write, one day, maybe.
|
||||||
|
|
||||||
=== Function calls
|
=== Function calls
|
||||||
To call a function, either Expr or Golang type, it is necessary to specify its name and, at least, its required parameters.
|
To call a function, either Expr or Golang type, it is necessary to specify its name and, at least, its required parameters.
|
||||||
@@ -1010,7 +1035,7 @@ Clone variables are normal local variables. The only diffence will appear when t
|
|||||||
.Example
|
.Example
|
||||||
`>>>` [blue]`f = func() { @x = 3; x = 5 }` [gray]_// f() declares two *different* local variables: ``@x`` and ``x``_ +
|
`>>>` [blue]`f = func() { @x = 3; x = 5 }` [gray]_// f() declares two *different* local variables: ``@x`` and ``x``_ +
|
||||||
[green]`f():any{}` +
|
[green]`f():any{}` +
|
||||||
`>>>` [blue]`f()` [gray]_// The multi-expression (two) in f() is calculated and the last result is returned_ +
|
`>>>` [blue]`f()` [gray]_// The multi-expression (two expressions) in f() is calculated and the last result is returned_ +
|
||||||
[green]`5` +
|
[green]`5` +
|
||||||
`>>>` [blue]`x` [gray]_// The `x` variable was not defined in the main context before the f() invocation. It appears in the main context by cloning the `@x` variable, local to f() after its termnation._ +
|
`>>>` [blue]`x` [gray]_// The `x` variable was not defined in the main context before the f() invocation. It appears in the main context by cloning the `@x` variable, local to f() after its termnation._ +
|
||||||
[green]`3`
|
[green]`3`
|
||||||
@@ -1048,7 +1073,7 @@ Builtins activation is done by using the [blue]`BUILTIN` operator. All modules e
|
|||||||
|
|
||||||
.Builtin activation syntax
|
.Builtin activation syntax
|
||||||
====
|
====
|
||||||
*_builtin-activation_* = [blue]`BUILTIN` (_builtin-name_ | _list-of-builtin-names_) +
|
*_builtin-activation_* = [blue]`BUILTIN` (_builtin-name_ | _list-of-builtin-names_ | **"*"**) +
|
||||||
_builtin-name_ = _string_ +
|
_builtin-name_ = _string_ +
|
||||||
_list-of-builtin-names_ = **[** _string_ { "**,**" _string_ } **]**
|
_list-of-builtin-names_ = **[** _string_ { "**,**" _string_ } **]**
|
||||||
====
|
====
|
||||||
@@ -1086,9 +1111,9 @@ The "base" builtin module provides functions for type checking and type conversi
|
|||||||
* <<_fract,fract()>>
|
* <<_fract,fract()>>
|
||||||
|
|
||||||
.Other functions
|
.Other functions
|
||||||
|
* <<_char,char()>>
|
||||||
* <<_eval,eval()>>
|
* <<_eval,eval()>>
|
||||||
* <<_set,set()>>
|
* <<_set,set()>>
|
||||||
* <<_unset,unset()>>
|
|
||||||
* <<_var,var()>>
|
* <<_var,var()>>
|
||||||
|
|
||||||
|
|
||||||
@@ -1100,7 +1125,9 @@ Returns _true_ if the value type of _<expr>_ is boolean, false otherwise.
|
|||||||
`>>>` [blue]`isBool(true)` +
|
`>>>` [blue]`isBool(true)` +
|
||||||
[green]`true` +
|
[green]`true` +
|
||||||
`>>>` [blue]`isBool(3==2)` +
|
`>>>` [blue]`isBool(3==2)` +
|
||||||
[green]`true`
|
[green]`true` +
|
||||||
|
`>>>` [blue]`isBool(3 + 2)` +
|
||||||
|
[green]`false`
|
||||||
|
|
||||||
===== isDict()
|
===== isDict()
|
||||||
Syntax: `isDict(<expr>) -> bool` +
|
Syntax: `isDict(<expr>) -> bool` +
|
||||||
@@ -1178,7 +1205,7 @@ Returns _true_ if the value type of _<expr>_ is fraction or int, false otherwise
|
|||||||
|
|
||||||
===== isString()
|
===== isString()
|
||||||
Syntax: `isString(<expr>) -> bool` +
|
Syntax: `isString(<expr>) -> bool` +
|
||||||
Returns a boolean value , false otherwise.
|
Returns _true_ if the value type of _<expr>_ is string, false otherwise.
|
||||||
|
|
||||||
.Examples
|
.Examples
|
||||||
`>>>` [blue]`isString("ciao")` +
|
`>>>` [blue]`isString("ciao")` +
|
||||||
@@ -1190,7 +1217,7 @@ Returns a boolean value , false otherwise.
|
|||||||
|
|
||||||
===== bool()
|
===== bool()
|
||||||
Syntax: `bool(<expr>) -> bool` +
|
Syntax: `bool(<expr>) -> bool` +
|
||||||
Returns a _boolean_ value consisent to the value of the expression.
|
Returns a _boolean_ value consisent with the value of the expression.
|
||||||
|
|
||||||
.Examples
|
.Examples
|
||||||
`>>>` [blue]`bool(1)` +
|
`>>>` [blue]`bool(1)` +
|
||||||
@@ -1295,6 +1322,16 @@ Returns a _fraction_ value consistent with the value of the expression.
|
|||||||
`>>>` [blue]`fract(true)` +
|
`>>>` [blue]`fract(true)` +
|
||||||
[green]`1:1`
|
[green]`1:1`
|
||||||
|
|
||||||
|
===== char()
|
||||||
|
Syntax: `char(<intexpr>) -> string` +
|
||||||
|
Returns the character whose ASCII (soon Unicode too) code point is specified by the integer expression.
|
||||||
|
|
||||||
|
.Examples
|
||||||
|
`>>>` [blue]`char(65)` +
|
||||||
|
[green]`"A"` +
|
||||||
|
`>>>` [blue]`char(97)` +
|
||||||
|
[green]`"a"`
|
||||||
|
|
||||||
===== eval()
|
===== eval()
|
||||||
Syntax: `eval(<string-expr>) -> any` +
|
Syntax: `eval(<string-expr>) -> any` +
|
||||||
Computes and returns the value of the [.underline]#string# expression.
|
Computes and returns the value of the [.underline]#string# expression.
|
||||||
@@ -1308,12 +1345,12 @@ Syntax: +
|
|||||||
`{4sp}var(<string-expr>, <expr>) -> any` +
|
`{4sp}var(<string-expr>, <expr>) -> any` +
|
||||||
`{4sp}var(<string-expr>) -> any`
|
`{4sp}var(<string-expr>) -> any`
|
||||||
|
|
||||||
This function allows you to define variables whose names must include special characters. The first form of the function allows you to define a variable with a name specified by the first parameter and assign it the value of the second parameter. The second form only returns the value of the variable with the specified name.
|
This function allows you to define variables whose names can include special characters. The first form of the function allows you to define a variable with a name specified by the first parameter and assign it the value of the second parameter. The second form only returns the value of the variable with the specified name.
|
||||||
|
|
||||||
.Examples
|
.Examples
|
||||||
`>>>` [blue]`var("$x", 3+9)` +
|
`>>>` [blue]`var("$x", 3+9)` +
|
||||||
[green]`12` +
|
[green]`12` +
|
||||||
`>>>` [blue]`var("$x")` +
|
`>>>` [blue]`var("$"+"x")` +
|
||||||
[green]`12` +
|
[green]`12` +
|
||||||
`>>>` [blue]`var("gain%", var("$x"))` +
|
`>>>` [blue]`var("gain%", var("$x"))` +
|
||||||
[green]`12` +
|
[green]`12` +
|
||||||
@@ -1334,26 +1371,17 @@ It is equivalent to the first form of the var() function, but it is more explici
|
|||||||
`>>>` [blue]`var("$x")` +
|
`>>>` [blue]`var("$x")` +
|
||||||
[green]`100` +
|
[green]`100` +
|
||||||
|
|
||||||
===== unset()
|
|
||||||
Syntax: +
|
|
||||||
`{4sp}unset(<string-expr>) -> any`
|
|
||||||
|
|
||||||
This function allows you to unset a variable whose name can include special characters. The parameter is the name of the variable to unset.
|
|
||||||
|
|
||||||
.Examples
|
|
||||||
`>>>` [blue]`unset("$x")` +
|
|
||||||
[green]`nil` +
|
|
||||||
`>>>` [blue]`var("$x")` +
|
|
||||||
[red]`Eval Error: var(): unknown variable "$x"`
|
|
||||||
|
|
||||||
==== Module "fmt"
|
==== Module "fmt"
|
||||||
|
#to-do#
|
||||||
|
|
||||||
===== print()
|
===== print()
|
||||||
|
|
||||||
===== println()
|
===== println()
|
||||||
|
|
||||||
==== Module "import"
|
==== Module "import"
|
||||||
Module actiovation: +
|
Module activation: +
|
||||||
|
`{4sp}BUILTIN "import"`
|
||||||
|
|
||||||
===== _import()_
|
===== _import()_
|
||||||
Syntax: +
|
Syntax: +
|
||||||
@@ -1364,6 +1392,8 @@ Loads the multi-expression contained in the specified source and returns its val
|
|||||||
===== _importAll()_
|
===== _importAll()_
|
||||||
|
|
||||||
==== Module "iterator"
|
==== Module "iterator"
|
||||||
|
Module activation: +
|
||||||
|
`{4sp}BUILTIN "iterator"`
|
||||||
|
|
||||||
===== run()
|
===== run()
|
||||||
Syntax: +
|
Syntax: +
|
||||||
@@ -1372,6 +1402,9 @@ Syntax: +
|
|||||||
Iterates over the specified iterator and applies the specified operator to the current value of the iterator.
|
Iterates over the specified iterator and applies the specified operator to the current value of the iterator.
|
||||||
|
|
||||||
==== Module "math.arith"
|
==== Module "math.arith"
|
||||||
|
Module activation: +
|
||||||
|
`{4sp}BUILTIN "math.arith"`
|
||||||
|
|
||||||
Currently, the "math.arith" module provides two functions, add() and mul(), that perform addition and multiplication of an arbitrary number of parameters. More functions will be added in the future.
|
Currently, the "math.arith" module provides two functions, add() and mul(), that perform addition and multiplication of an arbitrary number of parameters. More functions will be added in the future.
|
||||||
|
|
||||||
* <<_add,add()>>
|
* <<_add,add()>>
|
||||||
@@ -1421,13 +1454,12 @@ Same as <<_add,add()>> but returns the product of the values of the parameters.
|
|||||||
[green]`24`
|
[green]`24`
|
||||||
|
|
||||||
==== Module "os.file"
|
==== Module "os.file"
|
||||||
|
Module activation: +
|
||||||
|
`{4sp}BUILTIN "os.file"`
|
||||||
|
|
||||||
The "os.file" module provides functions for working with files.
|
The "os.file" module provides functions for working with files.
|
||||||
|
|
||||||
Activation: +
|
.File related functions
|
||||||
`{4sp}builtin "os.file"`
|
|
||||||
|
|
||||||
Currently available functions:
|
|
||||||
|
|
||||||
* <<_fileOpen,fileOpen()>>
|
* <<_fileOpen,fileOpen()>>
|
||||||
* <<_fileAppend,fileAppend()>>
|
* <<_fileAppend,fileAppend()>>
|
||||||
* <<_fileCreate,fileCreate()>>
|
* <<_fileCreate,fileCreate()>>
|
||||||
@@ -1436,6 +1468,10 @@ Currently available functions:
|
|||||||
* <<_fileReadText,fileReadText()>>
|
* <<_fileReadText,fileReadText()>>
|
||||||
* <<_fileReadTextAll,fileReadTextAll()>>
|
* <<_fileReadTextAll,fileReadTextAll()>>
|
||||||
|
|
||||||
|
.Iterator functions for files
|
||||||
|
* <<_fileByteIterator,fileByteIterator()>>
|
||||||
|
* <<_fileLineIterator,fileLineIterator()>>
|
||||||
|
|
||||||
More functions will be added in the future.
|
More functions will be added in the future.
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -1447,6 +1483,10 @@ Syntax: +
|
|||||||
Returns a file handle for the specified file path. The file is opened in read-write mode. If the file does not exist, it is created.
|
Returns a file handle for the specified file path. The file is opened in read-write mode. If the file does not exist, it is created.
|
||||||
|
|
||||||
===== fileAppend()
|
===== fileAppend()
|
||||||
|
Syntax: +
|
||||||
|
`{4sp}fileAppend(<file-path>) -> any`
|
||||||
|
|
||||||
|
Like <<_fileCreate,fileCreate()>> but write operations happen at the end of the file.
|
||||||
|
|
||||||
===== fileCreate()
|
===== fileCreate()
|
||||||
Syntax: +
|
Syntax: +
|
||||||
@@ -1455,21 +1495,30 @@ Syntax: +
|
|||||||
Creates or truncates the named _<file-path>_. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0o666 (before umask). The associated file descriptor has mode [O_RDWR]. The directory containing the file must already exist.
|
Creates or truncates the named _<file-path>_. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0o666 (before umask). The associated file descriptor has mode [O_RDWR]. The directory containing the file must already exist.
|
||||||
|
|
||||||
===== fileClose()
|
===== fileClose()
|
||||||
|
#to-do#
|
||||||
|
|
||||||
===== fileWriteText()
|
===== fileWriteText()
|
||||||
|
#to-do#
|
||||||
|
|
||||||
===== fileReadText()
|
===== fileReadText()
|
||||||
|
#to-do#
|
||||||
|
|
||||||
===== fileReadTextAll()
|
===== fileReadTextAll()
|
||||||
|
#to-do#
|
||||||
|
|
||||||
|
===== fileByteIterator()
|
||||||
|
#to-do#
|
||||||
|
|
||||||
|
===== fileLineIterator()
|
||||||
|
#to-do#
|
||||||
|
|
||||||
|
|
||||||
==== Module "string"
|
==== Module "string"
|
||||||
|
Module activation: +
|
||||||
|
`{4sp}BUILTIN "string"`
|
||||||
|
|
||||||
This module provides functions for working with strings.
|
This module provides functions for working with strings.
|
||||||
|
|
||||||
Activation: +
|
|
||||||
`{4sp}builtin "string"`
|
|
||||||
|
|
||||||
|
|
||||||
Currently available functions:
|
Currently available functions:
|
||||||
|
|
||||||
* <<_strJoin,strJoin()>>
|
* <<_strJoin,strJoin()>>
|
||||||
|
|||||||
@@ -0,0 +1,322 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>file: Go Coverage Report</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: black;
|
||||||
|
color: rgb(80, 80, 80);
|
||||||
|
}
|
||||||
|
body, pre, #legend span {
|
||||||
|
font-family: Menlo, monospace;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
#topbar {
|
||||||
|
background: black;
|
||||||
|
position: fixed;
|
||||||
|
top: 0; left: 0; right: 0;
|
||||||
|
height: 42px;
|
||||||
|
border-bottom: 1px solid rgb(80, 80, 80);
|
||||||
|
}
|
||||||
|
#content {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
#nav, #legend {
|
||||||
|
float: left;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
#legend {
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
#nav {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
#legend span {
|
||||||
|
margin: 0 5px;
|
||||||
|
}
|
||||||
|
.cov0 { color: rgb(192, 0, 0) }
|
||||||
|
.cov1 { color: rgb(128, 128, 128) }
|
||||||
|
.cov2 { color: rgb(116, 140, 131) }
|
||||||
|
.cov3 { color: rgb(104, 152, 134) }
|
||||||
|
.cov4 { color: rgb(92, 164, 137) }
|
||||||
|
.cov5 { color: rgb(80, 176, 140) }
|
||||||
|
.cov6 { color: rgb(68, 188, 143) }
|
||||||
|
.cov7 { color: rgb(56, 200, 146) }
|
||||||
|
.cov8 { color: rgb(44, 212, 149) }
|
||||||
|
.cov9 { color: rgb(32, 224, 152) }
|
||||||
|
.cov10 { color: rgb(20, 236, 155) }
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="topbar">
|
||||||
|
<div id="nav">
|
||||||
|
<select id="files">
|
||||||
|
|
||||||
|
<option value="file0">git.portale-stac.it/go-pkg/expr/file/file.go (88.9%)</option>
|
||||||
|
|
||||||
|
<option value="file1">git.portale-stac.it/go-pkg/expr/file/reader.go (77.8%)</option>
|
||||||
|
|
||||||
|
<option value="file2">git.portale-stac.it/go-pkg/expr/file/writer.go (100.0%)</option>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div id="legend">
|
||||||
|
<span>not tracked</span>
|
||||||
|
|
||||||
|
<span class="cov0">not covered</span>
|
||||||
|
<span class="cov8">covered</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<pre class="file" id="file0" style="display: none">// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// file.go
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Handle interface {
|
||||||
|
kern.Typer
|
||||||
|
GetFile() *os.File
|
||||||
|
GetName() string
|
||||||
|
Valid() bool
|
||||||
|
Close() error
|
||||||
|
}
|
||||||
|
|
||||||
|
type handleBase struct {
|
||||||
|
fh *os.File
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handleBase) GetFile() *os.File <span class="cov0" title="0">{
|
||||||
|
return h.fh
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (h *handleBase) GetName() (name string) <span class="cov8" title="1">{
|
||||||
|
if h.fh != nil </span><span class="cov8" title="1">{
|
||||||
|
name = h.fh.Name()
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handleBase) Valid() bool <span class="cov8" title="1">{
|
||||||
|
return h.fh != nil
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (h *handleBase) Close() (err error) <span class="cov8" title="1">{
|
||||||
|
if h.fh != nil </span><span class="cov8" title="1">{
|
||||||
|
err = h.fh.Close()
|
||||||
|
h.fh = nil
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre class="file" id="file1" style="display: none">// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// reader.go
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Reader struct {
|
||||||
|
// fh *os.File
|
||||||
|
handleBase
|
||||||
|
reader *bufio.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewReader(fh *os.File) *Reader <span class="cov8" title="1">{
|
||||||
|
return &Reader{handleBase: handleBase{fh: fh}, reader: bufio.NewReader(fh)}
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func OpenReader(filePath string) (r *Reader, err error) <span class="cov8" title="1">{
|
||||||
|
var fh *os.File
|
||||||
|
if fh, err = os.Open(filePath); err == nil </span><span class="cov8" title="1">{
|
||||||
|
r = NewReader(fh)
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) TypeName() string <span class="cov8" title="1">{
|
||||||
|
return "fileReader"
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (h *Reader) String() string <span class="cov8" title="1">{
|
||||||
|
return "reader"
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (h *Reader) Valid() bool <span class="cov8" title="1">{
|
||||||
|
return h.handleBase.Valid() && h.reader != nil
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (w *Reader) Close() (err error) <span class="cov8" title="1">{
|
||||||
|
w.reader = nil
|
||||||
|
err = w.handleBase.Close()
|
||||||
|
return
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (h *Reader) ReadByte() (b byte, err error) <span class="cov8" title="1">{
|
||||||
|
if h.reader != nil </span><span class="cov8" title="1">{
|
||||||
|
b, err = h.reader.ReadByte()
|
||||||
|
}</span> else<span class="cov0" title="0"> {
|
||||||
|
err = io.ErrClosedPipe
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) ReadAll() (p []byte, err error) <span class="cov8" title="1">{
|
||||||
|
if h.reader != nil </span><span class="cov8" title="1">{
|
||||||
|
p, err = io.ReadAll(h.reader)
|
||||||
|
}</span> else<span class="cov0" title="0"> {
|
||||||
|
err = io.ErrClosedPipe
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) ReadString(delim byte) (s string, err error) <span class="cov0" title="0">{
|
||||||
|
if h.reader != nil </span><span class="cov0" title="0">{
|
||||||
|
s, err = h.reader.ReadString(delim)
|
||||||
|
}</span> else<span class="cov0" title="0"> {
|
||||||
|
err = io.ErrClosedPipe
|
||||||
|
}</span>
|
||||||
|
<span class="cov0" title="0">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) Reset() (err error) <span class="cov8" title="1">{
|
||||||
|
if h.fh != nil </span><span class="cov8" title="1">{
|
||||||
|
if _, err = h.fh.Seek(0, 0); err == nil </span><span class="cov8" title="1">{
|
||||||
|
h.reader.Reset(h.fh)
|
||||||
|
}</span>
|
||||||
|
}
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre class="file" id="file2" style="display: none">// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// writer.go
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Writer struct {
|
||||||
|
// fh *os.File
|
||||||
|
handleBase
|
||||||
|
writer *bufio.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriter(fh *os.File) *Writer <span class="cov8" title="1">{
|
||||||
|
return &Writer{handleBase: handleBase{fh: fh}, writer: bufio.NewWriter(fh)}
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func CreateWriter(filePath string) (w *Writer, err error) <span class="cov8" title="1">{
|
||||||
|
var fh *os.File
|
||||||
|
if fh, err = os.Create(filePath); err == nil </span><span class="cov8" title="1">{
|
||||||
|
w = NewWriter(fh)
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func AppendWriter(filePath string) (w *Writer, err error) <span class="cov8" title="1">{
|
||||||
|
var fh *os.File
|
||||||
|
if fh, err = os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0644); err == nil </span><span class="cov8" title="1">{
|
||||||
|
w = NewWriter(fh)
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) TypeName() string <span class="cov8" title="1">{
|
||||||
|
return "fileWriter"
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (w *Writer) String() string <span class="cov8" title="1">{
|
||||||
|
return "writer"
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (w *Writer) Valid() bool <span class="cov8" title="1">{
|
||||||
|
return w.handleBase.Valid() && w.writer != nil
|
||||||
|
}</span>
|
||||||
|
|
||||||
|
func (w *Writer) Close() (err error) <span class="cov8" title="1">{
|
||||||
|
var err1 error
|
||||||
|
if w.writer != nil </span><span class="cov8" title="1">{
|
||||||
|
err1 = w.Flush()
|
||||||
|
w.writer = nil
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">if err = w.handleBase.Close(); err == nil </span><span class="cov8" title="1">{
|
||||||
|
err = err1
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Flush() (err error) <span class="cov8" title="1">{
|
||||||
|
if w.writer != nil </span><span class="cov8" title="1">{
|
||||||
|
err = w.writer.Flush()
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Write(args ...any) (n int, err error) <span class="cov8" title="1">{
|
||||||
|
if w.writer != nil </span><span class="cov8" title="1">{
|
||||||
|
n, err = fmt.Fprint(w.writer, args...)
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Writef(format string, args ...any) (n int, err error) <span class="cov8" title="1">{
|
||||||
|
if w.writer != nil </span><span class="cov8" title="1">{
|
||||||
|
n, err = fmt.Fprintf(w.writer, format, args...)
|
||||||
|
}</span>
|
||||||
|
<span class="cov8" title="1">return</span>
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
var files = document.getElementById('files');
|
||||||
|
var visible;
|
||||||
|
files.addEventListener('change', onChange, false);
|
||||||
|
function select(part) {
|
||||||
|
if (visible)
|
||||||
|
visible.style.display = 'none';
|
||||||
|
visible = document.getElementById(part);
|
||||||
|
if (!visible)
|
||||||
|
return;
|
||||||
|
files.value = part;
|
||||||
|
visible.style.display = 'block';
|
||||||
|
location.hash = part;
|
||||||
|
}
|
||||||
|
function onChange() {
|
||||||
|
select(files.value);
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
}
|
||||||
|
if (location.hash != "") {
|
||||||
|
select(location.hash.substr(1));
|
||||||
|
}
|
||||||
|
if (!visible) {
|
||||||
|
select("file0");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// file.go
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Handle interface {
|
||||||
|
kern.Typer
|
||||||
|
GetFile() *os.File
|
||||||
|
GetName() string
|
||||||
|
Valid() bool
|
||||||
|
Close() error
|
||||||
|
}
|
||||||
|
|
||||||
|
type handleBase struct {
|
||||||
|
fh *os.File
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handleBase) GetFile() *os.File {
|
||||||
|
return h.fh
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handleBase) GetName() (name string) {
|
||||||
|
if h.fh != nil {
|
||||||
|
name = h.fh.Name()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handleBase) Valid() bool {
|
||||||
|
return h.fh != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handleBase) Close() (err error) {
|
||||||
|
if h.fh != nil {
|
||||||
|
err = h.fh.Close()
|
||||||
|
h.fh = nil
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// reader.go
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Reader struct {
|
||||||
|
// fh *os.File
|
||||||
|
handleBase
|
||||||
|
reader *bufio.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewReader(fh *os.File) *Reader {
|
||||||
|
return &Reader{handleBase: handleBase{fh: fh}, reader: bufio.NewReader(fh)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpenReader(filePath string) (r *Reader, err error) {
|
||||||
|
var fh *os.File
|
||||||
|
if fh, err = os.Open(filePath); err == nil {
|
||||||
|
r = NewReader(fh)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) TypeName() string {
|
||||||
|
return "fileReader"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) String() string {
|
||||||
|
return "reader"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) Valid() bool {
|
||||||
|
return h.handleBase.Valid() && h.reader != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Reader) Close() (err error) {
|
||||||
|
w.reader = nil
|
||||||
|
err = w.handleBase.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) ReadByte() (b byte, err error) {
|
||||||
|
if h.reader != nil {
|
||||||
|
b, err = h.reader.ReadByte()
|
||||||
|
} else {
|
||||||
|
err = io.ErrClosedPipe
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) ReadAll() (p []byte, err error) {
|
||||||
|
if h.reader != nil {
|
||||||
|
p, err = io.ReadAll(h.reader)
|
||||||
|
} else {
|
||||||
|
err = io.ErrClosedPipe
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) ReadString(delim byte) (s string, err error) {
|
||||||
|
if h.reader != nil {
|
||||||
|
s, err = h.reader.ReadString(delim)
|
||||||
|
} else {
|
||||||
|
err = io.ErrClosedPipe
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Reader) Reset() (err error) {
|
||||||
|
if h.fh != nil {
|
||||||
|
if _, err = h.fh.Seek(0, 0); err == nil {
|
||||||
|
h.reader.Reset(h.fh)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// reader.go
|
||||||
|
package file
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestOpenReader(t *testing.T) {
|
||||||
|
r, err := OpenReader("t_reader_test.go")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("OpenReader failed: %v", err)
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
|
if !r.Valid() {
|
||||||
|
t.Fatal("Reader should be valid after opening")
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.TypeName() != "fileReader" {
|
||||||
|
t.Fatalf("Expected TypeName 'fileReader', got '%s'", r.TypeName())
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.String() != "reader" {
|
||||||
|
t.Fatalf("Expected String 'reader', got '%s'", r.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName may return either "t_reader_test.go" or "./t_reader_test.go" depending on the environment
|
||||||
|
name := r.GetName()
|
||||||
|
if (name != "t_reader_test.go") && (name != "./t_reader_test.go") {
|
||||||
|
t.Fatalf("Expected GetName 't_reader_test.go' or './t_reader_test.go', got '%s'", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test reading a byte
|
||||||
|
b, err := r.ReadByte()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ReadByte failed: %v", err)
|
||||||
|
}
|
||||||
|
if b == 0 {
|
||||||
|
t.Fatal("ReadByte should not return zero byte")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = r.Reset()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Reset failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if s, err := r.ReadString('\n'); err != nil {
|
||||||
|
t.Fatalf("ReadString failed: %v", err)
|
||||||
|
} else {
|
||||||
|
t.Logf("ReadString: %s", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test reading all content
|
||||||
|
content, err := r.ReadAll()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ReadAll failed: %v", err)
|
||||||
|
}
|
||||||
|
if len(content) == 0 {
|
||||||
|
t.Fatal("ReadAll should return non-empty content")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// writer.go
|
||||||
|
package file
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestCreateWriter(t *testing.T) {
|
||||||
|
w, err := CreateWriter("/tmp/test_writer.txt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("CreateWriter failed: %v", err)
|
||||||
|
}
|
||||||
|
defer w.Close()
|
||||||
|
|
||||||
|
if !w.Valid() {
|
||||||
|
t.Fatal("Writer should be valid after creation")
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.TypeName() != "fileWriter" {
|
||||||
|
t.Fatalf("Expected TypeName 'fileWriter', got '%s'", w.TypeName())
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.String() != "writer" {
|
||||||
|
t.Fatalf("Expected String 'writer', got '%s'", w.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
name := w.GetName()
|
||||||
|
if name != "/tmp/test_writer.txt" {
|
||||||
|
t.Fatalf("Expected GetName '/tmp/test_writer.txt', got '%s'", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if n, err := w.Write("Hello, World!\n"); err != nil {
|
||||||
|
t.Fatalf("Write failed: %v", err)
|
||||||
|
} else if n != len("Hello, World!\n") {
|
||||||
|
t.Fatalf("Expected to write %d bytes, wrote %d", len("Hello, World!\n"), n)
|
||||||
|
}
|
||||||
|
|
||||||
|
if n, err := w.Writef("This is a %s.\n", "test"); err != nil {
|
||||||
|
t.Fatalf("Writef failed: %v", err)
|
||||||
|
} else if n != len("This is a test.\n") {
|
||||||
|
t.Fatalf("Expected to write %d bytes, wrote %d", len("This is a test.\n"), n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppendWriter(t *testing.T) {
|
||||||
|
w, err := AppendWriter("/tmp/test_writer.txt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("AppendWriter failed: %v", err)
|
||||||
|
}
|
||||||
|
defer w.Close()
|
||||||
|
|
||||||
|
if !w.Valid() {
|
||||||
|
t.Fatal("Writer should be valid after opening for append")
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.TypeName() != "fileWriter" {
|
||||||
|
t.Fatalf("Expected TypeName 'fileWriter', got '%s'", w.TypeName())
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.String() != "writer" {
|
||||||
|
t.Fatalf("Expected String 'writer', got '%s'", w.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
name := w.GetName()
|
||||||
|
if name != "/tmp/test_writer.txt" {
|
||||||
|
t.Fatalf("Expected GetName '/tmp/test_writer.txt', got '%s'", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// writer.go
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Writer struct {
|
||||||
|
// fh *os.File
|
||||||
|
handleBase
|
||||||
|
writer *bufio.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWriter(fh *os.File) *Writer {
|
||||||
|
return &Writer{handleBase: handleBase{fh: fh}, writer: bufio.NewWriter(fh)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateWriter(filePath string) (w *Writer, err error) {
|
||||||
|
var fh *os.File
|
||||||
|
if fh, err = os.Create(filePath); err == nil {
|
||||||
|
w = NewWriter(fh)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func AppendWriter(filePath string) (w *Writer, err error) {
|
||||||
|
var fh *os.File
|
||||||
|
if fh, err = os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0644); err == nil {
|
||||||
|
w = NewWriter(fh)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) TypeName() string {
|
||||||
|
return "fileWriter"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) String() string {
|
||||||
|
return "writer"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Valid() bool {
|
||||||
|
return w.handleBase.Valid() && w.writer != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Close() (err error) {
|
||||||
|
var err1 error
|
||||||
|
if w.writer != nil {
|
||||||
|
err1 = w.Flush()
|
||||||
|
w.writer = nil
|
||||||
|
}
|
||||||
|
if err = w.handleBase.Close(); err == nil {
|
||||||
|
err = err1
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Flush() (err error) {
|
||||||
|
if w.writer != nil {
|
||||||
|
err = w.writer.Flush()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Write(args ...any) (n int, err error) {
|
||||||
|
if w.writer != nil {
|
||||||
|
n, err = fmt.Fprint(w.writer, args...)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Writer) Writef(format string, args ...any) (n int, err error) {
|
||||||
|
if w.writer != nil {
|
||||||
|
n, err = fmt.Fprintf(w.writer, format, args...)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
-388
@@ -1,388 +0,0 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
||||||
// All rights reserved.
|
|
||||||
|
|
||||||
// function.go
|
|
||||||
package expr
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.portale-stac.it/go-pkg/expr/kern"
|
|
||||||
"git.portale-stac.it/go-pkg/expr/scan"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ---- Function template
|
|
||||||
// type FuncTemplate func(ctx expr.ExprContext, name string, args map[string]any) (result any, err error)
|
|
||||||
|
|
||||||
// ---- Common functor definition
|
|
||||||
type BaseFunctor struct {
|
|
||||||
info kern.ExprFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (functor *BaseFunctor) ToString(opt kern.FmtOpt) (s string) {
|
|
||||||
if functor.info != nil {
|
|
||||||
s = functor.info.ToString(opt)
|
|
||||||
} else {
|
|
||||||
s = "func(){}"
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (functor *BaseFunctor) GetParams() (params []kern.ExprFuncParam) {
|
|
||||||
if functor.info != nil {
|
|
||||||
return functor.info.Params()
|
|
||||||
} else {
|
|
||||||
return []kern.ExprFuncParam{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (functor *BaseFunctor) SetFunc(info kern.ExprFunc) {
|
|
||||||
functor.info = info
|
|
||||||
}
|
|
||||||
|
|
||||||
func (functor *BaseFunctor) GetFunc() kern.ExprFunc {
|
|
||||||
return functor.info
|
|
||||||
}
|
|
||||||
|
|
||||||
func (functor *BaseFunctor) GetDefinitionContext() kern.ExprContext {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Function Parameters
|
|
||||||
type paramFlags uint16
|
|
||||||
|
|
||||||
const (
|
|
||||||
PfDefault paramFlags = 1 << iota
|
|
||||||
PfOptional
|
|
||||||
PfRepeat
|
|
||||||
)
|
|
||||||
|
|
||||||
type funcParamInfo struct {
|
|
||||||
name string
|
|
||||||
flags paramFlags
|
|
||||||
defaultValue any
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFuncParam(name string) kern.ExprFuncParam {
|
|
||||||
return &funcParamInfo{name: name}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFuncParamFlag(name string, flags paramFlags) kern.ExprFuncParam {
|
|
||||||
return &funcParamInfo{name: name, flags: flags}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFuncParamFlagDef(name string, flags paramFlags, defValue any) *funcParamInfo {
|
|
||||||
return &funcParamInfo{name: name, flags: flags, defaultValue: defValue}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (param *funcParamInfo) Name() string {
|
|
||||||
return param.name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (param *funcParamInfo) Type() string {
|
|
||||||
return kern.TypeAny
|
|
||||||
}
|
|
||||||
|
|
||||||
func (param *funcParamInfo) IsDefault() bool {
|
|
||||||
return (param.flags & PfDefault) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (param *funcParamInfo) IsOptional() bool {
|
|
||||||
return (param.flags & PfOptional) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (param *funcParamInfo) IsRepeat() bool {
|
|
||||||
return (param.flags & PfRepeat) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (param *funcParamInfo) DefaultValue() any {
|
|
||||||
return param.defaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Functions
|
|
||||||
|
|
||||||
// funcInfo implements expr.ExprFunc
|
|
||||||
type funcInfo struct {
|
|
||||||
name string
|
|
||||||
minArgs int
|
|
||||||
maxArgs int
|
|
||||||
functor kern.Functor
|
|
||||||
formalParams []kern.ExprFuncParam
|
|
||||||
returnType string
|
|
||||||
}
|
|
||||||
|
|
||||||
func newFuncInfo(name string, functor kern.Functor, returnType string, params []kern.ExprFuncParam) (info *funcInfo, err error) {
|
|
||||||
var minArgs = 0
|
|
||||||
var maxArgs = 0
|
|
||||||
for _, p := range params {
|
|
||||||
if maxArgs == -1 {
|
|
||||||
return nil, fmt.Errorf("no more params can be specified after the ellipsis symbol: %q", p.Name())
|
|
||||||
}
|
|
||||||
if p.IsDefault() || p.IsOptional() {
|
|
||||||
maxArgs++
|
|
||||||
} else if maxArgs == minArgs {
|
|
||||||
minArgs++
|
|
||||||
maxArgs++
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("can't specify non-optional param after optional ones: %q", p.Name())
|
|
||||||
}
|
|
||||||
if p.IsRepeat() {
|
|
||||||
minArgs--
|
|
||||||
maxArgs = -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info = &funcInfo{
|
|
||||||
name: name, minArgs: minArgs, maxArgs: maxArgs, functor: functor, returnType: returnType, formalParams: params,
|
|
||||||
}
|
|
||||||
functor.SetFunc(info)
|
|
||||||
return info, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) Params() []kern.ExprFuncParam {
|
|
||||||
return info.formalParams
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) ReturnType() string {
|
|
||||||
return info.returnType
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) ToString(opt kern.FmtOpt) string {
|
|
||||||
var sb strings.Builder
|
|
||||||
if len(info.Name()) == 0 {
|
|
||||||
sb.WriteString("func")
|
|
||||||
} else {
|
|
||||||
sb.WriteString(info.Name())
|
|
||||||
}
|
|
||||||
sb.WriteByte('(')
|
|
||||||
if info.formalParams != nil {
|
|
||||||
for i, p := range info.formalParams {
|
|
||||||
if i > 0 {
|
|
||||||
sb.WriteString(", ")
|
|
||||||
}
|
|
||||||
sb.WriteString(p.Name())
|
|
||||||
|
|
||||||
if p.IsDefault() {
|
|
||||||
sb.WriteByte('=')
|
|
||||||
if s, ok := p.DefaultValue().(string); ok {
|
|
||||||
sb.WriteByte('"')
|
|
||||||
sb.WriteString(s)
|
|
||||||
sb.WriteByte('"')
|
|
||||||
} else {
|
|
||||||
sb.WriteString(fmt.Sprintf("%v", p.DefaultValue()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if info.maxArgs < 0 {
|
|
||||||
sb.WriteString(" ...")
|
|
||||||
}
|
|
||||||
sb.WriteString("):")
|
|
||||||
if len(info.returnType) > 0 {
|
|
||||||
sb.WriteString(info.returnType)
|
|
||||||
} else {
|
|
||||||
sb.WriteString(kern.TypeAny)
|
|
||||||
}
|
|
||||||
sb.WriteString("{}")
|
|
||||||
return sb.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) Name() string {
|
|
||||||
return info.name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) MinArgs() int {
|
|
||||||
return info.minArgs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) MaxArgs() int {
|
|
||||||
return info.maxArgs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) Functor() kern.Functor {
|
|
||||||
return info.functor
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) AllocContext(parentCtx kern.ExprContext) (ctx kern.ExprContext) {
|
|
||||||
if defCtx := info.functor.GetDefinitionContext(); defCtx != nil {
|
|
||||||
ctx = defCtx.Clone()
|
|
||||||
ctx.SetParent(defCtx)
|
|
||||||
} else {
|
|
||||||
ctx = parentCtx.Clone()
|
|
||||||
ctx.SetParent(parentCtx)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) ParamSpec(paramName string) kern.ExprFuncParam {
|
|
||||||
for _, spec := range info.formalParams {
|
|
||||||
if spec.Name() == paramName {
|
|
||||||
return spec
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func initActualParams(ctx kern.ExprContext, info kern.ExprFunc, callTerm *scan.Term) (actualParams map[string]any, err error) {
|
|
||||||
var varArgs []any
|
|
||||||
var varName string
|
|
||||||
|
|
||||||
namedParamsStarted := false
|
|
||||||
|
|
||||||
formalParams := info.Params()
|
|
||||||
actualParams = make(map[string]any, len(formalParams))
|
|
||||||
if callTerm == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, tree := range callTerm.Children {
|
|
||||||
var paramValue any
|
|
||||||
paramCtx := ctx.Clone()
|
|
||||||
if paramValue, err = tree.Compute(paramCtx); err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if paramName, namedParam := kern.GetAssignVarName(tree); namedParam {
|
|
||||||
if info.ParamSpec(paramName) == nil {
|
|
||||||
err = fmt.Errorf("%s(): unknown param %q", info.Name(), paramName)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
actualParams[paramName] = paramValue
|
|
||||||
namedParamsStarted = true
|
|
||||||
} else if !namedParamsStarted {
|
|
||||||
if varArgs != nil {
|
|
||||||
varArgs = append(varArgs, paramValue)
|
|
||||||
} else if i < len(formalParams) {
|
|
||||||
spec := formalParams[i]
|
|
||||||
if spec.IsRepeat() {
|
|
||||||
varArgs = make([]any, 0, len(callTerm.Children)-i)
|
|
||||||
varArgs = append(varArgs, paramValue)
|
|
||||||
varName = spec.Name()
|
|
||||||
} else {
|
|
||||||
actualParams[spec.Name()] = paramValue
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = kern.ErrTooManyParams(info.Name(), len(formalParams), len(callTerm.Children))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = fmt.Errorf("%s(): positional param nr %d not allowed after named params", info.Name(), i+1)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
if varArgs != nil {
|
|
||||||
actualParams[varName] = varArgs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (info *funcInfo) PrepareCall(name string, actualParams map[string]any) (err error) {
|
|
||||||
passedCount := len(actualParams)
|
|
||||||
if info.MinArgs() > passedCount {
|
|
||||||
err = kern.ErrTooFewParams(name, info.MinArgs(), info.MaxArgs(), passedCount)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if passedCount < len(info.formalParams) {
|
|
||||||
for _, p := range info.formalParams {
|
|
||||||
if _, exists := actualParams[p.Name()]; !exists {
|
|
||||||
if !p.IsDefault() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if p.IsRepeat() {
|
|
||||||
varArgs := make([]any, 1)
|
|
||||||
varArgs[0] = p.DefaultValue()
|
|
||||||
actualParams[p.Name()] = varArgs
|
|
||||||
} else {
|
|
||||||
actualParams[p.Name()] = p.DefaultValue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if info.MaxArgs() >= 0 && info.MaxArgs() < len(actualParams) {
|
|
||||||
err = kern.ErrTooManyParams(name, info.MaxArgs(), len(actualParams))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----- Call a function ---
|
|
||||||
|
|
||||||
// func getAssignVarName(t *term) (name string, ok bool) {
|
|
||||||
// if ok = t.symbol() == SymEqual; ok {
|
|
||||||
// name = t.children[0].source()
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func CallFunctionByTerm(parentCtx expr.ExprContext, name string, callTerm *term) (result any, err error) {
|
|
||||||
// var actualParams map[string]any
|
|
||||||
// if info, exists := GetFuncInfo(parentCtx, name); exists {
|
|
||||||
// if actualParams, err = initActualParams(parentCtx, info, callTerm); err == nil {
|
|
||||||
// ctx := info.AllocContext(parentCtx)
|
|
||||||
// if err = info.PrepareCall(name, actualParams); err == nil {
|
|
||||||
// functor := info.Functor()
|
|
||||||
// result, err = functor.InvokeNamed(ctx, name, actualParams)
|
|
||||||
// exportObjectsToParent(ctx)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// err = fmt.Errorf("unknown function %s()", name)
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func CallFunctionByArgs(parentCtx expr.ExprContext, name string, args []any) (result any, err error) {
|
|
||||||
// var actualParams map[string]any
|
|
||||||
// if info, exists := GetFuncInfo(parentCtx, name); exists {
|
|
||||||
// functor := info.Functor()
|
|
||||||
// actualParams = bindActualParams(functor, args)
|
|
||||||
// ctx := info.AllocContext(parentCtx)
|
|
||||||
// if err = info.PrepareCall(name, actualParams); err == nil {
|
|
||||||
// result, err = functor.InvokeNamed(ctx, name, actualParams)
|
|
||||||
// exportObjectsToParent(ctx)
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// err = fmt.Errorf("unknown function %s()", name)
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func CallFunctionByParams(parentCtx expr.ExprContext, name string, actualParams map[string]any) (result any, err error) {
|
|
||||||
// //var actualParams map[string]any
|
|
||||||
// if info, exists := GetFuncInfo(parentCtx, name); exists {
|
|
||||||
// functor := info.Functor()
|
|
||||||
// ctx := info.AllocContext(parentCtx)
|
|
||||||
// if err = info.PrepareCall(name, actualParams); err == nil {
|
|
||||||
// result, err = functor.InvokeNamed(ctx, name, actualParams)
|
|
||||||
// exportObjectsToParent(ctx)
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// err = fmt.Errorf("unknown function %s()", name)
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func GetParam(args map[string]any, paramName string, paramNum int) (value any, exists bool) {
|
|
||||||
// if value, exists = args[paramName]; !exists {
|
|
||||||
// if paramNum > 0 && paramNum <= len(args) {
|
|
||||||
// value, exists = args["arg"+strconv.Itoa(paramNum)]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func bindActualParams(functor Functor, args []any) (actualParams map[string]any) {
|
|
||||||
// formalParams := functor.GetParams()
|
|
||||||
// actualParams = make(map[string]any, len(args))
|
|
||||||
// for i, arg := range args {
|
|
||||||
// if i < len(formalParams) {
|
|
||||||
// actualParams[formalParams[i].Name()] = arg
|
|
||||||
// } else {
|
|
||||||
// actualParams["arg"+strconv.Itoa(i+1)] = arg
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// global-context.go
|
// global-context.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
//go:build graph
|
//go:build graph
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// helpers.go
|
// helpers.go
|
||||||
@@ -45,7 +45,7 @@ func EvalStringV(source string, args []Arg) (result any, err error) {
|
|||||||
functor := kern.NewGolangFunctor(f)
|
functor := kern.NewGolangFunctor(f)
|
||||||
// ctx.RegisterFunc(arg.Name, functor, 0, -1)
|
// ctx.RegisterFunc(arg.Name, functor, 0, -1)
|
||||||
ctx.RegisterFunc(arg.Name, functor, kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc(arg.Name, functor, kern.TypeAny, []kern.ExprFuncParam{
|
||||||
NewFuncParamFlagDef(kern.ParamValue, PfDefault|PfRepeat, 0),
|
kern.NewFuncParamFlagDef(kern.ParamValue, kern.PfDefault|kern.PfRepeat, 0),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("invalid function specification: %q", arg.Name)
|
err = fmt.Errorf("invalid function specification: %q", arg.Name)
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// import-utils.go
|
// import-utils.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// int-iterator.go
|
// int-iterator.go
|
||||||
|
|||||||
+18
-3
@@ -1,14 +1,17 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// iter-factory.go
|
// iter-factory.go
|
||||||
package expr
|
package expr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
|
|
||||||
"git.portale-stac.it/go-pkg/expr/kern"
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
|
"git.portale-stac.it/go-pkg/expr/scan"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewIterator(value any) (it kern.Iterator, err error) {
|
func NewIterator(ctx kern.ExprContext, value any, ops []*scan.Term) (it kern.Iterator, err error) {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return NewArrayIterator([]any{}), nil
|
return NewArrayIterator([]any{}), nil
|
||||||
}
|
}
|
||||||
@@ -21,9 +24,21 @@ func NewIterator(value any) (it kern.Iterator, err error) {
|
|||||||
case []any:
|
case []any:
|
||||||
it = NewArrayIterator(v)
|
it = NewArrayIterator(v)
|
||||||
case kern.Iterator:
|
case kern.Iterator:
|
||||||
it = v
|
// var exprs []*scan.Term
|
||||||
|
it, err = NewIterIter(v, ctx, ops)
|
||||||
default:
|
default:
|
||||||
it = NewArrayIterator([]any{value})
|
it = NewArrayIterator([]any{value})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HasIterStandardOperations(name string) bool {
|
||||||
|
return slices.Contains([]string{kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName}, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HasIterOperations(name string, ops ...string) bool {
|
||||||
|
return slices.Contains([]string{
|
||||||
|
kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName,
|
||||||
|
}, name) ||
|
||||||
|
slices.Contains(ops, name)
|
||||||
|
}
|
||||||
|
|||||||
+135
@@ -0,0 +1,135 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// iter-iter.go
|
||||||
|
package expr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"git.portale-stac.it/go-pkg/expr/kern"
|
||||||
|
"git.portale-stac.it/go-pkg/expr/scan"
|
||||||
|
)
|
||||||
|
|
||||||
|
const iterIterType = "IterIter"
|
||||||
|
|
||||||
|
type IterIter struct {
|
||||||
|
it kern.Iterator
|
||||||
|
count int64
|
||||||
|
index int64
|
||||||
|
ctx kern.ExprContext
|
||||||
|
exprList []*scan.Term
|
||||||
|
current any
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIterIter(it kern.Iterator, ctx kern.ExprContext, exprs []*scan.Term) (iter kern.Iterator, err error) {
|
||||||
|
if ctx == nil {
|
||||||
|
err = fmt.Errorf("context is required for %s", iterIterType)
|
||||||
|
} else if it == nil {
|
||||||
|
err = fmt.Errorf("source iterator is required for %s", iterIterType)
|
||||||
|
} else {
|
||||||
|
iter = &IterIter{it: it, count: 0, index: -1, ctx: ctx, exprList: exprs, current: nil}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) String() string {
|
||||||
|
return fmt.Sprintf("$(%s)", it.it)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) TypeName() string {
|
||||||
|
return iterIterType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) HasOperation(name string) bool {
|
||||||
|
return HasIterStandardOperations(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) CallOperation(name string, args map[string]any) (v any, err error) {
|
||||||
|
switch name {
|
||||||
|
case kern.NextName:
|
||||||
|
v, err = it.Next()
|
||||||
|
case kern.ResetName:
|
||||||
|
err = it.Reset()
|
||||||
|
case kern.CleanName:
|
||||||
|
err = it.Clean()
|
||||||
|
case kern.IndexName:
|
||||||
|
v = int64(it.Index())
|
||||||
|
case kern.CurrentName:
|
||||||
|
v, err = it.Current()
|
||||||
|
case kern.CountName:
|
||||||
|
v = it.count
|
||||||
|
default:
|
||||||
|
err = kern.ErrNoOperation(name)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) Current() (item any, err error) {
|
||||||
|
if it.current != nil {
|
||||||
|
item = it.current
|
||||||
|
} else if len(it.exprList) > 0 {
|
||||||
|
// Evaluate the expression list and use the result as the current item
|
||||||
|
var exprValue any
|
||||||
|
for _, expr := range it.exprList {
|
||||||
|
if exprValue, err = expr.Compute(it.ctx); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
it.ctx.UnsafeSetVar(kern.ControlLastResult, exprValue)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
item = exprValue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var exists bool
|
||||||
|
if it.current, exists = it.ctx.GetVar("_"); !exists {
|
||||||
|
err = fmt.Errorf("current item not available")
|
||||||
|
} else {
|
||||||
|
item = it.current
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) Next() (item any, err error) {
|
||||||
|
var src any
|
||||||
|
|
||||||
|
it.current = nil
|
||||||
|
ctx := it.ctx
|
||||||
|
for src, err = it.it.Next(); src == nil && err == nil; src, err = it.it.Next() {
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
if src == nil {
|
||||||
|
err = io.EOF
|
||||||
|
} else {
|
||||||
|
ctx.UnsafeSetVar("_", src)
|
||||||
|
ctx.UnsafeSetVar("__", it.it.Index())
|
||||||
|
ctx.UnsafeSetVar("_#", it.it.Count())
|
||||||
|
item, err = it.Current()
|
||||||
|
ctx.DeleteVar("_#")
|
||||||
|
ctx.DeleteVar("__")
|
||||||
|
ctx.DeleteVar("_")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) Index() int64 {
|
||||||
|
return it.index
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) Count() int64 {
|
||||||
|
return it.count
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) Reset() error {
|
||||||
|
it.index = -1
|
||||||
|
it.count = 0
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (it *IterIter) Clean() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,23 +1,23 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// bind-go-function.go
|
// bind-go-function.go
|
||||||
package kern
|
package kern
|
||||||
|
|
||||||
// ---- Linking with Go functions
|
// ---- Linking with Go functions
|
||||||
type golangFunctor struct {
|
type GolangFunctor struct {
|
||||||
BaseFunctor
|
BaseFunctor
|
||||||
f FuncTemplate
|
f FuncTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGolangFunctor(f FuncTemplate) *golangFunctor {
|
func NewGolangFunctor(f FuncTemplate) *GolangFunctor {
|
||||||
return &golangFunctor{f: f}
|
return &GolangFunctor{f: f}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (functor *golangFunctor) TypeName() string {
|
func (functor *GolangFunctor) TypeName() string {
|
||||||
return "GoFunctor"
|
return "GoFunctor"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (functor *golangFunctor) InvokeNamed(ctx ExprContext, name string, args map[string]any) (result any, err error) {
|
func (functor *GolangFunctor) InvokeNamed(ctx ExprContext, name string, args map[string]any) (result any, err error) {
|
||||||
return functor.f(ctx, name, args)
|
return functor.f(ctx, name, args)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// common-errors.go
|
// common-errors.go
|
||||||
@@ -84,6 +84,10 @@ func ErrUnknownVar(funcName, varName string) error {
|
|||||||
return fmt.Errorf("%s(): unknown variable %q", funcName, varName)
|
return fmt.Errorf("%s(): unknown variable %q", funcName, varName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ErrFuncInvalidArg(funcName, details string) error {
|
||||||
|
return fmt.Errorf("%s(): invalid argument -- %s", funcName, details)
|
||||||
|
}
|
||||||
|
|
||||||
// --- Operator errors
|
// --- Operator errors
|
||||||
|
|
||||||
func ErrLeftOperandMustBeVariable(leftTerm, opTerm Term) error {
|
func ErrLeftOperandMustBeVariable(leftTerm, opTerm Term) error {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// common-params.go
|
// common-params.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// common-type-names.go
|
// common-type-names.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// context-helpers.go
|
// context-helpers.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// control.go
|
// control.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// dict-type.go
|
// dict-type.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// expr-context.go
|
// expr-context.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// expr-function.go
|
// expr-function.go
|
||||||
@@ -37,3 +37,8 @@ type ExprFunc interface {
|
|||||||
PrepareCall(name string, actualParams map[string]any) (err error)
|
PrepareCall(name string, actualParams map[string]any) (err error)
|
||||||
AllocContext(parentCtx ExprContext) (ctx ExprContext)
|
AllocContext(parentCtx ExprContext) (ctx ExprContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsFunctor(v any) (ok bool) {
|
||||||
|
_, ok = v.(Functor)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// expr.go
|
// expr.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// formatter.go
|
// formatter.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// fraction-type.go
|
// fraction-type.go
|
||||||
|
|||||||
@@ -0,0 +1,164 @@
|
|||||||
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// func-info.go
|
||||||
|
package kern
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// --- Functions
|
||||||
|
|
||||||
|
// FuncInfo implements expr.ExprFunc
|
||||||
|
type FuncInfo struct {
|
||||||
|
name string
|
||||||
|
minArgs int
|
||||||
|
maxArgs int
|
||||||
|
functor Functor
|
||||||
|
formalParams []ExprFuncParam
|
||||||
|
returnType string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFuncInfo(name string, functor Functor, returnType string, params []ExprFuncParam) (info *FuncInfo, err error) {
|
||||||
|
var minArgs = 0
|
||||||
|
var maxArgs = 0
|
||||||
|
for _, p := range params {
|
||||||
|
if maxArgs == -1 {
|
||||||
|
return nil, fmt.Errorf("no more params can be specified after the ellipsis symbol: %q", p.Name())
|
||||||
|
}
|
||||||
|
if p.IsDefault() || p.IsOptional() {
|
||||||
|
maxArgs++
|
||||||
|
} else if maxArgs == minArgs {
|
||||||
|
minArgs++
|
||||||
|
maxArgs++
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("can't specify non-optional param after optional ones: %q", p.Name())
|
||||||
|
}
|
||||||
|
if p.IsRepeat() {
|
||||||
|
minArgs--
|
||||||
|
maxArgs = -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info = &FuncInfo{
|
||||||
|
name: name, minArgs: minArgs, maxArgs: maxArgs, functor: functor, returnType: returnType, formalParams: params,
|
||||||
|
}
|
||||||
|
functor.SetFunc(info)
|
||||||
|
return info, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) Params() []ExprFuncParam {
|
||||||
|
return info.formalParams
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) ReturnType() string {
|
||||||
|
return info.returnType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) ToString(opt FmtOpt) string {
|
||||||
|
var sb strings.Builder
|
||||||
|
if len(info.Name()) == 0 {
|
||||||
|
sb.WriteString("func")
|
||||||
|
} else {
|
||||||
|
sb.WriteString(info.Name())
|
||||||
|
}
|
||||||
|
sb.WriteByte('(')
|
||||||
|
if info.formalParams != nil {
|
||||||
|
for i, p := range info.formalParams {
|
||||||
|
if i > 0 {
|
||||||
|
sb.WriteString(", ")
|
||||||
|
}
|
||||||
|
sb.WriteString(p.Name())
|
||||||
|
|
||||||
|
if p.IsDefault() {
|
||||||
|
sb.WriteByte('=')
|
||||||
|
if s, ok := p.DefaultValue().(string); ok {
|
||||||
|
sb.WriteByte('"')
|
||||||
|
sb.WriteString(s)
|
||||||
|
sb.WriteByte('"')
|
||||||
|
} else {
|
||||||
|
sb.WriteString(fmt.Sprintf("%v", p.DefaultValue()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if info.maxArgs < 0 {
|
||||||
|
sb.WriteString(" ...")
|
||||||
|
}
|
||||||
|
sb.WriteString("):")
|
||||||
|
if len(info.returnType) > 0 {
|
||||||
|
sb.WriteString(info.returnType)
|
||||||
|
} else {
|
||||||
|
sb.WriteString(TypeAny)
|
||||||
|
}
|
||||||
|
sb.WriteString("{}")
|
||||||
|
return sb.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) Name() string {
|
||||||
|
return info.name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) MinArgs() int {
|
||||||
|
return info.minArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) MaxArgs() int {
|
||||||
|
return info.maxArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) Functor() Functor {
|
||||||
|
return info.functor
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) AllocContext(parentCtx ExprContext) (ctx ExprContext) {
|
||||||
|
if defCtx := info.functor.GetDefinitionContext(); defCtx != nil {
|
||||||
|
ctx = defCtx.Clone()
|
||||||
|
ctx.SetParent(defCtx)
|
||||||
|
} else {
|
||||||
|
ctx = parentCtx.Clone()
|
||||||
|
ctx.SetParent(parentCtx)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) ParamSpec(paramName string) ExprFuncParam {
|
||||||
|
for _, spec := range info.formalParams {
|
||||||
|
if spec.Name() == paramName {
|
||||||
|
return spec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (info *FuncInfo) PrepareCall(name string, actualParams map[string]any) (err error) {
|
||||||
|
passedCount := len(actualParams)
|
||||||
|
if info.MinArgs() > passedCount {
|
||||||
|
err = ErrTooFewParams(name, info.MinArgs(), info.MaxArgs(), passedCount)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if passedCount < len(info.formalParams) {
|
||||||
|
for _, p := range info.formalParams {
|
||||||
|
if _, exists := actualParams[p.Name()]; !exists {
|
||||||
|
if !p.IsDefault() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if p.IsRepeat() {
|
||||||
|
varArgs := make([]any, 1)
|
||||||
|
varArgs[0] = p.DefaultValue()
|
||||||
|
actualParams[p.Name()] = varArgs
|
||||||
|
} else {
|
||||||
|
actualParams[p.Name()] = p.DefaultValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.MaxArgs() >= 0 && info.MaxArgs() < len(actualParams) {
|
||||||
|
err = ErrTooManyParams(name, info.MaxArgs(), len(actualParams))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
+6
-11
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// function.go
|
// function.go
|
||||||
@@ -14,11 +14,6 @@ type FuncTemplate func(ctx ExprContext, name string, args map[string]any) (resul
|
|||||||
|
|
||||||
type DeepFuncTemplate func(a, b any) (eq bool, err error)
|
type DeepFuncTemplate func(a, b any) (eq bool, err error)
|
||||||
|
|
||||||
func IsFunctor(v any) (ok bool) {
|
|
||||||
_, ok = v.(Functor)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Common functor definition
|
// ---- Common functor definition
|
||||||
type BaseFunctor struct {
|
type BaseFunctor struct {
|
||||||
info ExprFunc
|
info ExprFunc
|
||||||
@@ -54,17 +49,17 @@ func (functor *BaseFunctor) GetDefinitionContext() ExprContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---- Function Parameters
|
// ---- Function Parameters
|
||||||
type paramFlags uint16
|
type FuncParamFlags uint16
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PfDefault paramFlags = 1 << iota
|
PfDefault FuncParamFlags = 1 << iota
|
||||||
PfOptional
|
PfOptional
|
||||||
PfRepeat
|
PfRepeat
|
||||||
)
|
)
|
||||||
|
|
||||||
type funcParamInfo struct {
|
type funcParamInfo struct {
|
||||||
name string
|
name string
|
||||||
flags paramFlags
|
flags FuncParamFlags
|
||||||
defaultValue any
|
defaultValue any
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +67,11 @@ func NewFuncParam(name string) ExprFuncParam {
|
|||||||
return &funcParamInfo{name: name}
|
return &funcParamInfo{name: name}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFuncParamFlag(name string, flags paramFlags) ExprFuncParam {
|
func NewFuncParamFlag(name string, flags FuncParamFlags) ExprFuncParam {
|
||||||
return &funcParamInfo{name: name, flags: flags}
|
return &funcParamInfo{name: name, flags: flags}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFuncParamFlagDef(name string, flags paramFlags, defValue any) *funcParamInfo {
|
func NewFuncParamFlagDef(name string, flags FuncParamFlags, defValue any) *funcParamInfo {
|
||||||
return &funcParamInfo{name: name, flags: flags, defaultValue: defValue}
|
return &funcParamInfo{name: name, flags: flags, defaultValue: defValue}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// iterator.go
|
// iterator.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// list-type.go
|
// list-type.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// term.go
|
// term.go
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
//go:build darwin
|
//go:build darwin
|
||||||
|
|
||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// lib-ext-darwin.go
|
// lib-ext-darwin.go
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
//go:build linux
|
//go:build linux
|
||||||
|
|
||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// lib-ext-linux.go
|
// lib-ext-linux.go
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
//go:build windows
|
//go:build windows
|
||||||
|
|
||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// lib-ext-windows.go
|
// lib-ext-windows.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// list-iterator.go
|
// list-iterator.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-dict.go
|
// operand-dict.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-expr.go
|
// operand-expr.go
|
||||||
|
|||||||
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-func.go
|
// operand-func.go
|
||||||
@@ -70,14 +70,14 @@ func evalFuncDef(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
paramList := make([]kern.ExprFuncParam, 0, len(opTerm.Children))
|
paramList := make([]kern.ExprFuncParam, 0, len(opTerm.Children))
|
||||||
for _, param := range opTerm.Children {
|
for _, param := range opTerm.Children {
|
||||||
var defValue any
|
var defValue any
|
||||||
flags := paramFlags(0)
|
flags := kern.FuncParamFlags(0)
|
||||||
if len(param.Children) > 0 {
|
if len(param.Children) > 0 {
|
||||||
flags |= PfDefault
|
flags |= kern.PfDefault
|
||||||
if defValue, err = param.Children[0].Compute(ctx); err != nil {
|
if defValue, err = param.Children[0].Compute(ctx); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info := NewFuncParamFlagDef(param.Source(), flags, defValue)
|
info := kern.NewFuncParamFlagDef(param.Source(), flags, defValue)
|
||||||
paramList = append(paramList, info)
|
paramList = append(paramList, info)
|
||||||
}
|
}
|
||||||
v = newExprFunctor(ast, paramList, ctx)
|
v = newExprFunctor(ast, paramList, ctx)
|
||||||
|
|||||||
+39
-8
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-iterator.go
|
// operand-iterator.go
|
||||||
@@ -125,7 +125,7 @@ func evalIterator(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
} else {
|
} else {
|
||||||
if dictIt, ok := firstChildValue.(*kern.DictType); ok {
|
if dictIt, ok := firstChildValue.(*kern.DictType); ok {
|
||||||
var args []any
|
var args []any
|
||||||
if args, err = evalSibling(ctx, opTerm.Children, nil); err == nil {
|
if args, err = evalSiblings(ctx, opTerm.Children, nil); err == nil {
|
||||||
v, err = NewDictIterator(dictIt, args)
|
v, err = NewDictIterator(dictIt, args)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -134,24 +134,55 @@ func evalIterator(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
}
|
}
|
||||||
} else if list, ok := firstChildValue.(*kern.ListType); ok {
|
} else if list, ok := firstChildValue.(*kern.ListType); ok {
|
||||||
var args []any
|
var args []any
|
||||||
if args, err = evalSibling(ctx, opTerm.Children, nil); err == nil {
|
if args, err = evalSiblings(ctx, opTerm.Children, nil); err == nil {
|
||||||
v = NewListIterator(list, args)
|
v = NewListIterator(list, args)
|
||||||
}
|
}
|
||||||
} else if intVal, ok := firstChildValue.(int64); ok {
|
} else if intVal, ok := firstChildValue.(int64); ok {
|
||||||
var args []any
|
var args []any
|
||||||
if args, err = evalSibling(ctx, opTerm.Children, intVal); err == nil {
|
if args, err = evalSiblings(ctx, opTerm.Children, intVal); err == nil {
|
||||||
v, err = NewIntIterator(args)
|
v, err = NewIntIterator(args)
|
||||||
}
|
}
|
||||||
|
} else if it, ok := firstChildValue.(kern.Iterator); ok {
|
||||||
|
v, err = NewIterIter(it, ctx, opTerm.Children[1:])
|
||||||
} else {
|
} else {
|
||||||
var list []any
|
var siblings []any
|
||||||
if list, err = evalSibling(ctx, opTerm.Children, firstChildValue); err == nil {
|
if siblings, err = evalSiblings(ctx, opTerm.Children, firstChildValue); err == nil {
|
||||||
v = NewArrayIterator(list)
|
v = NewArrayIterator(siblings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func evalSibling(ctx kern.ExprContext, terms []*scan.Term, firstChildValue any) (list []any, err error) {
|
// func evalIterIter(ctx kern.ExprContext, firstChildValue any, siblings []any) (v any, err error) {
|
||||||
|
// var op kern.Functor
|
||||||
|
// var args map[string]any
|
||||||
|
|
||||||
|
// if it, ok := firstChildValue.(kern.Iterator); ok {
|
||||||
|
// if len(siblings) > 1 {
|
||||||
|
// if op, ok = siblings[1].(kern.Functor); ok {
|
||||||
|
// args = make(map[string]any, len(siblings)-2)
|
||||||
|
// for i, arg := range siblings[2:] {
|
||||||
|
// switch a := arg.(type) {
|
||||||
|
// case *kern.DictType:
|
||||||
|
// for keyAny, item := range *a {
|
||||||
|
// if key, ok := keyAny.(string); ok {
|
||||||
|
// args[key] = item
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// default:
|
||||||
|
// args["arg"+strconv.Itoa(i+1)] = arg
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else if op == nil {
|
||||||
|
// return nil, fmt.Errorf("the first sibling parameter must be a functor to be used as operation for the iterator")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// v, err = NewIterIter(it, ctx, op, args)
|
||||||
|
// }
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
func evalSiblings(ctx kern.ExprContext, terms []*scan.Term, firstChildValue any) (list []any, err error) {
|
||||||
items := make([]any, 0, len(terms))
|
items := make([]any, 0, len(terms))
|
||||||
for i, tree := range terms {
|
for i, tree := range terms {
|
||||||
var param any
|
var param any
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-list.go
|
// operand-list.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-literal.go
|
// operand-literal.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-selector-case.go
|
// operand-selector-case.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-var.go
|
// operand-var.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserightChilded.
|
// All rights reserightChilded.
|
||||||
|
|
||||||
// operator-assign.go
|
// operator-assign.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-bitwise.go
|
// operator-bitwise.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-bool.go
|
// operator-bool.go
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-builtin.go
|
// operator-builtin.go
|
||||||
@@ -37,7 +37,7 @@ func evalBuiltin(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
} else {
|
} else {
|
||||||
var moduleSpec any
|
var moduleSpec any
|
||||||
var it kern.Iterator
|
var it kern.Iterator
|
||||||
if it, err = NewIterator(childValue); err != nil {
|
if it, err = NewIterator(ctx, childValue, nil); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for moduleSpec, err = it.Next(); err == nil; moduleSpec, err = it.Next() {
|
for moduleSpec, err = it.Next(); err == nil; moduleSpec, err = it.Next() {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-but.go
|
// operator-but.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-context-value.go
|
// operator-context-value.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-ctrl.go
|
// operator-ctrl.go
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-default.go
|
// operator-default.go
|
||||||
@@ -111,7 +111,7 @@ func evalAssignDefault(ctx kern.ExprContext, opTerm *scan.Term) (v any, err erro
|
|||||||
if functor, ok := rightValue.(kern.Functor); ok {
|
if functor, ok := rightValue.(kern.Functor); ok {
|
||||||
//ctx.RegisterFunc(leftTerm.source(), functor, 0, -1)
|
//ctx.RegisterFunc(leftTerm.source(), functor, 0, -1)
|
||||||
ctx.RegisterFunc(leftTerm.Source(), functor, kern.TypeAny, []kern.ExprFuncParam{
|
ctx.RegisterFunc(leftTerm.Source(), functor, kern.TypeAny, []kern.ExprFuncParam{
|
||||||
NewFuncParamFlag(kern.ParamValue, PfDefault|PfRepeat),
|
kern.NewFuncParamFlag(kern.ParamValue, kern.PfDefault|kern.PfRepeat),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
v = rightValue
|
v = rightValue
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-digest.go
|
// operator-digest.go
|
||||||
@@ -37,7 +37,7 @@ func evalDigest(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if it, err = NewIterator(leftValue); err != nil {
|
if it, err = NewIterator(ctx, leftValue, nil); err != nil {
|
||||||
return nil, fmt.Errorf("left operand of DIGEST must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
return nil, fmt.Errorf("left operand of DIGEST must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-dot.go
|
// operator-dot.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-fact.go
|
// operator-fact.go
|
||||||
|
|||||||
+6
-3
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-filter.go
|
// operator-filter.go
|
||||||
@@ -28,6 +28,7 @@ func evalFilter(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
var leftValue, rightValue any
|
var leftValue, rightValue any
|
||||||
var it kern.Iterator
|
var it kern.Iterator
|
||||||
var item any
|
var item any
|
||||||
|
var ok bool
|
||||||
|
|
||||||
if err = opTerm.CheckOperands(); err != nil {
|
if err = opTerm.CheckOperands(); err != nil {
|
||||||
return
|
return
|
||||||
@@ -37,8 +38,10 @@ func evalFilter(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if it, err = NewIterator(leftValue); err != nil {
|
if it, ok = leftValue.(kern.Iterator); !ok {
|
||||||
return nil, fmt.Errorf("left operand of FILTER must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
if it, err = NewIterator(ctx, leftValue, nil); err != nil {
|
||||||
|
return nil, fmt.Errorf("left operand of FILTER must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
values := kern.NewListA()
|
values := kern.NewListA()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operand-fraction.go
|
// operand-fraction.go
|
||||||
|
|||||||
+5
-2
@@ -31,6 +31,7 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
var item any
|
var item any
|
||||||
var sKey string
|
var sKey string
|
||||||
var keyByIndex bool
|
var keyByIndex bool
|
||||||
|
var ok bool
|
||||||
|
|
||||||
if err = opTerm.CheckOperands(); err != nil {
|
if err = opTerm.CheckOperands(); err != nil {
|
||||||
return
|
return
|
||||||
@@ -40,8 +41,10 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if it, err = NewIterator(leftValue); err != nil {
|
if it, ok = leftValue.(kern.Iterator); !ok {
|
||||||
return nil, fmt.Errorf("left operand of MAP must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
if it, err = NewIterator(ctx, leftValue, nil); err != nil {
|
||||||
|
return nil, fmt.Errorf("left operand of MAP must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rightTk := opTerm.Children[1].Tk
|
rightTk := opTerm.Children[1].Tk
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-in.go
|
// operator-in.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-include.go
|
// operator-include.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-index.go
|
// operator-index.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-insert.go
|
// operator-insert.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-iter-value.go
|
// operator-iter-value.go
|
||||||
|
|||||||
+10
-5
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-join.go
|
// operator-join.go
|
||||||
@@ -28,6 +28,7 @@ func evalJoin(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
var leftValue, rightValue any
|
var leftValue, rightValue any
|
||||||
var itLeft, itRight kern.Iterator
|
var itLeft, itRight kern.Iterator
|
||||||
var item any
|
var item any
|
||||||
|
var ok bool
|
||||||
|
|
||||||
if err = opTerm.CheckOperands(); err != nil {
|
if err = opTerm.CheckOperands(); err != nil {
|
||||||
return
|
return
|
||||||
@@ -41,12 +42,16 @@ func evalJoin(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if itLeft, err = NewIterator(leftValue); err != nil {
|
if itLeft, ok = leftValue.(kern.Iterator); !ok {
|
||||||
return nil, fmt.Errorf("left operand of JOIN must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
if itLeft, err = NewIterator(ctx, leftValue, nil); err != nil {
|
||||||
|
return nil, fmt.Errorf("left operand of JOIN must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if itRight, err = NewIterator(rightValue); err != nil {
|
if itRight, ok = rightValue.(kern.Iterator); !ok {
|
||||||
return nil, fmt.Errorf("right operand of JOIN must be an iterable data-source; got %s", kern.TypeName(rightValue))
|
if itRight, err = NewIterator(ctx, rightValue, nil); err != nil {
|
||||||
|
return nil, fmt.Errorf("right operand of JOIN must be an iterable data-source; got %s", kern.TypeName(rightValue))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
values := kern.NewListA()
|
values := kern.NewListA()
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-length.go
|
// operator-length.go
|
||||||
|
|||||||
+6
-3
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-map.go
|
// operator-map.go
|
||||||
@@ -28,6 +28,7 @@ func evalMap(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
var leftValue, rightValue any
|
var leftValue, rightValue any
|
||||||
var it kern.Iterator
|
var it kern.Iterator
|
||||||
var item any
|
var item any
|
||||||
|
var ok bool
|
||||||
|
|
||||||
if err = opTerm.CheckOperands(); err != nil {
|
if err = opTerm.CheckOperands(); err != nil {
|
||||||
return
|
return
|
||||||
@@ -37,8 +38,10 @@ func evalMap(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if it, err = NewIterator(leftValue); err != nil {
|
if it, ok = leftValue.(kern.Iterator); !ok {
|
||||||
return nil, fmt.Errorf("left operand of MAP must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
if it, err = NewIterator(ctx, leftValue, nil); err != nil {
|
||||||
|
return nil, fmt.Errorf("left operand of MAP must be an iterable data-source; got %s", kern.TypeName(leftValue))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
values := kern.NewListA()
|
values := kern.NewListA()
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-plugin.go
|
// operator-plugin.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-post-inc-dec.go
|
// operator-post-inc-dec.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-pre-inc-dec.go
|
// operator-pre-inc-dec.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-prod.go
|
// operator-prod.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-range.go
|
// operator-range.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-rel.go
|
// operator-rel.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-selector.go
|
// operator-selector.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-shift.go
|
// operator-shift.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-sign.go
|
// operator-sign.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-sum.go
|
// operator-sum.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// operator-unset.go
|
// operator-unset.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// parser.go
|
// parser.go
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// plugin.go
|
// plugin.go
|
||||||
@@ -100,7 +100,7 @@ func importPluginFromSearchPath(ctx kern.ExprContext, name any) (count int, err
|
|||||||
var it kern.Iterator
|
var it kern.Iterator
|
||||||
dirList := buildSearchDirList(ctx, "plugin", ENV_EXPR_PLUGIN_PATH)
|
dirList := buildSearchDirList(ctx, "plugin", ENV_EXPR_PLUGIN_PATH)
|
||||||
count = 0
|
count = 0
|
||||||
if it, err = NewIterator(name); err != nil {
|
if it, err = NewIterator(ctx, name, nil); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for moduleSpec, err = it.Next(); err == nil; moduleSpec, err = it.Next() {
|
for moduleSpec, err = it.Next(); err == nil; moduleSpec, err = it.Next() {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// ast.go
|
// ast.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// expr project scanner.go
|
// expr project scanner.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// Symbol.go
|
// Symbol.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// Symbol.go
|
// Symbol.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// t_scanner_test.go
|
// t_scanner_test.go
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// term-constructor-registry.go
|
// term-constructor-registry.go
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// term.go
|
// term.go
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user