From aea1a08d6a9d378137d467d3e1f1ccc40232b725 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Apr 2023 13:23:47 +0100 Subject: Adds the negate operator Negates all of the numbers produced by its content subex --- subex/subexast.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'subex/subexast.go') 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, + }), + } +} -- cgit v1.2.3