From 1c2d7a4e9258ed72f5c8ebecc3d575d065f25c5d Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Apr 2023 12:22:57 +0100 Subject: Changes parser so the storing operator is postfix instead of prefix --- subex/parse.go | 24 ++++++++++-------------- 1 file 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 { -- cgit v1.2.3