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/subexast.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'subex/subexast.go') 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, + } +} -- cgit v1.2.3