# HG changeset patch # User Stefan Monnier # Date 1207366325 0 # Node ID c9b42189e94fa47b1b28293af2a432052b2c801c # Parent 5dee8473f368a159c37761d7e8822f30c2060b9d (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. diff -r 5dee8473f368 -r c9b42189e94f lisp/ChangeLog --- a/lisp/ChangeLog Sat Apr 05 03:31:50 2008 +0000 +++ b/lisp/ChangeLog Sat Apr 05 03:32:05 2008 +0000 @@ -1,3 +1,19 @@ +2008-04-05 Stefan Monnier + + * 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 . + (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 * vc-rcs.el (vc-rcs-dir-status): diff -r 5dee8473f368 -r c9b42189e94f lisp/progmodes/hideif.el --- a/lisp/progmodes/hideif.el Sat Apr 05 03:31:50 2008 +0000 +++ b/lisp/progmodes/hideif.el Sat Apr 05 03:32:05 2008 +0000 @@ -348,10 +348,27 @@ (defvar hif-token) (defvar hif-token-list) -;; pattern to match initial identifier, !, &&, ||, (, or ). -;; Added ==, + and -: garyo@avs.com 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 @@ (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 @@ 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 @@ (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 -----------------------