<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/subexast.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/subexast.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/subexast.go')
-rw-r--r--subex/subexast.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/subex/subexast.go b/subex/subexast.go
index 5e63f03..9e7067b 100644
--- a/subex/subexast.go
+++ b/subex/subexast.go
@@ -181,3 +181,15 @@ func (ast SubexASTRange) compileWith(next SubexState) SubexState {
next: next,
}
}
+
+// Run content and then assume that output is a series of numbers, sum them and output the total
+// Will cast strings, booleans and null to numbers
+type SubexASTSum struct {
+ content SubexAST
+}
+func (ast SubexASTSum) compileWith(next SubexState) SubexState {
+ return &SubexSumState {
+ inputState: ast.content.compileWith(&SubexNoneState{}),
+ next: next,
+ }
+}