From ffd1b73b4f3294d9f3aa2ed600da3ba053aeb47c Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Tue, 18 Apr 2023 15:07:52 +0100 Subject: Adds the sum operator Currently doesn't parse strings as each atom is considered independantly. Instead individual characters in strings can be cast --- subex/parse.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'subex/parse.go') diff --git a/subex/parse.go b/subex/parse.go index 6e1493b..0208142 100644 --- a/subex/parse.go +++ b/subex/parse.go @@ -206,7 +206,7 @@ func parseSubex(l *RuneReader, minPower int) SubexAST { case '[': rangeParts := parseRangeSubex(l) lhs = SubexASTRange {rangeParts} - case ')', '|', ';', '{': + case ')', '|', ';', '{', '+': l.rewind() return nil case '$': @@ -243,10 +243,12 @@ func parseSubex(l *RuneReader, minPower int) SubexAST { r := l.next() switch { case r == '{' && minPower <= 8: - lhs = SubexASTRepeat{ + lhs = SubexASTRepeat { content: lhs, acceptable: parseRepeatRange(l), } + case r == '+' && minPower <= 8: + lhs = SubexASTSum {lhs} case r == '|' && minPower <= 4: rhs := parseSubex(l, 5) if rhs == nil { @@ -262,13 +264,6 @@ func parseSubex(l *RuneReader, minPower int) SubexAST { content: lhs, delimiter: rhs, } - //case r == '+' && minPower <= 6: - // rhs := parseSubex(l, 7) - // if rhs == nil { - // panic("Missing subex after +") - // } - // // TODO: Implement this. Runs subex on the left, then subex on the right, then sums the outputs of each and outputs that - // lhs = SubexASTAdd{lhs, rhs} default: l.rewind() break loop -- cgit v1.2.3