diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-19 16:54:53 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-19 16:54:53 +0100 |
commit | 8a9d6ef5970eea2a42ff9eb537f2a3f5e56aec2c (patch) | |
tree | a1bc5863695ecf49cadb133bbdce14a1259e22a6 /main/command.go | |
parent | 1830133215449ebd32751aca7deb9b66663563bd (diff) | |
download | stred-go-8a9d6ef5970eea2a42ff9eb537f2a3f5e56aec2c.tar |
Upgrades the substitute command to also act as a filter
Substitute now captures the command after it and only runs it if the substitution is a success
Diffstat (limited to 'main/command.go')
-rw-r--r-- | main/command.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/main/command.go b/main/command.go index ba6f9dc..ea6fb59 100644 --- a/main/command.go +++ b/main/command.go @@ -107,6 +107,7 @@ func (cmd DeleteAllCommand) exec(state *ProgramState) { type SubstituteCommand struct { subex subex.SubexState + next Command } func (cmd SubstituteCommand) exec(state *ProgramState) { valueStream := make(chan walk.WalkValue) @@ -119,15 +120,19 @@ func (cmd SubstituteCommand) exec(state *ProgramState) { atomStream := walk.Atomise(valueStream) atomsOut, error := subex.RunTransducer(cmd.subex, atomStream) if error { - panic("Error running subex") + return } valuesOut, err := walk.MemoryCompound(atomsOut) if err != nil { - panic("Error compounding atoms") + return } state.value = valuesOut + cmd.next.exec(state) } type Command interface { exec(*ProgramState) -}
\ No newline at end of file +} + +type NoopCommand struct {} +func (cmd NoopCommand) exec(state *ProgramState) {}
\ No newline at end of file |