From fd79fd18c6c32884e757e91b8629c87af4cbf34e Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 30 Mar 2024 21:09:32 +0000 Subject: Add map destructure --- subex/subexast.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'subex/subexast.go') diff --git a/subex/subexast.go b/subex/subexast.go index a2c3675..2685925 100644 --- a/subex/subexast.go +++ b/subex/subexast.go @@ -489,6 +489,11 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in construct = &SubexConstructArrayValuesState { next: next, } + case MapStructure: + innerOutType = ValueType + construct = &SubexConstructMapState { + next: next, + } default: panic("Invalid ast structure") } @@ -523,6 +528,14 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in next: construct, }, } + case MapStructure: + innerInType = ValueType + destructFooter = &SubexDiscardTerminalState { + terminal: walk.MapEnd, + next: &SubexDecrementNestState { + next: construct, + }, + } default: panic("Invalid ast destructure") } @@ -550,6 +563,10 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in beginConstruct = &SubexCaptureBeginState { next: inner, } + case MapStructure: + beginConstruct = &SubexCaptureBeginState { + next: inner, + } default: panic("Invalid ast structure") } @@ -593,6 +610,18 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in }, }, } + case MapStructure: + return &SubexCaptureBeginState { + next: &SubexCopyState { + filter: anyMapFilter{}, + next: &SubexDiscardState { + next: &SubexIncrementNestState { + keys: true, + next: beginConstruct, + }, + }, + }, + } default: panic("Invalid destructure in ast") } -- cgit v1.2.3