<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/subexstate.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-02-26 09:37:30 +0000
committerCharlie Stanton <charlie@shtanton.xyz>2023-02-26 09:37:30 +0000
commit7b63b7c9d03b23f496ec9bfb8e91be3693b19a8f (patch)
tree824aa1c659e532537f812be36d0e0384eae1b2fd /subex/subexstate.go
parent9ba3b1d97e8fd2a2e3c4bb08fe350c8dd5f9733e (diff)
downloadstred-go-7b63b7c9d03b23f496ec9bfb8e91be3693b19a8f.tar
Replace append with walk.ConcatData in many places to fix bug to do with semantics of append
When doing append, be very careful as it does make changes in place to the underlying array of the slice which may affect other slices
Diffstat (limited to 'subex/subexstate.go')
-rw-r--r--subex/subexstate.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/subex/subexstate.go b/subex/subexstate.go
index 9e0d61a..415714f 100644
--- a/subex/subexstate.go
+++ b/subex/subexstate.go
@@ -35,7 +35,7 @@ type SubexStoreState struct {
func (state SubexStoreState) eat(store Store, char walk.Datum) (nextStates []SubexBranch) {
acceptedOutputs := state.match.accepting(store)
for _, acceptedOutput := range acceptedOutputs {
- nextStore := store.withValue(state.slot, append(state.toStore, acceptedOutput...))
+ nextStore := store.withValue(state.slot, walk.ConcatData(state.toStore, acceptedOutput))
nextStates = append(nextStates, state.next.eat(nextStore.clone(), char)...)
}
nextMatchStates := state.match.eat(store.clone(), char)
@@ -45,7 +45,7 @@ func (state SubexStoreState) eat(store Store, char walk.Datum) (nextStates []Sub
match: matchState.state,
slot: state.slot,
next: state.next,
- toStore: append(state.toStore, matchState.output...),
+ toStore: walk.ConcatData(state.toStore, matchState.output),
},
output: nil,
store: store.clone(),
@@ -56,7 +56,7 @@ func (state SubexStoreState) eat(store Store, char walk.Datum) (nextStates []Sub
func (state SubexStoreState) accepting(store Store) (outputs [][]walk.Datum) {
acceptedOutputs := state.match.accepting(store)
for _, acceptedOutput := range acceptedOutputs {
- nextStore := store.withValue(state.slot, append(state.toStore, acceptedOutput...))
+ nextStore := store.withValue(state.slot, walk.ConcatData(state.toStore, acceptedOutput))
outputs = append(outputs, state.next.accepting(nextStore)...)
}
return outputs
@@ -79,7 +79,7 @@ func (state SubexOutputState) eat(store Store, char walk.Datum) []SubexBranch {
content := state.build(store)
nextStates := state.next.eat(store, char)
for i := range nextStates {
- nextStates[i].output = append(content, nextStates[i].output...)
+ nextStates[i].output = walk.ConcatData(content, nextStates[i].output)
}
return nextStates
}
@@ -87,7 +87,7 @@ func (state SubexOutputState) accepting(store Store) [][]walk.Datum {
content := state.build(store)
outputs := state.next.accepting(store)
for i := range outputs {
- outputs[i] = append(content, outputs[i]...)
+ outputs[i] = walk.ConcatData(content, outputs[i])
}
return outputs
}