diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-05-12 11:37:44 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-05-12 11:37:44 +0100 |
commit | 551613765c9e60e2221ac920d2756b949e68f373 (patch) | |
tree | ac579a9e0d6c015edca694880f259c8dac4d7a04 /main/main.go | |
parent | e98ebbad387def55d8347adb5bf45034d542cce0 (diff) | |
download | stred-go-551613765c9e60e2221ac920d2756b949e68f373.tar |
Move reading and writing of tokens into a separate package to prepare for other input and output formats
Diffstat (limited to 'main/main.go')
-rw-r--r-- | main/main.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/main/main.go b/main/main.go index 55ed5b5..668253d 100644 --- a/main/main.go +++ b/main/main.go @@ -4,14 +4,15 @@ import ( "os" "bufio" "main/walk" + "main/json_tokens" ) type Program []Command type ProgramState struct { path, value, xreg, yreg, zreg []walk.Atom - in walk.JSONIn - out walk.JSONOut + in walk.StredReader + out walk.StredWriter program []Command pc int } @@ -44,8 +45,8 @@ func main() { stdout := bufio.NewWriter(os.Stdout) state := ProgramState { - in: walk.NewJSONIn(stdin), - out: walk.NewJSONOut(stdout), + in: json_tokens.NewJSONIn(stdin), + out: json_tokens.NewJSONOut(stdout), program: program, } @@ -61,12 +62,13 @@ func main() { state.program[state.pc].exec(&state) } if !quiet { - pathValues, err := walk.Compound(state.path) + err := state.out.Write(walk.WalkItem { + Path: state.path, + Value: state.value, + }) if err != nil { - panic("Tried to convert invalid atoms to values") + panic("Error while outputting") } - path := walk.PathFromWalkValues(pathValues) - state.out.Print(path, state.value) } } |