From 0072e6aad2f9969348d5315a692f1f5e2ebc075d Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Apr 2023 12:59:22 +0100 Subject: Adds product/and operator --- subex/subexast.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'subex/subexast.go') diff --git a/subex/subexast.go b/subex/subexast.go index e191a30..431ea26 100644 --- a/subex/subexast.go +++ b/subex/subexast.go @@ -27,7 +27,7 @@ type SubexASTStore struct { slot rune } func (ast SubexASTStore) compileWith(next SubexState) SubexState { - return &SubexStoreBeginState { + return &SubexCaptureBeginState { next: ast.match.compileWith(&SubexStoreEndState { slot: ast.slot, next: next, @@ -183,15 +183,27 @@ func (ast SubexASTRange) compileWith(next SubexState) SubexState { } } -// 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 +// Run content, if content is a list of booleans, OR them, if all values are castable to numbers, sum them and output the total +// Reject if neither of these cases match type SubexASTSum struct { content SubexAST } func (ast SubexASTSum) compileWith(next SubexState) SubexState { - return &SubexSumBeginState { + return &SubexCaptureBeginState { next: ast.content.compileWith(&SubexSumEndState { next: next, }), } } + +// Like sum but for AND and product +type SubexASTProduct struct { + content SubexAST +} +func (ast SubexASTProduct) compileWith(next SubexState) SubexState { + return &SubexCaptureBeginState { + next: ast.content.compileWith(&SubexProductEndState { + next: next, + }), + } +} -- cgit v1.2.3