diff options
| author | Charlie Stanton <charlie@shtanton.xyz> | 2023-02-19 09:27:55 +0000 | 
|---|---|---|
| committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-02-19 09:27:55 +0000 | 
| commit | 3bd45dc49a35b82dcc4ae93796c3e152d799bc0b (patch) | |
| tree | 3a681ac5dbd777d2b6b116429cfbd934815661ce /main/command.go | |
| parent | a5a4db8283fda88c5bd42272de0258e5d134c5bd (diff) | |
| download | stred-go-3bd45dc49a35b82dcc4ae93796c3e152d799bc0b.tar | |
Move JSON serialising, deserialising and walking code into a separate package
Diffstat (limited to 'main/command.go')
| -rw-r--r-- | main/command.go | 40 | 
1 files changed, 22 insertions, 18 deletions
diff --git a/main/command.go b/main/command.go index 91cb5e4..c61b0cd 100644 --- a/main/command.go +++ b/main/command.go @@ -1,5 +1,9 @@  package main +import ( +	"main/walk" +) +  type PrintValueCommand struct {}  func (cmd PrintValueCommand) exec(state *ProgramState) {  	for _, item := range state.space { @@ -9,19 +13,19 @@ func (cmd PrintValueCommand) exec(state *ProgramState) {  type ToggleTerminalCommand struct {}  func (cmd ToggleTerminalCommand) exec(state *ProgramState) { -	toggled := map[TerminalValue]TerminalValue { -		ArrayBegin: MapBegin, -		ArrayEnd: MapEnd, -		MapBegin: ArrayBegin, -		MapEnd: ArrayEnd, +	toggled := map[walk.TerminalValue]walk.TerminalValue { +		walk.ArrayBegin: walk.MapBegin, +		walk.ArrayEnd: walk.MapEnd, +		walk.MapBegin: walk.ArrayBegin, +		walk.MapEnd: walk.ArrayEnd,  	}  	for i := range state.space { -		terminal, isTerminal := state.space[i].value.(TerminalValue) +		terminal, isTerminal := state.space[i].Value.(walk.TerminalValue)  		if !isTerminal {  			continue  		} -		state.space[i].value = toggled[terminal] +		state.space[i].Value = toggled[terminal]  	}  } @@ -48,26 +52,26 @@ func (cmd SequenceCommand) exec(state *ProgramState) {  }  type AppendLiteralCommand struct { -	values []WalkValue +	values []walk.WalkValue  }  func (cmd AppendLiteralCommand) exec(state *ProgramState) {  	for _, value := range cmd.values { -		state.space = append(state.space, WalkItem { -			path: nil, -			value: value, +		state.space = append(state.space, walk.WalkItem { +			Path: nil, +			Value: value,  		})  	}  }  type PrependLiteralCommand struct { -	values []WalkValue +	values []walk.WalkValue  }  func (cmd PrependLiteralCommand) exec(state *ProgramState) { -	var newItems []WalkItem +	var newItems []walk.WalkItem  	for _, value := range cmd.values { -		newItems = append(newItems, WalkItem { -			path: nil, -			value: value, +		newItems = append(newItems, walk.WalkItem { +			Path: nil, +			Value: value,  		})  	}  	state.space = append(newItems, state.space...) @@ -76,7 +80,7 @@ func (cmd PrependLiteralCommand) exec(state *ProgramState) {  type NextCommand struct {}  func (cmd NextCommand) exec(state *ProgramState) {  	nextItem := <- state.in -	state.space = []WalkItem{nextItem} +	state.space = []walk.WalkItem{nextItem}  }  type AppendNextCommand struct {} @@ -86,7 +90,7 @@ func (cmd AppendNextCommand) exec(state *ProgramState) {  }  type PrintLiteralsCommand struct { -	items []WalkItem +	items []walk.WalkItem  }  func (cmd PrintLiteralsCommand) exec(state *ProgramState) {  	for _, item := range cmd.items {  | 
