Implemented expression parsing
This commit is contained in:
41
src/build/expression/List.go
Normal file
41
src/build/expression/List.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user