<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-19 16:25:30 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-19 16:25:30 +0100
commit1830133215449ebd32751aca7deb9b66663563bd (patch)
treec7d1b87758dbdada445548d598a7e07e7ecbc8bf /main
parentb80b72cfe2e02ce7b9467e161703a47e433f992d (diff)
downloadstred-go-1830133215449ebd32751aca7deb9b66663563bd.tar
Implements subex substitutions for the value register
Diffstat (limited to 'main')
-rw-r--r--main/command.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/main/command.go b/main/command.go
index 511bda8..ba6f9dc 100644
--- a/main/command.go
+++ b/main/command.go
@@ -109,7 +109,23 @@ type SubstituteCommand struct {
subex subex.SubexState
}
func (cmd SubstituteCommand) exec(state *ProgramState) {
- // TODO
+ valueStream := make(chan walk.WalkValue)
+ go func(in []walk.WalkValue, out chan<- walk.WalkValue) {
+ for _, value := range in {
+ out <- value
+ }
+ close(out)
+ }(state.value, valueStream)
+ atomStream := walk.Atomise(valueStream)
+ atomsOut, error := subex.RunTransducer(cmd.subex, atomStream)
+ if error {
+ panic("Error running subex")
+ }
+ valuesOut, err := walk.MemoryCompound(atomsOut)
+ if err != nil {
+ panic("Error compounding atoms")
+ }
+ state.value = valuesOut
}
type Command interface {