branch: elpa/emacsql
commit f9820deed75c6a9afbb4310bd5e08cbe96e72b68
Author: Christopher Wellons <[email protected]>
Commit: Christopher Wellons <[email protected]>
Add unary operators.
---
emacsql.el | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/emacsql.el b/emacsql.el
index 17ff1231b4..6b89a35bc4 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -398,6 +398,7 @@ definitions for return from a `emacsql-defexpander'."
(cl-destructuring-bind (op . args) expr
(cl-flet ((recur (n) (combine (emacsql--expr (nth n args)))))
(cl-ecase op
+ ;; Trinary/binary
((<= >=)
(cl-ecase (length args)
(2 (format "%s %s %s" (recur 0) op (recur 1)))
@@ -405,13 +406,24 @@ definitions for return from a `emacsql-defexpander'."
(recur 1)
(recur (if (eq op '>=) 2 0))
(recur (if (eq op '>=) 0 2))))))
- ((< > = != like glob is and or * / % << >> + - & |)
+ ;; Binary
+ ((< > = != like glob is and or * / % << >> + & |)
(if (= 2 (length args))
(format "%s %s %s"
(recur 0)
(if (eq op '%) '%% (upcase (symbol-name op)))
(recur 1))
- (error "Wrong number of operands for %s" op)))))))))
+ (error "Wrong number of operands for %s" op)))
+ ;; Unary
+ ((not)
+ (if (= 1 (length args))
+ (format "%s %s" (upcase (symbol-name op)) (recur 0))
+ (error "Wrong number of operands for %s" op)))
+ ;; Unary/Binary
+ ((-)
+ (cl-ecase (length args)
+ (1 (format "-(%s)" (recur 0)))
+ (2 (format "%s - %s" (recur 0) (recur 1)))))))))))
;; SQL Expansion Functions: