From 7162ae8c641314846f0b565d7614ac8d71dbd628 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 7 Apr 2024 16:04:23 +0100 Subject: Add merge command --- subex/parse.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'subex') diff --git a/subex/parse.go b/subex/parse.go index 619c1c3..d825f75 100644 --- a/subex/parse.go +++ b/subex/parse.go @@ -183,7 +183,7 @@ func parseRepeatRange(l RuneReader) (output []ConvexRange) { return output } -func parseValueReplacement(l RuneReader) (output SubexAST) { +func parseValueReplacement(l RuneReader, end rune) (output SubexAST) { output = SubexASTEmpty{} // TODO escaping // TODO add arrays, maps and strings @@ -193,7 +193,7 @@ func parseValueReplacement(l RuneReader) (output SubexAST) { case eof: panic("Missing closing `") case ' ': - case '`': + case end: break loop case '$': slot := l.Next() @@ -207,6 +207,21 @@ func parseValueReplacement(l RuneReader) (output SubexAST) { }, } // TODO: destructures + case '#': + if !accept(l, "(") { + panic("Missing ( after #") + } + output = SubexASTConcat { + First: output, + Second: SubexASTDestructure { + Destructure: NoneStructure, + Structure: MapStructure, + Content: parseValueReplacement(l, ')'), + }, + } + if !accept(l, "#") { + panic("Missing # after )") + } case '"': output = SubexASTConcat { First: output, @@ -501,7 +516,7 @@ func parseSubex(l RuneReader, minPower int, inType Type) (lhs SubexAST, outType lhs = SubexASTCopyNumber{} case '`': outType = inType - lhs = parseValueReplacement(l) + lhs = parseValueReplacement(l, '`') case ' ': if inType == RuneType { outType = RuneType -- cgit v1.2.3