stred

Stred: Streaming Tree Editor. Like sed but for JSON
git clone http://shtanton.xyz/git/repo/stred
Log | Files | Refs

commit 6a77b63c3cd4edb992b94e42c5a222a1480a3f33
parent 773c5e115fbb4e8b432e95e02216af9b23415ca8
Author: Charlie Stanton <charlie@shtanton.xyz>
Date:   Thu, 20 Apr 2023 09:25:51 +0100

Add commands to append to and swap with the path and X registers

Diffstat:
Mmain/command.go | 28++++++++++++++++++++++++++--
Mmain/parse.go | 8++++++++
2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/main/command.go b/main/command.go @@ -135,4 +135,28 @@ type Command interface { } type NoopCommand struct {} -func (cmd NoopCommand) exec(state *ProgramState) {} -\ No newline at end of file +func (cmd NoopCommand) exec(state *ProgramState) {} + +type SwapXRegCommand struct {} +func (cmd SwapXRegCommand) exec(state *ProgramState) { + v := state.value + state.value = state.xreg + state.xreg = v +} + +type AppendXRegCommand struct {} +func (cmd AppendXRegCommand) exec(state *ProgramState) { + state.xreg = append(state.xreg, state.value...) +} + +type SwapPathCommand struct {} +func (cmd SwapPathCommand) exec(state *ProgramState) { + v := state.value + state.value = state.path + state.path = v +} + +type AppendPathCommand struct {} +func (cmd AppendPathCommand) exec(state *ProgramState) { + state.path = append(state.path, state.value...) +} +\ No newline at end of file diff --git a/main/parse.go b/main/parse.go @@ -251,6 +251,14 @@ func (p *parser) parseBasicCommand(commandChar rune) Command { return PrintLiteralsCommand {items: items} case 'o': return NoopCommand{} + case 'x': + return SwapXRegCommand{} + case 'X': + return AppendXRegCommand{} + case 'k': + return SwapPathCommand{} + case 'K': + return AppendPathCommand{} default: panic("Invalid command") }