stred

Stred: Streaming Tree Editor. Like sed but for JSON
git clone http://shtanton.xyz/git/repo/stred
Log | Files | Refs

commit 1830133215449ebd32751aca7deb9b66663563bd
parent b80b72cfe2e02ce7b9467e161703a47e433f992d
Author: Charlie Stanton <charlie@shtanton.xyz>
Date:   Wed, 19 Apr 2023 16:25:30 +0100

Implements subex substitutions for the value register

Diffstat:
Mmain/command.go | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git 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 {