Added token package
All checks were successful
/ test (push) Successful in 15s

This commit is contained in:
Eduard Urbach 2025-06-19 15:58:29 +02:00
parent 38bd387002
commit 1405d2b8b1
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
18 changed files with 1500 additions and 0 deletions

61
src/token/Instructions.go Normal file
View file

@ -0,0 +1,61 @@
package token
// Instructions yields on each AST node.
func (list List) Instructions(yield func(List) bool) {
start := 0
groupLevel := 0
blockLevel := 0
for i, t := range list {
switch t.Kind {
case NewLine:
if start == i {
start = i + 1
continue
}
if groupLevel > 0 || blockLevel > 0 {
continue
}
if !yield(list[start:i]) {
return
}
start = i + 1
case GroupStart:
groupLevel++
case GroupEnd:
groupLevel--
case BlockStart:
blockLevel++
case BlockEnd:
blockLevel--
if groupLevel > 0 || blockLevel > 0 {
continue
}
if !yield(list[start : i+1]) {
return
}
start = i + 1
case EOF:
if start < i {
yield(list[start:i])
}
return
}
}
if start < len(list) {
yield(list[start:])
}
}