diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-23 20:25:49 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-23 20:25:49 +0100 |
commit | 7084f5e1ceb61eab199512410048ad53e3ea08d7 (patch) | |
tree | 54db2851f4eb4b06998e00173d0bf30b9991d43f /main/command.go | |
parent | 663dd2ede81e6415a3c16a46d8e9cfa2e209238f (diff) | |
download | stred-go-7084f5e1ceb61eab199512410048ad53e3ea08d7.tar |
Add full merge command
Diffstat (limited to 'main/command.go')
-rw-r--r-- | main/command.go | 33 |
1 files changed, 31 insertions, 2 deletions
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" |