From 7084f5e1ceb61eab199512410048ad53e3ea08d7 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Tue, 23 Apr 2024 20:25:49 +0100 Subject: Add full merge command --- main/command.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'main/command.go') diff --git a/main/command.go b/main/command.go index 38e1c95..e795333 100644 --- a/main/command.go +++ b/main/command.go @@ -138,9 +138,38 @@ func (cmd MergeCommand) String() string { return "m" } -type FullMergeCommand struct {} +type FullMergeCommand struct { + subex subex.Transducer +} func (cmd FullMergeCommand) exec(state *ProgramState) { - panic("Unimplemented") + _, notOk := runSubex(cmd.subex, state.value) + if notOk || state.end { + state.pc++ + return + } + + for { + item, err := state.Read() + if err != nil { + panic("Missing next value") + } + + _, nonTerminal := runSubex(cmd.subex, []walk.Value{item.Value}) + + state.value = append( + state.value[:len(state.value) - 1], + walk.Merge(state.value[len(state.value) - 1], item.Value)... + ) + + if !nonTerminal && item.End { + state.prevStart = item.PrevStart + state.start = item.Start + state.end = item.End + state.nextEnd = item.NextEnd + state.pc += 2 + return + } + } } func (cmd FullMergeCommand) String() string { return "M" -- cgit v1.2.3