<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/subexast.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2024-03-30 21:09:32 +0000
committerCharlie Stanton <charlie@shtanton.xyz>2024-03-30 21:09:32 +0000
commitfd79fd18c6c32884e757e91b8629c87af4cbf34e (patch)
tree50e6b49c64b1c6cf230c80ce83a925ec98fd2387 /subex/subexast.go
parent976d96af62945178f3a3ab572620026df75003cf (diff)
downloadstred-go-fd79fd18c6c32884e757e91b8629c87af4cbf34e.tar
Add map destructure
Diffstat (limited to 'subex/subexast.go')
-rw-r--r--subex/subexast.go29
1 files changed, 29 insertions, 0 deletions
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")
}