package main type PrintValueCommand struct {} func (cmd PrintValueCommand) exec(state *ProgramState) { state.out <- state.space } type ToggleTerminalCommand struct {} func (cmd ToggleTerminalCommand) exec(state *ProgramState) { terminal, isTerminal := state.space.value.(TerminalValue) if !isTerminal { return } switch terminal { case ArrayBegin: state.space.value = MapBegin case ArrayEnd: state.space.value = MapEnd case MapBegin: state.space.value = ArrayBegin case MapEnd: state.space.value = ArrayEnd } } type FilteredCommand struct { filter Filter command Command } func (cmd FilteredCommand) exec(state *ProgramState) { if cmd.filter.exec(state) { cmd.command.exec(state) } } type Command interface { exec(*ProgramState) }