<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/subexstate.go
diff options
context:
space:
mode:
Diffstat (limited to 'subex/subexstate.go')
-rw-r--r--subex/subexstate.go65
1 files changed, 32 insertions, 33 deletions
diff --git a/subex/subexstate.go b/subex/subexstate.go
index 415714f..12ace42 100644
--- a/subex/subexstate.go
+++ b/subex/subexstate.go
@@ -6,21 +6,21 @@ import (
// A state of execution for the transducer
type SubexState interface {
- // Eat a datum and transition to any number of new states
- eat(store Store, char walk.Datum) []SubexBranch
+ // Eat a Atom and transition to any number of new states
+ eat(store Store, char walk.Atom) []SubexBranch
// Find accepting states reachable through epsilon transitions and return their outputs
- accepting(store Store) [][]walk.Datum
+ accepting(store Store) [][]walk.Atom
}
// Try first, if it fails then try second
type SubexGroupState struct {
first, second SubexState
}
-func (state SubexGroupState) eat(store Store, char walk.Datum) []SubexBranch {
+func (state SubexGroupState) eat(store Store, char walk.Atom) []SubexBranch {
otherStore := store.clone()
return append(state.first.eat(store, char), state.second.eat(otherStore, char)...)
}
-func (state SubexGroupState) accepting(store Store) [][]walk.Datum {
+func (state SubexGroupState) accepting(store Store) [][]walk.Atom {
return append(state.first.accepting(store), state.second.accepting(store)...)
}
@@ -30,9 +30,9 @@ type SubexStoreState struct {
match SubexState
slot rune
next SubexState
- toStore []walk.Datum
+ toStore []walk.Atom
}
-func (state SubexStoreState) eat(store Store, char walk.Datum) (nextStates []SubexBranch) {
+func (state SubexStoreState) eat(store Store, char walk.Atom) (nextStates []SubexBranch) {
acceptedOutputs := state.match.accepting(store)
for _, acceptedOutput := range acceptedOutputs {
nextStore := store.withValue(state.slot, walk.ConcatData(state.toStore, acceptedOutput))
@@ -53,7 +53,7 @@ func (state SubexStoreState) eat(store Store, char walk.Datum) (nextStates []Sub
}
return nextStates
}
-func (state SubexStoreState) accepting(store Store) (outputs [][]walk.Datum) {
+func (state SubexStoreState) accepting(store Store) (outputs [][]walk.Atom) {
acceptedOutputs := state.match.accepting(store)
for _, acceptedOutput := range acceptedOutputs {
nextStore := store.withValue(state.slot, walk.ConcatData(state.toStore, acceptedOutput))
@@ -68,14 +68,14 @@ type SubexOutputState struct {
next SubexState
}
// Given a store, return what is outputted by an epsilon transition from this state
-func (state SubexOutputState) build(store Store) []walk.Datum {
- var result []walk.Datum
+func (state SubexOutputState) build(store Store) []walk.Atom {
+ var result []walk.Atom
for _, part := range state.content {
result = append(result, part.build(store)...)
}
return result
}
-func (state SubexOutputState) eat(store Store, char walk.Datum) []SubexBranch {
+func (state SubexOutputState) eat(store Store, char walk.Atom) []SubexBranch {
content := state.build(store)
nextStates := state.next.eat(store, char)
for i := range nextStates {
@@ -83,7 +83,7 @@ func (state SubexOutputState) eat(store Store, char walk.Datum) []SubexBranch {
}
return nextStates
}
-func (state SubexOutputState) accepting(store Store) [][]walk.Datum {
+func (state SubexOutputState) accepting(store Store) [][]walk.Atom {
content := state.build(store)
outputs := state.next.accepting(store)
for i := range outputs {
@@ -94,67 +94,66 @@ func (state SubexOutputState) accepting(store Store) [][]walk.Datum {
// A final state, transitions to nothing but is accepting
type SubexNoneState struct {}
-func (state SubexNoneState) eat(store Store, char walk.Datum) []SubexBranch {
+func (state SubexNoneState) eat(store Store, char walk.Atom) []SubexBranch {
return nil
}
-func (state SubexNoneState) accepting(store Store) [][]walk.Datum {
- return [][]walk.Datum{nil}
+func (state SubexNoneState) accepting(store Store) [][]walk.Atom {
+ return [][]walk.Atom{nil}
}
-// Read in a specific datum and output it
-// TODO rename to better reflect datum instead of rune
-type SubexCopyRuneState struct {
- rune walk.Datum
+// Read in a specific Atom and output it
+type SubexCopyAtomState struct {
+ atom walk.Atom
next SubexState
}
-func (state SubexCopyRuneState) eat(store Store, char walk.Datum) []SubexBranch {
- // TODO can I compare Datum values with == ?
- if char == state.rune {
+func (state SubexCopyAtomState) eat(store Store, char walk.Atom) []SubexBranch {
+ // TODO can I compare Atom values with == ?
+ if char == state.atom {
return []SubexBranch{{
state: state.next,
- output: []walk.Datum{char},
+ output: []walk.Atom{char},
store: store,
}}
}
return nil
}
-func (state SubexCopyRuneState) accepting(store Store) [][]walk.Datum {
+func (state SubexCopyAtomState) accepting(store Store) [][]walk.Atom {
return nil
}
-// Read in any datum and output it
+// Read in any Atom and output it
type SubexCopyAnyState struct {
next SubexState
}
-func (state SubexCopyAnyState) eat(store Store, char walk.Datum) []SubexBranch {
+func (state SubexCopyAnyState) eat(store Store, char walk.Atom) []SubexBranch {
return []SubexBranch{{
state: state.next,
- output: []walk.Datum{char},
+ output: []walk.Atom{char},
store: store,
}}
}
-func (state SubexCopyAnyState) accepting(store Store) [][]walk.Datum {
+func (state SubexCopyAnyState) accepting(store Store) [][]walk.Atom {
return nil
}
-// Read in a datum and apply a map to generate a datum to output
+// Read in an Atom and apply a map to generate an Atom to output
// If the input isn't in the map transition to nothing
type SubexRangeState struct {
- parts map[walk.Datum]walk.Datum
+ parts map[walk.Atom]walk.Atom
next SubexState
}
-func (state SubexRangeState) eat(store Store, char walk.Datum) []SubexBranch {
+func (state SubexRangeState) eat(store Store, char walk.Atom) []SubexBranch {
out, exists := state.parts[char]
if !exists {
return nil
} else {
return []SubexBranch{{
state: state.next,
- output: []walk.Datum{out},
+ output: []walk.Atom{out},
store: store,
}}
}
}
-func (state SubexRangeState) accepting(store Store) [][]walk.Datum {
+func (state SubexRangeState) accepting(store Store) [][]walk.Atom {
return nil
}