diff options
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 |