diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-03-05 10:00:28 +0000 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-03-05 10:00:28 +0000 |
commit | 6f107b7a0ccfbcd3e2ec05d91c98877d9b2e0fc7 (patch) | |
tree | 3f2831b0dee324473962bb78f2f6b459dff048cb /subex | |
parent | ba20360431842bed56109a34e36416a3de5bf905 (diff) | |
download | stred-go-6f107b7a0ccfbcd3e2ec05d91c98877d9b2e0fc7.tar |
Renames TransducerOutput to OutputContent (and related types) and moves into main/subexstate.go
Diffstat (limited to 'subex')
-rw-r--r-- | subex/main.go | 23 | ||||
-rw-r--r-- | subex/parse.go | 8 | ||||
-rw-r--r-- | subex/subexast.go | 2 | ||||
-rw-r--r-- | subex/subexstate.go | 24 |
4 files changed, 28 insertions, 29 deletions
diff --git a/subex/main.go b/subex/main.go index fd0d356..0b87dc9 100644 --- a/subex/main.go +++ b/subex/main.go @@ -8,29 +8,6 @@ import ( "strings" ) -// A part of an insertion, either an Atom or a slot from which to load -// TODO rename this -type TransducerOutput interface { - // Given the current store, return the []Atom produced by the TransducerOutput - build(Store) []walk.Atom -} - -// A TransducerOutput which is just an Atom literal -type TransducerReplacementAtom struct { - atom walk.Atom -} -func (replacement TransducerReplacementAtom) build(store Store) []walk.Atom { - return []walk.Atom{replacement.atom} -} - -// A TransducerOutput which is a slot that is loaded from -type TransducerReplacementLoad struct { - slot rune -} -func (replacement TransducerReplacementLoad) build(store Store) []walk.Atom { - return store[replacement.slot] -} - // Where slots are stored type Store map[rune][]walk.Atom // Return a new store with all the data from this one diff --git a/subex/parse.go b/subex/parse.go index 16bc620..f2c77bc 100644 --- a/subex/parse.go +++ b/subex/parse.go @@ -29,7 +29,7 @@ func parseTerminatorAtomLiteral(termType rune, l *RuneReader) walk.Atom { } } -func parseReplacement(l *RuneReader) (output []TransducerOutput) { +func parseReplacement(l *RuneReader) (output []OutputContent) { // TODO escaping loop: for { r := l.next() @@ -43,11 +43,11 @@ func parseReplacement(l *RuneReader) (output []TransducerOutput) { if slot == eof { panic("Missing slot character") } - output = append(output, TransducerReplacementLoad{slot: slot}) + output = append(output, OutputLoad{slot: slot}) case '@', '~', '#': - output = append(output, TransducerReplacementAtom{atom: parseTerminatorAtomLiteral(r, l)}) + output = append(output, OutputAtomLiteral{atom: parseTerminatorAtomLiteral(r, l)}) default: - output = append(output, TransducerReplacementAtom{atom: r}) + output = append(output, OutputAtomLiteral{atom: r}) } } return output diff --git a/subex/subexast.go b/subex/subexast.go index c49f215..0c5c676 100644 --- a/subex/subexast.go +++ b/subex/subexast.go @@ -120,7 +120,7 @@ func (ast SubexASTCopyAny) String() string { // Output a series of Atoms without reading anything from input type SubexASTOutput struct { - replacement []TransducerOutput + replacement []OutputContent } func (ast SubexASTOutput) compileWith(next SubexState) SubexState { return &SubexOutputState{ diff --git a/subex/subexstate.go b/subex/subexstate.go index 12ace42..5a38d0b 100644 --- a/subex/subexstate.go +++ b/subex/subexstate.go @@ -62,9 +62,31 @@ func (state SubexStoreState) accepting(store Store) (outputs [][]walk.Atom) { return outputs } +// A part of an output literal, either an Atom or a slot from which to load +type OutputContent interface { + // Given the current store, return the []Atom produced by the TransducerOutput + build(Store) []walk.Atom +} + +// An OutputContent which is just an Atom literal +type OutputAtomLiteral struct { + atom walk.Atom +} +func (replacement OutputAtomLiteral) build(store Store) []walk.Atom { + return []walk.Atom{replacement.atom} +} + +// An OutputContent which is a slot that is loaded from +type OutputLoad struct { + slot rune +} +func (replacement OutputLoad) build(store Store) []walk.Atom { + return store[replacement.slot] +} + // Don't read in anything, just output the series of data and slots specified type SubexOutputState struct { - content []TransducerOutput + content []OutputContent next SubexState } // Given a store, return what is outputted by an epsilon transition from this state |