Implemented array storage

This commit is contained in:
2024-07-20 17:35:26 +02:00
parent d35c07ed1c
commit 155df7c44c
17 changed files with 150 additions and 45 deletions

View File

@ -6,7 +6,10 @@ import (
"git.akyoto.dev/cli/q/src/build/token"
)
var call = []byte("λ")
var (
call = []byte("λ")
array = []byte("@")
)
// Parse generates an expression tree from tokens.
func Parse(tokens token.List) *Expression {
@ -18,7 +21,7 @@ func Parse(tokens token.List) *Expression {
)
for i, t := range tokens {
if t.Kind == token.GroupStart {
if t.Kind == token.GroupStart || t.Kind == token.ArrayStart {
groupLevel++
if groupLevel == 1 {
@ -28,23 +31,30 @@ func Parse(tokens token.List) *Expression {
continue
}
if t.Kind == token.GroupEnd {
if t.Kind == token.GroupEnd || t.Kind == token.ArrayEnd {
groupLevel--
if groupLevel != 0 {
continue
}
isFunctionCall := isComplete(cursor)
if isFunctionCall {
// Function call or array access
if isComplete(cursor) {
parameters := NewList(tokens[groupPosition:i])
node := New()
node.Token.Kind = token.Operator
node.Token.Position = tokens[groupPosition].Position
node.Token.Bytes = call
node.Precedence = precedence("λ")
switch t.Kind {
case token.GroupEnd:
node.Token.Bytes = call
node.Precedence = precedence("λ")
case token.ArrayEnd:
node.Token.Bytes = array
node.Precedence = precedence("@")
}
if cursor.Token.Kind == token.Operator && node.Precedence > cursor.Precedence {
cursor.LastChild().Replace(node)