diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-03-30 15:20:07 +0000 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-03-30 15:20:07 +0000 |
commit | 7a9f00b9bd39173494ea734b899a9f099dafb306 (patch) | |
tree | a169451bcba8c424ade1ff5cdac29eef6818d8d8 /subex/subexstate.go | |
parent | 9d82785f46949151b783d83648b39ce9ba40c615 (diff) | |
download | stred-go-7a9f00b9bd39173494ea734b899a9f099dafb306.tar |
Add array value destructure
Diffstat (limited to 'subex/subexstate.go')
-rw-r--r-- | subex/subexstate.go | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/subex/subexstate.go b/subex/subexstate.go index 4de8ae2..45b5d00 100644 --- a/subex/subexstate.go +++ b/subex/subexstate.go @@ -355,6 +355,24 @@ func (state SubexConstructArrayState) epsilon(aux auxiliaryState) []SubexBranch }} } +type SubexConstructArrayValuesState struct { + next SubexState +} +func (state SubexConstructArrayValuesState) epsilon(aux auxiliaryState) []SubexBranch { + values, aux := aux.popOutput() + var array walk.ArrayValue + for _, v := range values { + array = append(array, walk.ArrayElement { + Index: 0, + Value: v, + }) + } + return []SubexBranch {{ + state: state.next, + aux: aux.topAppend([]walk.Value {array}), + }} +} + type SubexConstructStringState struct { next SubexState } @@ -377,12 +395,15 @@ func (state SubexConstructStringState) String() string { } type SubexIncrementNestState struct { + keys bool next SubexState } func (state SubexIncrementNestState) epsilon(aux auxiliaryState) []SubexBranch { + aux.nestingLen += 1 + aux.nestingValue = state.keys return []SubexBranch {{ state: state.next, - aux: aux.incNest(), + aux: aux, }} } func (state SubexIncrementNestState) String() string { @@ -393,8 +414,10 @@ type SubexDecrementNestState struct { next SubexState } func (state SubexDecrementNestState) epsilon(aux auxiliaryState) []SubexBranch { + aux.nestingLen -= 1 + // aux.nestingValue will be set in addStates return []SubexBranch {{ state: state.next, - aux: aux.decNest(), + aux: aux, }} } |