Implemented expression parsing

This commit is contained in:
2024-06-16 16:57:33 +02:00
parent 864c9c7b43
commit ef16bdb4c7
18 changed files with 618 additions and 99 deletions

View File

@ -0,0 +1,41 @@
package expression
import (
"git.akyoto.dev/cli/q/src/build/token"
)
// List generates a list of expressions from comma separated parameters.
func List(tokens []token.Token) []*Expression {
var list []*Expression
start := 0
groupLevel := 0
for i, t := range tokens {
switch t.Kind {
case token.GroupStart, token.ArrayStart, token.BlockStart:
groupLevel++
case token.GroupEnd, token.ArrayEnd, token.BlockEnd:
groupLevel--
case token.Separator:
if groupLevel > 0 {
continue
}
parameter := tokens[start:i]
expression := Parse(parameter)
list = append(list, expression)
start = i + 1
}
}
if start != len(tokens) {
parameter := tokens[start:]
expression := Parse(parameter)
list = append(list, expression)
}
return list
}