aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier <[email protected]>2008-04-05 03:32:05 +0000
committerStefan Monnier <[email protected]>2008-04-05 03:32:05 +0000
commitd302e5cfe3625da8000d2c0729bc4e9684eacb6e (patch)
treeb07a9019db82a10f195ad245f974cb5cf89561ce
parentb5507bc14e6de95edfff0eb5021674cda14538d9 (diff)
(hif-token-alist): New var.
(hif-token-regexp, hif-tokenize): Use it. (hif-mathify-binop): New macro. (hif-plus, hif-minus, hif-notequal, hif-greater, hif-less) (hif-greater-equal, hif-less-equal): Use it. (hif-logior, hif-logand): New functions. (hif-math): Accept | and & as well.
-rw-r--r--lisp/ChangeLog16
-rw-r--r--lisp/progmodes/hideif.el87
2 files changed, 58 insertions, 45 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c6535b7f8d..75771572cf 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
+2008-04-05 Stefan Monnier <[email protected]>
+
+ * progmodes/hideif.el (hif-token-alist): New var.
+ (hif-token-regexp, hif-tokenize): Use it.
+ (hif-mathify-binop): New macro.
+ (hif-plus, hif-minus, hif-notequal, hif-greater, hif-less)
+ (hif-greater-equal, hif-less-equal): Use it.
+ (hif-logior, hif-logand): New functions.
+ (hif-math): Accept | and & as well.
+
+ * progmodes/etags.el: Fix problem with completion for buffer-local
+ tables. Reported by Radey Shouman <[email protected]>.
+ (tags-complete-tag): Remove.
+ (tags-lazy-completion-table): New function to replace it.
+ (find-tag-tag, complete-tag): Update users.
+
2008-04-04 Dan Nicolaescu <[email protected]>
* vc-rcs.el (vc-rcs-dir-status):
diff --git a/lisp/progmodes/hideif.el b/lisp/progmodes/hideif.el
index 83ffb5f7a0..5c9bf45e39 100644
--- a/lisp/progmodes/hideif.el
+++ b/lisp/progmodes/hideif.el
@@ -348,10 +348,27 @@ that form should be displayed.")
(defvar hif-token)
(defvar hif-token-list)
-;; pattern to match initial identifier, !, &&, ||, (, or ).
-;; Added ==, + and -: [email protected] 8/9/94
+(defconst hif-token-alist
+ '(("||" . or)
+ ("&&" . and)
+ ("|" . hif-logior)
+ ("&" . hif-logand)
+ ("==" . equal)
+ ("!=" . hif-notequal)
+ ("!" . not)
+ ("(" . lparen)
+ (")" . rparen)
+ (">" . hif-greater)
+ ("<" . hif-less)
+ (">=" . hif-greater-equal)
+ ("<=" . hif-less-equal)
+ ("+" . hif-plus)
+ ("-" . hif-minus)
+ ("?" . hif-conditional)
+ (":" . hif-colon)))
+
(defconst hif-token-regexp
- "\\(&&\\|||\\|[!=]=\\|!\\|[()+?:-]\\|[<>]=?\\|\\w+\\)")
+ (concat (regexp-opt (mapcar 'car hif-token-alist)) "\\|\\w+"))
(defun hif-tokenize (start end)
"Separate string between START and END into a list of tokens."
@@ -369,26 +386,11 @@ that form should be displayed.")
(let ((token (buffer-substring (point) (match-end 0))))
(goto-char (match-end 0))
;; (message "token: %s" token) (sit-for 1)
- (push (cond
- ((string-equal token "||") 'or)
- ((string-equal token "&&") 'and)
- ((string-equal token "==") 'equal)
- ((string-equal token "!=") 'hif-notequal)
- ((string-equal token "!") 'not)
- ((string-equal token "defined") 'hif-defined)
- ((string-equal token "(") 'lparen)
- ((string-equal token ")") 'rparen)
- ((string-equal token ">") 'hif-greater)
- ((string-equal token "<") 'hif-less)
- ((string-equal token ">=") 'hif-greater-equal)
- ((string-equal token "<=") 'hif-less-equal)
- ((string-equal token "+") 'hif-plus)
- ((string-equal token "-") 'hif-minus)
- ((string-equal token "?") 'hif-conditional)
- ((string-equal token ":") 'hif-colon)
- ((string-match "\\`[0-9]*\\'" token)
- (string-to-number token))
- (t (intern token)))
+ (push (or (cdr (assoc token hif-token-alist))
+ (if (string-equal token "defined") 'hif-defined)
+ (if (string-match "\\`[0-9]*\\'" token)
+ (string-to-number token))
+ (intern token))
token-list)))
(t (error "Bad #if expression: %s" (buffer-string)))))))
(nreverse token-list)))
@@ -457,7 +459,7 @@ that form should be displayed.")
math : factor | math '+|-' factor."
(let ((result (hif-factor))
(math-op nil))
- (while (memq hif-token '(hif-plus hif-minus))
+ (while (memq hif-token '(hif-plus hif-minus hif-logior hif-logand))
(setq math-op hif-token)
(hif-nexttoken)
(setq result (list math-op result (hif-factor))))
@@ -515,27 +517,22 @@ that form should be displayed.")
(or (not (zerop (hif-mathify a))) (not (zerop (hif-mathify b)))))
(defun hif-not (a)
(zerop (hif-mathify a)))
-(defun hif-plus (a b)
- "Like ordinary plus but treat t and nil as 1 and 0."
- (+ (hif-mathify a) (hif-mathify b)))
-(defun hif-minus (a b)
- "Like ordinary minus but treat t and nil as 1 and 0."
- (- (hif-mathify a) (hif-mathify b)))
-(defun hif-notequal (a b)
- "Like (not (equal A B)) but as one symbol."
- (not (equal a b)))
-(defun hif-greater (a b)
- "Simple comparison."
- (> (hif-mathify a) (hif-mathify b)))
-(defun hif-less (a b)
- "Simple comparison."
- (< (hif-mathify a) (hif-mathify b)))
-(defun hif-greater-equal (a b)
- "Simple comparison."
- (>= (hif-mathify a) (hif-mathify b)))
-(defun hif-less-equal (a b)
- "Simple comparison."
- (<= (hif-mathify a) (hif-mathify b)))
+
+(defmacro hif-mathify-binop (fun)
+ `(lambda (a b)
+ ,(format "Like `%s' but treat t and nil as 1 and 0." fun)
+ (,fun (hif-mathify a) (hif-mathify b))))
+
+(defalias 'hif-plus (hif-mathify-binop +))
+(defalias 'hif-minus (hif-mathify-binop -))
+(defalias 'hif-notequal (hif-mathify-binop /=))
+(defalias 'hif-greater (hif-mathify-binop >))
+(defalias 'hif-less (hif-mathify-binop <))
+(defalias 'hif-greater-equal (hif-mathify-binop >=))
+(defalias 'hif-less-equal (hif-mathify-binop <=))
+(defalias 'hif-logior (hif-mathify-binop logior))
+(defalias 'hif-logand (hif-mathify-binop logand))
+
;;;----------- end of parser -----------------------