diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-03-31 21:23:17 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-03-31 21:23:17 +0100 |
commit | 81925b6ad5212512d27365b8224b76095191431f (patch) | |
tree | f625a8eddb556a58c45c7e16a205df1ed6b92d3a /subex/parse.go | |
parent | 256450cc3dcdd9a9b92a33642739f7143526e9b9 (diff) | |
download | stred-go-81925b6ad5212512d27365b8224b76095191431f.tar |
Add " shorthand for string destructure
Diffstat (limited to 'subex/parse.go')
-rw-r--r-- | subex/parse.go | 20 |
1 files changed, 19 insertions, 1 deletions
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 '=': |