fleshed out GetVar, added Token stack collection, started printing module
This commit is contained in:
parent
516fda54b3
commit
84013cb4a0
6 changed files with 89 additions and 2 deletions
57
pkg/shsh/debug.go
Normal file
57
pkg/shsh/debug.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue