diff options
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, + }), + } +} |