<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2024-04-07 16:04:23 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2024-04-07 16:04:23 +0100
commit7162ae8c641314846f0b565d7614ac8d71dbd628 (patch)
treefba1b545e6d20dac7f958bedf83afc61fcbbc256 /subex
parent658900fcae610caace83a112ac0ee865108ebc92 (diff)
downloadstred-go-7162ae8c641314846f0b565d7614ac8d71dbd628.tar
Add merge command
Diffstat (limited to 'subex')
-rw-r--r--subex/parse.go21
1 files changed, 18 insertions, 3 deletions
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