<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/parse.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-18 15:07:52 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-18 15:07:52 +0100
commitffd1b73b4f3294d9f3aa2ed600da3ba053aeb47c (patch)
treeac3075e8ea26190838e0e6df3f5e6af65909ca51 /subex/parse.go
parentfebdc5dcd5b25a090b90c920914775265da98d39 (diff)
downloadstred-go-ffd1b73b4f3294d9f3aa2ed600da3ba053aeb47c.tar
Adds the sum operator
Currently doesn't parse strings as each atom is considered independantly. Instead individual characters in strings can be cast
Diffstat (limited to 'subex/parse.go')
-rw-r--r--subex/parse.go13
1 files changed, 4 insertions, 9 deletions
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