Reduced token size

This commit is contained in:
2024-07-21 14:35:06 +02:00
parent ca36d34cb9
commit 04ba68a075
47 changed files with 543 additions and 764 deletions

View File

@ -3,31 +3,31 @@ package ast
import "git.akyoto.dev/cli/q/src/build/token"
// Count counts how often the given token appears in the AST.
func Count(body AST, kind token.Kind, name string) int {
func Count(body AST, buffer []byte, kind token.Kind, name string) int {
count := 0
for _, node := range body {
switch node := node.(type) {
case *Assign:
count += node.Expression.Count(kind, name)
count += node.Expression.Count(buffer, kind, name)
case *Call:
count += node.Expression.Count(kind, name)
count += node.Expression.Count(buffer, kind, name)
case *Define:
count += node.Value.Count(kind, name)
count += node.Value.Count(buffer, kind, name)
case *Return:
if node.Value != nil {
count += node.Value.Count(kind, name)
count += node.Value.Count(buffer, kind, name)
}
case *If:
count += node.Condition.Count(kind, name)
count += Count(node.Body, kind, name)
count += node.Condition.Count(buffer, kind, name)
count += Count(node.Body, buffer, kind, name)
case *Loop:
count += Count(node.Body, kind, name)
count += Count(node.Body, buffer, kind, name)
default:
panic("unknown AST type")