diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-07 15:27:36 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-07 15:27:36 +0100 |
commit | 658900fcae610caace83a112ac0ee865108ebc92 (patch) | |
tree | 4d7b6bebe0d192abf62970ca4324ef1ff274e3c8 /subex/subexstate.go | |
parent | 81925b6ad5212512d27365b8224b76095191431f (diff) | |
download | stred-go-658900fcae610caace83a112ac0ee865108ebc92.tar |
Change output subex internals to allow structures
Also add substitute register syntactic sugar
Diffstat (limited to 'subex/subexstate.go')
-rw-r--r-- | subex/subexstate.go | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/subex/subexstate.go b/subex/subexstate.go index 4f5dc19..1e1e94e 100644 --- a/subex/subexstate.go +++ b/subex/subexstate.go @@ -133,6 +133,19 @@ func (state SubexStoreEndState) epsilon(aux auxiliaryState) []SubexBranch { }} } +type SubexStoreRunesEndState struct { + slot int + next SubexState +} +func (state SubexStoreRunesEndState) epsilon(aux auxiliaryState) []SubexBranch { + toStore, aux := aux.popOutputRunes() + aux.store = aux.store.withRunes(state.slot, toStore) + return []SubexBranch {{ + state: state.next, + aux: aux, + }} +} + /* // A part of an output literal, either an Atom or a slot from which to load type OutputContent interface { @@ -211,48 +224,48 @@ func (state SubexOutputState) accepting(aux auxiliaryState) []OutputStack { } */ -type OutputValue interface { - build(store Store) []walk.Value -} - -type OutputValueLoad struct { - slot int +type SubexOutputValueLiteralState struct { + literal walk.Scalar + next SubexState } -func (ov OutputValueLoad) build(store Store) []walk.Value { - return store.values[ov.slot] +func (state SubexOutputValueLiteralState) epsilon(aux auxiliaryState) []SubexBranch { + return []SubexBranch {{ + state: state.next, + aux: aux.topAppend([]walk.Value {state.literal}), + }} } -type OutputValueLiteral struct { - scalar walk.Scalar +type SubexOutputValueLoadState struct { + slot int + next SubexState } -func (ov OutputValueLiteral) build(store Store) []walk.Value { - return []walk.Value{ov.scalar} +func (state SubexOutputValueLoadState) epsilon(aux auxiliaryState) []SubexBranch { + return []SubexBranch {{ + state: state.next, + aux: aux.topAppend(aux.store.values[state.slot]), + }} } -type SubexOutputValuesState struct { - content []OutputValue +type SubexOutputRuneLiteralState struct { + literal rune next SubexState } -func (state SubexOutputValuesState) epsilon(aux auxiliaryState) []SubexBranch { - var content []walk.Value - for _, el := range state.content { - content = append(content, el.build(aux.store)...) - } +func (state SubexOutputRuneLiteralState) epsilon(aux auxiliaryState) []SubexBranch { return []SubexBranch {{ state: state.next, - aux: aux.topAppend(content), + aux: aux.topAppendRune([]rune {state.literal}), }} } -type OutputRune interface { -} - -type OutputRuneLoad struct { +type SubexOutputRuneLoadState struct { slot int + next SubexState } - -type OutputRuneLiteral struct { - r rune +func (state SubexOutputRuneLoadState) epsilon(aux auxiliaryState) []SubexBranch { + return []SubexBranch {{ + state: state.next, + aux: aux.topAppendRune(aux.store.runes[state.slot]), + }} } // A final state, transitions to nothing but is accepting |