From 7162ae8c641314846f0b565d7614ac8d71dbd628 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 7 Apr 2024 16:04:23 +0100 Subject: Add merge command --- main/command.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'main/command.go') 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 -- cgit v1.2.3