diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-03-30 21:09:32 +0000 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-03-30 21:09:32 +0000 |
commit | fd79fd18c6c32884e757e91b8629c87af4cbf34e (patch) | |
tree | 50e6b49c64b1c6cf230c80ce83a925ec98fd2387 /subex/parse.go | |
parent | 976d96af62945178f3a3ab572620026df75003cf (diff) | |
download | stred-go-fd79fd18c6c32884e757e91b8629c87af4cbf34e.tar |
Add map destructure
Diffstat (limited to 'subex/parse.go')
-rw-r--r-- | subex/parse.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/subex/parse.go b/subex/parse.go index 98821fd..1e17bb3 100644 --- a/subex/parse.go +++ b/subex/parse.go @@ -35,6 +35,7 @@ const ( StringStructure ArrayStructure ArrayValuesStructure + MapStructure ) func (s Structure) String() string { switch s { @@ -46,6 +47,8 @@ func (s Structure) String() string { return "@" case ArrayValuesStructure: return ":" + case MapStructure: + return "#" default: panic("Invalid structure") } @@ -329,6 +332,9 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub case ArrayValuesStructure: innerInType = ValueType expectedInType = ValueType + case MapStructure: + innerInType = ValueType + expectedInType = ValueType default: panic("Invalid structure") } @@ -356,6 +362,9 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub case ':': structure = ArrayValuesStructure expectedInnerOutType = ValueType + case '#': + structure = MapStructure + expectedInnerOutType = ValueType default: panic("Missing matching destructure") } @@ -371,6 +380,8 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub outType = ValueType case ArrayValuesStructure: outType = ValueType + case MapStructure: + outType = ValueType } lhs = SubexASTDestructure { @@ -400,6 +411,8 @@ func parseSubex(l RuneReader, minPower int, inType Type) (lhs SubexAST, outType lhs, outType = parseDestructure(l, ArrayStructure, inType) case ':': lhs, outType = parseDestructure(l, ArrayValuesStructure, inType) + case '#': + lhs, outType = parseDestructure(l, MapStructure, inType) // TODO // case '[': // rangeParts := parseRangeSubex(l) |