From ececdecdaf6c6f6295d31a92f0663d703e7760dd Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Tue, 23 Aug 2022 22:09:14 +0100 Subject: Initial commit No parsing yet, but the execution is not bad Commands: - Print value - Toggle terminal (switch between array and map) - Filter command Filters: - Path filter Path filters are compiled from a regex like AST --- main/command.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 main/command.go (limited to 'main/command.go') diff --git a/main/command.go b/main/command.go new file mode 100644 index 0000000..560d3c3 --- /dev/null +++ b/main/command.go @@ -0,0 +1,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) +} \ No newline at end of file -- cgit v1.2.3