From 81925b6ad5212512d27365b8224b76095191431f Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 31 Mar 2024 21:23:17 +0100 Subject: Add " shorthand for string destructure --- subex/parse.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'subex/parse.go') diff --git a/subex/parse.go b/subex/parse.go index 1e17bb3..d7fe243 100644 --- a/subex/parse.go +++ b/subex/parse.go @@ -413,11 +413,29 @@ func parseSubex(l RuneReader, minPower int, inType Type) (lhs SubexAST, outType lhs, outType = parseDestructure(l, ArrayValuesStructure, inType) case '#': lhs, outType = parseDestructure(l, MapStructure, inType) + case '"': + if inType == ValueType { + var innerOutType Type + lhs, innerOutType = parseSubex(l, 0, RuneType) + if !accept(l, "\"") { + panic("Missing matching \"") + } + resolveTypes(innerOutType, RuneType) + lhs = SubexASTDestructure { + Destructure: StringStructure, + Structure: StringStructure, + Content: lhs, + } + outType = ValueType + } else { + l.Rewind() + return SubexASTEmpty{}, inType + } // TODO // case '[': // rangeParts := parseRangeSubex(l) // lhs = SubexASTRange {rangeParts} - case ')', ']', '"', '|', ';', '{', '+', '*', '/', '!', '=', '$': + case ')', ']', '|', ';', '{', '+', '*', '/', '!', '=', '$': l.Rewind() return SubexASTEmpty{}, inType // case '=': -- cgit v1.2.3