<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'subex/parse.go')
-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