diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-07 16:04:23 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-07 16:04:23 +0100 |
commit | 7162ae8c641314846f0b565d7614ac8d71dbd628 (patch) | |
tree | fba1b545e6d20dac7f958bedf83afc61fcbbc256 /main/command.go | |
parent | 658900fcae610caace83a112ac0ee865108ebc92 (diff) | |
download | stred-go-7162ae8c641314846f0b565d7614ac8d71dbd628.tar |
Add merge command
Diffstat (limited to 'main/command.go')
-rw-r--r-- | main/command.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/main/command.go b/main/command.go index 3f22821..6d75974 100644 --- a/main/command.go +++ b/main/command.go @@ -44,13 +44,47 @@ func (cmd AppendNextCommand) exec(state *ProgramState) { if err != nil { panic("Missing next value") } + + state.prevStart = nextItem.PrevStart + state.start = nextItem.Start + state.end = nextItem.End + state.nextEnd = nextItem.NextEnd + state.value = append(state.value, nextItem.Value) + state.pc++ } func (cmd AppendNextCommand) String() string { return "N" } +type MergeCommand struct {} +func (cmd MergeCommand) exec(state *ProgramState) { + nextItem, err := state.in.Read() + if err != nil { + panic("Missing next value") + } + + state.prevStart = nextItem.PrevStart + state.start = nextItem.Start + state.end = nextItem.End + state.nextEnd = nextItem.NextEnd + + if len(state.value) == 0 { + state.value = []walk.Value {nextItem.Value} + } else { + state.value = append( + state.value[:len(state.value) - 1], + walk.Merge(state.value[len(state.value) - 1], nextItem.Value)... + ) + } + + state.pc++ +} +func (cmd MergeCommand) String() string { + return "m" +} + type DeleteValueCommand struct {} func (cmd DeleteValueCommand) exec(state *ProgramState) { state.value = nil |