<- 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.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/subex/parse.go b/subex/parse.go
index 52488a7..4e7a3f6 100644
--- a/subex/parse.go
+++ b/subex/parse.go
@@ -166,7 +166,7 @@ func parseReplacement(l RuneReader) (output []OutputContent) {
switch r {
case eof:
panic("Missing closing \"")
- case '=', '^':
+ case '=', '^', ':':
break loop
case '$':
slot := l.Next()
@@ -281,7 +281,7 @@ func parseSubex(l RuneReader, minPower int) SubexAST {
case '[':
rangeParts := parseRangeSubex(l)
lhs = SubexASTRange {rangeParts}
- case ')', '|', ';', '{', '+', '-', '*', '/', '!', '$':
+ case ')', '|', ';', '{', '+', '-', '*', '/', '!', '$', ':':
l.Rewind()
return nil
case '=':
@@ -358,9 +358,19 @@ func parseSubex(l RuneReader, minPower int) SubexAST {
if slot == eof {
panic("Missing slot character")
}
- lhs = SubexASTStore{
- Match: lhs,
- Slot: slot,
+ if slot == '_' {
+ lhs = SubexASTDiscard {lhs}
+ } else {
+ lhs = SubexASTStore{
+ Match: lhs,
+ Slot: slot,
+ }
+ }
+ case r == ':' && minPower <= 4:
+ replacement := parseReplacement(l)
+ lhs = SubexASTConcat {
+ SubexASTDiscard {lhs},
+ SubexASTOutput {replacement},
}
case r == '|' && minPower <= 8:
rhs := parseSubex(l, 9)