<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-19 12:22:57 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-19 12:22:57 +0100
commit1c2d7a4e9258ed72f5c8ebecc3d575d065f25c5d (patch)
tree32fb8aa93aeff149d41419b7b02913c204749d2f
parent184368ae155fcdd50dde5c2e4b0c87e0d69acdd7 (diff)
downloadstred-go-1c2d7a4e9258ed72f5c8ebecc3d575d065f25c5d.tar
Changes parser so the storing operator is postfix instead of prefix
-rw-r--r--subex/parse.go24
1 files changed, 10 insertions, 14 deletions
diff --git a/subex/parse.go b/subex/parse.go
index 0208142..2389c3b 100644
--- a/subex/parse.go
+++ b/subex/parse.go
@@ -206,22 +206,9 @@ func parseSubex(l *RuneReader, minPower int) SubexAST {
case '[':
rangeParts := parseRangeSubex(l)
lhs = SubexASTRange {rangeParts}
- case ')', '|', ';', '{', '+':
+ case ')', '|', ';', '{', '+', '$':
l.rewind()
return nil
- case '$':
- slot := l.next()
- if slot == eof {
- panic("Missing slot character")
- }
- match := parseSubex(l, 100)
- if match == nil {
- panic("Missing regex for store")
- }
- lhs = SubexASTStore{
- match: match,
- slot: slot,
- }
case '"':
replacement := parseReplacement(l)
lhs = SubexASTOutput{replacement}
@@ -249,6 +236,15 @@ func parseSubex(l *RuneReader, minPower int) SubexAST {
}
case r == '+' && minPower <= 8:
lhs = SubexASTSum {lhs}
+ case r == '$' && minPower <= 8:
+ slot := l.next()
+ if slot == eof {
+ panic("Missing slot character")
+ }
+ lhs = SubexASTStore{
+ match: lhs,
+ slot: slot,
+ }
case r == '|' && minPower <= 4:
rhs := parseSubex(l, 5)
if rhs == nil {