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.
586 B · 28 lines
Go
at main
12345678910111213141516171819202122232425262728package expression
import ( "git.urbach.dev/cli/q/src/token")
// handleLiteral either adds a leaf to the cursor or becomes the cursor.func handleLiteral(root *Expression, cursor *Expression, t token.Token) (*Expression, *Expression) { if cursor != nil { node := newLeaf(t)
if len(cursor.Children) == 0 { switch cursor.Token.Kind { case token.Range, token.Dot: invalid := New() invalid.Token.Position = cursor.Token.Position cursor.AddChild(invalid) } }
cursor.AddChild(node) } else { cursor = newLeaf(t) root = cursor }
return root, cursor}