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/subexast.go | |
parent | 9d82785f46949151b783d83648b39ce9ba40c615 (diff) | |
download | stred-go-7a9f00b9bd39173494ea734b899a9f099dafb306.tar |
Add array value destructure
Diffstat (limited to 'subex/subexast.go')
-rw-r--r-- | subex/subexast.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/subex/subexast.go b/subex/subexast.go index 7070baf..a2c3675 100644 --- a/subex/subexast.go +++ b/subex/subexast.go @@ -484,6 +484,13 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in construct = &SubexConstructArrayState { next: next, } + case ArrayValuesStructure: + innerOutType = ValueType + construct = &SubexConstructArrayValuesState { + next: next, + } + default: + panic("Invalid ast structure") } var innerInType Type @@ -508,6 +515,16 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in next: construct, }, } + case ArrayValuesStructure: + innerInType = ValueType + destructFooter = &SubexDiscardTerminalState { + terminal: walk.ArrayEnd, + next: &SubexDecrementNestState { + next: construct, + }, + } + default: + panic("Invalid ast destructure") } inner := ast.Content.compileWith( @@ -529,6 +546,12 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in beginConstruct = &SubexCaptureBeginState { next: inner, } + case ArrayValuesStructure: + beginConstruct = &SubexCaptureBeginState { + next: inner, + } + default: + panic("Invalid ast structure") } switch ast.Destructure { @@ -540,6 +563,7 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in filter: anyStringFilter{}, next: &SubexDiscardState { next: &SubexIncrementNestState { + keys: true, next: beginConstruct, }, }, @@ -551,6 +575,19 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in filter: anyArrayFilter{}, next: &SubexDiscardState { next: &SubexIncrementNestState { + keys: true, + next: beginConstruct, + }, + }, + }, + } + case ArrayValuesStructure: + return &SubexCaptureBeginState { + next: &SubexCopyState { + filter: anyArrayFilter{}, + next: &SubexDiscardState { + next: &SubexIncrementNestState { + keys: false, next: beginConstruct, }, }, @@ -560,3 +597,6 @@ func (ast SubexASTDestructure) compileWith(next SubexState, slotMap *SlotMap, in panic("Invalid destructure in ast") } } +func (ast SubexASTDestructure) String() string { + return fmt.Sprintf("%v(%v)%v", ast.Destructure, ast.Content, ast.Structure) +} |