From 7a9f00b9bd39173494ea734b899a9f099dafb306 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 30 Mar 2024 15:20:07 +0000 Subject: Add array value destructure --- subex/subexstate.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'subex/subexstate.go') 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, }} } -- cgit v1.2.3