Compare commits

...

2 Commits

Author SHA1 Message Date
8ab2c28343 EvalArg -> Arg 2024-04-09 06:13:12 +02:00
c4a2fcce3d README.adoc: proofreading 2024-04-09 05:42:50 +02:00
3 changed files with 10 additions and 8 deletions

View File

@ -58,6 +58,8 @@ A few examples to get started.
[source,go] [source,go]
---- ----
package main
import ( import (
"fmt" "fmt"
"strings" "strings"
@ -213,7 +215,7 @@ Currently, boolean operations are evaluated using _short cut evaluation_. This m
#TODO: List operations# #TODO: List operations#
=== Variables === Variables
#TODO: List operations# #TODO: variables#
=== Other operations === Other operations
@ -307,13 +309,13 @@ The table below shows all supported operators by decreasing priorities.
=== Functions === Functions
==== Function calls ==== Function calls
#TODO: List operations# #TODO: function calls operations#
==== Function definitions ==== Function definitions
#TODO: List operations# #TODO: function definitions operations#
==== Builtins ==== Builtins
#TODO: List operations# #TODO: builtins#

View File

@ -19,16 +19,16 @@ func EvalString(ctx ExprContext, source string) (result any, err error) {
return return
} }
type EvalArg struct { type Arg struct {
name string name string
value any value any
} }
func EvalStringA(source string, args ...EvalArg) (result any, err error) { func EvalStringA(source string, args ...Arg) (result any, err error) {
return EvalStringV(source, args) return EvalStringV(source, args)
} }
func EvalStringV(source string, args []EvalArg) (result any, err error) { func EvalStringV(source string, args []Arg) (result any, err error) {
ctx := NewSimpleFuncStore() ctx := NewSimpleFuncStore()
for _, arg := range args { for _, arg := range args {
if isFunc(arg.value) { if isFunc(arg.value) {

View File

@ -24,7 +24,7 @@ func subtract(ctx ExprContext, name string, args []any) (result any, err error)
func TestEvalStringA(t *testing.T) { func TestEvalStringA(t *testing.T) {
source := `a + b * subtract(4,2)` source := `a + b * subtract(4,2)`
args := []EvalArg{ args := []Arg{
{"a", uint8(1)}, {"a", uint8(1)},
{"b", int8(2)}, {"b", int8(2)},
{"subtract", FuncTemplate(subtract)}, {"subtract", FuncTemplate(subtract)},