Implemented parameters

This commit is contained in:
2024-06-27 10:12:41 +02:00
parent 94151773a5
commit 8e64271f74
6 changed files with 76 additions and 27 deletions

View File

@ -5,9 +5,20 @@ import (
)
// List generates a list of expressions from comma separated parameters.
func List(tokens []token.Token) []*Expression {
func List(tokens token.List) []*Expression {
var list []*Expression
EachParameter(tokens, func(parameter token.List) error {
expression := Parse(parameter)
list = append(list, expression)
return nil
})
return list
}
// EachParameter calls the callback function on each parameter in a comma separated list.
func EachParameter(tokens token.List, call func(token.List) error) error {
start := 0
groupLevel := 0
@ -25,17 +36,20 @@ func List(tokens []token.Token) []*Expression {
}
parameter := tokens[start:i]
expression := Parse(parameter)
list = append(list, expression)
err := call(parameter)
if err != nil {
return err
}
start = i + 1
}
}
if start != len(tokens) {
parameter := tokens[start:]
expression := Parse(parameter)
list = append(list, expression)
return call(parameter)
}
return list
return nil
}