<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/command.go
blob: 560d3c319c21518dfc487ea2962e95df6100c9bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)
}