<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/command.go49
-rw-r--r--main/main.go13
2 files changed, 34 insertions, 28 deletions
diff --git a/main/command.go b/main/command.go
index 8053b86..511bda8 100644
--- a/main/command.go
+++ b/main/command.go
@@ -7,8 +7,12 @@ import (
type PrintValueCommand struct {}
func (cmd PrintValueCommand) exec(state *ProgramState) {
- for _, item := range state.space {
- state.out <- item
+ path := walk.PathFromWalkValues(state.path)
+ for _, value := range state.value {
+ state.out <- walk.WalkItem {
+ Value: value,
+ Path: path,
+ }
}
}
@@ -21,12 +25,12 @@ func (cmd ToggleTerminalCommand) exec(state *ProgramState) {
walk.MapEnd: walk.ArrayEnd,
}
- for i := range state.space {
- terminal, isTerminal := state.space[i].Value.(walk.TerminalValue)
+ for i := range state.value {
+ terminal, isTerminal := state.value[i].(walk.TerminalValue)
if !isTerminal {
continue
}
- state.space[i].Value = toggled[terminal]
+ state.value[i] = toggled[terminal]
}
}
@@ -35,8 +39,12 @@ type FilteredCommand struct {
command Command
}
func (cmd FilteredCommand) exec(state *ProgramState) {
- for _, item := range state.space {
- if cmd.filter.exec(item) {
+ path := walk.PathFromWalkValues(state.path)
+ for _, value := range state.value {
+ if cmd.filter.exec(walk.WalkItem {
+ Value: value,
+ Path: path,
+ }) {
cmd.command.exec(state)
return
}
@@ -56,38 +64,30 @@ type AppendLiteralCommand struct {
values []walk.WalkValue
}
func (cmd AppendLiteralCommand) exec(state *ProgramState) {
- for _, value := range cmd.values {
- state.space = append(state.space, walk.WalkItem {
- Path: nil,
- Value: value,
- })
- }
+ state.value = append(state.value, cmd.values...)
}
type PrependLiteralCommand struct {
values []walk.WalkValue
}
func (cmd PrependLiteralCommand) exec(state *ProgramState) {
- var newItems []walk.WalkItem
- for _, value := range cmd.values {
- newItems = append(newItems, walk.WalkItem {
- Path: nil,
- Value: value,
- })
- }
- state.space = append(newItems, state.space...)
+ var newItems []walk.WalkValue
+ newItems = append(newItems, cmd.values...)
+ state.value = append(newItems, state.value...)
}
type NextCommand struct {}
func (cmd NextCommand) exec(state *ProgramState) {
nextItem := <- state.in
- state.space = []walk.WalkItem{nextItem}
+ state.value = []walk.WalkValue{nextItem.Value}
+ state.path = nextItem.Path.ToWalkValues()
}
type AppendNextCommand struct {}
func (cmd AppendNextCommand) exec(state *ProgramState) {
nextItem := <- state.in
- state.space = append(state.space, nextItem)
+ state.value = append(state.value, nextItem.Value)
+ state.path = nextItem.Path.ToWalkValues()
}
type PrintLiteralsCommand struct {
@@ -101,7 +101,8 @@ func (cmd PrintLiteralsCommand) exec(state *ProgramState) {
type DeleteAllCommand struct {}
func (cmd DeleteAllCommand) exec(state *ProgramState) {
- state.space = nil
+ state.path = nil
+ state.value = nil
}
type SubstituteCommand struct {
diff --git a/main/main.go b/main/main.go
index 902c5b9..923ffa6 100644
--- a/main/main.go
+++ b/main/main.go
@@ -9,7 +9,7 @@ import (
type Program []Command
type ProgramState struct {
- space []walk.WalkItem
+ path, value, xreg []walk.WalkValue
in chan walk.WalkItem
out chan walk.WalkItem
program []Command
@@ -50,13 +50,18 @@ func main() {
go func () {
for walkItem := range dataStream {
- state.space = []walk.WalkItem{walkItem}
+ state.value = []walk.WalkValue{walkItem.Value}
+ state.path = walkItem.Path.ToWalkValues()
for _, cmd := range state.program {
cmd.exec(&state)
}
if !quiet {
- for _, item := range state.space {
- state.out <- item
+ path := walk.PathFromWalkValues(state.path)
+ for _, value := range state.value {
+ state.out <- walk.WalkItem {
+ Value: value,
+ Path: path,
+ }
}
}
}