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/parse.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'subex/parse.go') 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) -- cgit v1.2.3