From f6e27ecd8881498776428c0ae5b674f65192058e Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 21 Apr 2024 17:30:05 +0100 Subject: Modify merge to no longer read a new value Now just merges the last two values in the space --- main/command.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'main/command.go') diff --git a/main/command.go b/main/command.go index 04ac7f6..736dce5 100644 --- a/main/command.go +++ b/main/command.go @@ -119,24 +119,16 @@ func (cmd SubstituteAppendNextCommand) String() string { type MergeCommand struct {} func (cmd MergeCommand) exec(state *ProgramState) { - nextItem, err := state.Read() - if err != nil { - panic("Missing next value") + if len(state.value) <= 1 { + state.pc++ + return } - 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)... - ) - } + newVals := walk.Merge(state.value[len(state.value) - 2], state.value[len(state.value) - 1]) + state.value = append( + state.value[:len(state.value) - 2], + newVals... + ) state.pc++ } -- cgit v1.2.3