diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-19 12:59:22 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-19 12:59:22 +0100 |
commit | 0072e6aad2f9969348d5315a692f1f5e2ebc075d (patch) | |
tree | 0c75e9466a688694383279f56d69a46f014e3680 /subex/subexast.go | |
parent | 053a403a77e5b4c46e82932e94d5fb7a4117ce43 (diff) | |
download | stred-go-0072e6aad2f9969348d5315a692f1f5e2ebc075d.tar |
Adds product/and operator
Diffstat (limited to 'subex/subexast.go')
-rw-r--r-- | subex/subexast.go | 20 |
1 files changed, 16 insertions, 4 deletions
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, + }), + } +} |