<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/subexast.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-19 13:23:47 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-19 13:27:38 +0100
commitaea1a08d6a9d378137d467d3e1f1ccc40232b725 (patch)
tree680e7c913b3ea782557d51968e24d7fa5c4d450a /subex/subexast.go
parentb48dcb0d37bd3db854927df25e6ff41d07501026 (diff)
downloadstred-go-aea1a08d6a9d378137d467d3e1f1ccc40232b725.tar
Adds the negate operator
Negates all of the numbers produced by its content subex
Diffstat (limited to 'subex/subexast.go')
-rw-r--r--subex/subexast.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/subex/subexast.go b/subex/subexast.go
index abf0ca6..3c807ee 100644
--- a/subex/subexast.go
+++ b/subex/subexast.go
@@ -209,3 +209,17 @@ func (ast SubexASTProduct) compileWith(next SubexState) SubexState {
}),
}
}
+
+// Runs the content Subex, if all outputted atoms can be cast to numbers, outputs them all negated
+// Rejects if this fails
+type SubexASTNegate struct {
+ content SubexAST
+}
+func (ast SubexASTNegate) compileWith(next SubexState) SubexState {
+ return &SubexCaptureBeginState {
+ next: ast.content.compileWith(&SubexArithmeticEndState {
+ next: next,
+ calculate: negateValues,
+ }),
+ }
+}