Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
2.1 kB · 99 lines
Go
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899package expression
import ( "math"
"git.urbach.dev/cli/q/src/token")
// handleGroupEnd handles anything that uses a group like a function call or an array access.func handleGroupEnd(tokens token.List, root *Expression, cursor *Expression, groupPosition uint, i uint, t token.Token) (*Expression, *Expression) { if isComplete(cursor) { node := New()
switch t.Kind { case token.GroupEnd: node.Token.Kind = token.Call case token.ArrayEnd: node.Token.Kind = token.Array case token.BlockEnd: node.Token.Kind = token.Struct }
node.precedence = precedence(node.Token.Kind) coverGroup(node, tokens, groupPosition, t) identifier := cursor
if cursor.Token.Kind.IsOperator() && node.precedence > cursor.precedence { identifier = cursor.LastChild() } else if cursor == root { root = node }
identifier.InsertAbove(node)
if identifier.Token.Kind == token.New { separator := tokens[groupPosition:i].IndexKind(token.Separator) end := i
if separator != -1 { end = groupPosition + uint(separator) }
typ := tokens[groupPosition:end]
if len(typ) > 0 { typeToken := makeTypeToken(typ) node.AddChild(newLeaf(typeToken)) }
if separator != -1 { elementCount := Parse(tokens[end+1 : i]) node.AddChild(elementCount) } } else { parameters := NewList(tokens[groupPosition:i])
for _, param := range parameters { node.AddChild(param) } }
cursor = node return root, cursor }
group := Parse(tokens[groupPosition:i]) group.precedence = math.MaxInt8
if t.Kind == token.ArrayEnd { array := New() coverGroup(array, tokens, groupPosition, t) array.Token.Kind = token.Array array.precedence = precedence(token.Array)
if cursor == nil { cursor = array cursor.AddChild(group) root = cursor } else { array.AddChild(group) cursor.AddChild(array) }
return root, cursor }
if !group.Token.Kind.IsLiteral() { coverGroup(group, tokens, groupPosition, t) }
if cursor == nil { cursor = group root = group } else { cursor.AddChild(group) }
return root, cursor}