From 9e448767f3dbd47ae5510672879a0191a33f6dc0 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Sat, 26 Oct 2024 17:05:57 +0100 Subject: [PATCH] Add not operators (#1582) Add the unary operator not and bitwise not. Initially implemented in C & Python simply because I use those the most Surprised this wasn't implemented previously, not sure if there was a reason why --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- lang/c/c.py | 6 ++++++ lang/python/python.py | 6 ++++++ lang/tags/operators_bitwise.py | 3 +++ lang/tags/operators_bitwise.talon | 1 + lang/tags/operators_math.py | 3 +++ lang/tags/operators_math.talon | 1 + 6 files changed, 20 insertions(+) diff --git a/lang/c/c.py b/lang/c/c.py index 44fe90abd3..b485d0c732 100644 --- a/lang/c/c.py +++ b/lang/c/c.py @@ -266,6 +266,9 @@ def code_operator_and(): def code_operator_or(): actions.auto_insert(" || ") + def code_operator_not(): + actions.auto_insert("!") + def code_operator_bitwise_and(): actions.auto_insert(" & ") @@ -284,6 +287,9 @@ def code_operator_bitwise_exclusive_or(): def code_operator_bitwise_exclusive_or_assignment(): actions.auto_insert(" ^= ") + def code_operator_bitwise_not(): + actions.auto_insert("~") + def code_operator_bitwise_left_shift(): actions.auto_insert(" << ") diff --git a/lang/python/python.py b/lang/python/python.py index ead965deb6..3945bc0dbe 100644 --- a/lang/python/python.py +++ b/lang/python/python.py @@ -214,6 +214,9 @@ def code_operator_and(): def code_operator_or(): actions.auto_insert(" or ") + def code_operator_not(): + actions.auto_insert("not ") + def code_operator_in(): actions.auto_insert(" in ") @@ -238,6 +241,9 @@ def code_operator_bitwise_exclusive_or(): def code_operator_bitwise_exclusive_or_assignment(): actions.auto_insert(" ^= ") + def code_operator_bitwise_not(): + actions.auto_insert("~") + def code_operator_bitwise_left_shift(): actions.auto_insert(" << ") diff --git a/lang/tags/operators_bitwise.py b/lang/tags/operators_bitwise.py index c5c8fdf176..d5f7797c33 100644 --- a/lang/tags/operators_bitwise.py +++ b/lang/tags/operators_bitwise.py @@ -14,6 +14,9 @@ def code_operator_bitwise_and(): def code_operator_bitwise_or(): """code_operator_bitwise_or""" + def code_operator_bitwise_not(): + """code_operator_bitwise_not""" + def code_operator_bitwise_exclusive_or(): """code_operator_bitwise_exclusive_or""" diff --git a/lang/tags/operators_bitwise.talon b/lang/tags/operators_bitwise.talon index fffaaed5ec..e403e66c89 100644 --- a/lang/tags/operators_bitwise.talon +++ b/lang/tags/operators_bitwise.talon @@ -4,6 +4,7 @@ tag: user.code_operators_bitwise #bitwise operators [op] bitwise and: user.code_operator_bitwise_and() [op] bitwise or: user.code_operator_bitwise_or() +[op] bitwise not: user.code_operator_bitwise_not() # TODO: split these out into separate logical and bitwise operator commands diff --git a/lang/tags/operators_math.py b/lang/tags/operators_math.py index 0c474c5625..34507bf690 100644 --- a/lang/tags/operators_math.py +++ b/lang/tags/operators_math.py @@ -53,6 +53,9 @@ def code_operator_and(): def code_operator_or(): """code_operator_or""" + def code_operator_not(): + """code_operator_not""" + def code_operator_in(): """code_operator_in""" diff --git a/lang/tags/operators_math.talon b/lang/tags/operators_math.talon index a1e1fddc75..57d590e0d8 100644 --- a/lang/tags/operators_math.talon +++ b/lang/tags/operators_math.talon @@ -20,6 +20,7 @@ op mod: user.code_operator_modulo() # logical operators (op | logical) and: user.code_operator_and() (op | logical) or: user.code_operator_or() +(op | logical) not: user.code_operator_not() # set operators (op | is) in: user.code_operator_in()