refactored print loop, project structure
This commit is contained in:
parent
aaa0a8a507
commit
b0d9bb4643
9 changed files with 14 additions and 25 deletions
BIN
.token.go.swp
BIN
.token.go.swp
Binary file not shown.
0
License
Normal file
0
License
Normal file
0
Makefile
Normal file
0
Makefile
Normal file
0
Readme
Normal file
0
Readme
Normal file
11
cmd/print_ast.go
Normal file
11
cmd/print_ast.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"os"
|
||||
"git.callpipe.com/aidan/shsh"
|
||||
)
|
||||
|
||||
func main() {
|
||||
shsh.PrintSExpression(shsh.Lex(strings.Join(os.Args[1:], " ")))
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"git.callpipe.com/aidan/shsh"
|
||||
)
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
shsh.PrintSExpression(shsh.Lex(scanner.Text()))
|
||||
}
|
||||
}
|
||||
12
debug.go
12
debug.go
|
|
@ -13,12 +13,10 @@ func FmtToken(arg *Token) string {
|
|||
|
||||
switch arg.tag {
|
||||
case LIST:
|
||||
return fmt.Sprintf("(%s, List @ %p, %d)%s", "LIST", arg._inner,
|
||||
arg.position, suffix)
|
||||
return fmt.Sprintf("(%s, List @ %p)%s", "LIST", arg._inner, suffix)
|
||||
|
||||
default:
|
||||
return fmt.Sprintf("(%s, %s, %d)%s", GetTagAsStr(arg.tag), arg._inner,
|
||||
arg.position, suffix)
|
||||
return fmt.Sprintf("(%s, %s)%s", GetTagAsStr(arg.tag), arg._inner, suffix)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,12 +52,6 @@ loop:
|
|||
for iter := i; iter != nil; iter = iter.next {
|
||||
if iter.tag == LIST {
|
||||
lists.Push(iter._inner.(*Token))
|
||||
constructor.WriteString(FmtToken(&Token{
|
||||
next: iter.next,
|
||||
tag: STRING,
|
||||
position: iter.position,
|
||||
_inner: "[LIST]"}))
|
||||
continue
|
||||
}
|
||||
|
||||
constructor.WriteString(FmtToken(iter))
|
||||
|
|
|
|||
BIN
shsh
BIN
shsh
Binary file not shown.
2
token.go
2
token.go
|
|
@ -26,9 +26,9 @@ func Lex(input string) *Token {
|
|||
}
|
||||
|
||||
var ret *Token
|
||||
var tok strings.Builder
|
||||
iter := &ret
|
||||
delim := ' '
|
||||
var tok strings.Builder
|
||||
is_list := false
|
||||
is_str := false
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue