From 7a9f00b9bd39173494ea734b899a9f099dafb306 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 30 Mar 2024 15:20:07 +0000 Subject: Add array value destructure --- subex/parse.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'subex/parse.go') diff --git a/subex/parse.go b/subex/parse.go index f1565f5..98821fd 100644 --- a/subex/parse.go +++ b/subex/parse.go @@ -34,13 +34,18 @@ const ( NoneStructure Structure = iota StringStructure ArrayStructure + ArrayValuesStructure ) -func (s Structure) innerType() Type { +func (s Structure) String() string { switch s { + case NoneStructure: + return "-" case StringStructure: - return RuneType + return "~" case ArrayStructure: - return ValueType + return "@" + case ArrayValuesStructure: + return ":" default: panic("Invalid structure") } @@ -321,6 +326,9 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub case ArrayStructure: innerInType = ValueType expectedInType = ValueType + case ArrayValuesStructure: + innerInType = ValueType + expectedInType = ValueType default: panic("Invalid structure") } @@ -345,6 +353,9 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub case '@': structure = ArrayStructure expectedInnerOutType = ValueType + case ':': + structure = ArrayValuesStructure + expectedInnerOutType = ValueType default: panic("Missing matching destructure") } @@ -358,6 +369,8 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub outType = ValueType case ArrayStructure: outType = ValueType + case ArrayValuesStructure: + outType = ValueType } lhs = SubexASTDestructure { @@ -385,6 +398,8 @@ func parseSubex(l RuneReader, minPower int, inType Type) (lhs SubexAST, outType lhs, outType = parseDestructure(l, StringStructure, inType) case '@': lhs, outType = parseDestructure(l, ArrayStructure, inType) + case ':': + lhs, outType = parseDestructure(l, ArrayValuesStructure, inType) // TODO // case '[': // rangeParts := parseRangeSubex(l) -- cgit v1.2.3