SHS/pkg/shsh/debug.go

58 lines
1,022 B
Go
Raw Normal View History

package shsh
import (
"collections"
)
func FmtToken(arg *Token) string {
suffix := ""
if arg.next != nil {
suffix = "->"
}
switch arg.tag {
case LIST:
return sprintf("(%s, List @ %p, %d)%s", "LIST", arg._inner,
arg.position, suffix)
default:
return sprintf("(%s, %s, %d)%s", GetTagAsStr(arg.tag), arg._inner,
arg.position, suffix)
}
}
func GetTagAsStr(tag token_t) string {
switch tag {
case LIST:
return "LIST"
case STRING:
return "STRING"
case NUMBER:
return "NUMBER"
case SYMBOL:
return "SYMBOL"
}
}
func PrintSExpression(arg *Token) {
var lists Stack;
lists.push(arg)
loop:
// string builder?
i := lists.pop()
if i == nil {
goto done
}
for (iter := i; iter != nil; iter = i.next {
// add each string to string builder?
}
// print stringbuilder?
goto loop
done:
// TODO: Perhaps print some debug analytics here
}