<- Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/main/subexstate.go
diff options
context:
space:
mode:
Diffstat (limited to 'main/subexstate.go')
-rw-r--r--main/subexstate.go32
1 files changed, 17 insertions, 15 deletions
diff --git a/main/subexstate.go b/main/subexstate.go
index cc697f0..00b9e75 100644
--- a/main/subexstate.go
+++ b/main/subexstate.go
@@ -21,25 +21,25 @@ func (state SubexGroupState) accepting(store Store) []string {
}
type SubexStoreState struct {
- match RegexState
+ match SubexState
slot rune
next SubexState
- input string
+ toStore string
}
-func (state SubexStoreState) eat(store Store, char rune) []SubexBranch {
- var nextStates []SubexBranch
- if state.match.accepting() {
- store[state.slot] = state.input
- nextStates = state.next.eat(store, char)
+func (state SubexStoreState) eat(store Store, char rune) (nextStates []SubexBranch) {
+ acceptedOutputs := state.match.accepting(store)
+ for _, acceptedOutput := range acceptedOutputs {
+ nextStore := store.withValue(state.slot, state.toStore + acceptedOutput)
+ nextStates = append(nextStates, state.next.eat(nextStore.clone(), char)...)
}
- nextRegexStates := state.match.eat(char)
- for _, regexState := range nextRegexStates {
+ nextMatchStates := state.match.eat(store.clone(), char)
+ for _, matchState := range nextMatchStates {
nextStates = append(nextStates, SubexBranch {
state: SubexStoreState {
- match: regexState,
+ match: matchState.state,
slot: state.slot,
next: state.next,
- input: state.input + string(char),
+ toStore: state.toStore + matchState.output,
},
output: "",
store: store.clone(),
@@ -47,11 +47,13 @@ func (state SubexStoreState) eat(store Store, char rune) []SubexBranch {
}
return nextStates
}
-func (state SubexStoreState) accepting(store Store) []string {
- if state.match.accepting() {
- return state.next.accepting(store)
+func (state SubexStoreState) accepting(store Store) (outputs []string) {
+ acceptedOutputs := state.match.accepting(store)
+ for _, acceptedOutput := range acceptedOutputs {
+ nextStore := store.withValue(state.slot, state.toStore + acceptedOutput)
+ outputs = append(outputs, state.next.accepting(nextStore)...)
}
- return nil
+ return outputs
}
type SubexOutputState struct {