commit 1c2d7a4e9258ed72f5c8ebecc3d575d065f25c5d
parent 184368ae155fcdd50dde5c2e4b0c87e0d69acdd7
Author: Charlie Stanton <charlie@shtanton.xyz>
Date: Wed, 19 Apr 2023 12:22:57 +0100
Changes parser so the storing operator is postfix instead of prefix
Diffstat:
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git 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 {