diff options
| author | Richard M. Stallman | 1994-09-19 05:29:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-09-19 05:29:15 +0000 |
| commit | 7bbe1dea3b53faffed4683fd1f399e7be68e8162 (patch) | |
| tree | 65d51a679ae5d705b0bef67545a0df40a7fc9232 | |
| parent | 25869acf6e0892bc2f65c979297308d79059519c (diff) | |
| download | emacs-7bbe1dea3b53faffed4683fd1f399e7be68e8162.tar.gz emacs-7bbe1dea3b53faffed4683fd1f399e7be68e8162.zip | |
Handle ==, !=, + and -.
(hif-tokenize): Handle ==, !=, + and -.
(hif-token-regexp): Handle ==, !=, + and -.
(hif-notequal, hif-plus, hif-minus, hif-mathify): New functions.
(hif-math, hif-eq-expr): New functions.
(hif-term): Call hif-eq-expr.
(hide-ifdef-define): Pass 1 to hif-set-var.
| -rw-r--r-- | lisp/progmodes/hideif.el | 89 |
1 files changed, 51 insertions, 38 deletions
diff --git a/lisp/progmodes/hideif.el b/lisp/progmodes/hideif.el index 4cd538efcf8..a285b98e490 100644 --- a/lisp/progmodes/hideif.el +++ b/lisp/progmodes/hideif.el | |||
| @@ -107,38 +107,6 @@ | |||
| 107 | ;;; I will continue to upgrade hide-ifdef-mode | 107 | ;;; I will continue to upgrade hide-ifdef-mode |
| 108 | ;;; with your contributions. | 108 | ;;; with your contributions. |
| 109 | 109 | ||
| 110 | ;;; Change Log: | ||
| 111 | ;;; | ||
| 112 | ;;; Revision 1.7 88/02/16 03:12:58 liberte | ||
| 113 | ;;; Fixed comments and doc strings. | ||
| 114 | ;;; Added optional prefix arg for ifdef motion commands. | ||
| 115 | ;;; | ||
| 116 | ;;; Revision 1.6 88/02/05 00:36:18 liberte | ||
| 117 | ;;; Bug fixes. | ||
| 118 | ;;; 1. A multi-line comment that starts on an #ifdef line | ||
| 119 | ;;; now ends on that line. | ||
| 120 | ;;; 2. Fix bad function name: hide-hif-ifdef-toggle-read-only | ||
| 121 | ;;; 3. Make ifdef-block hiding work outside of ifdefs. | ||
| 122 | ;;; | ||
| 123 | ;;; Revision 1.5 88/01/31 23:19:31 liberte | ||
| 124 | ;;; Major clean up. | ||
| 125 | ;;; Prefix internal names with "hif-". | ||
| 126 | ;;; | ||
| 127 | ;;; Revision 1.4 88/01/30 14:09:38 liberte | ||
| 128 | ;;; Add hide-ifdef-hiding and hide-ifdef-mode to minor-mode-alist. | ||
| 129 | ;;; | ||
| 130 | ;;; Revision 1.3 88/01/29 00:38:19 liberte | ||
| 131 | ;;; Fix three bugs. | ||
| 132 | ;;; 1. Function "defined" is just like lookup. | ||
| 133 | ;;; 2. Skip to newline or cr in case text is hidden. | ||
| 134 | ;;; 3. Use car of token list if just one symbol. | ||
| 135 | ;;; | ||
| 136 | ;;; Revision 1.2 88/01/28 23:32:46 liberte | ||
| 137 | ;;; Use hide-ifdef-mode-prefix-key. | ||
| 138 | ;;; Copy current-local-map so other buffers do not get | ||
| 139 | ;;; hide-ifdef-mode bindings. | ||
| 140 | ;;; | ||
| 141 | |||
| 142 | ;;; Code: | 110 | ;;; Code: |
| 143 | 111 | ||
| 144 | (defvar hide-ifdef-mode-submap nil | 112 | (defvar hide-ifdef-mode-submap nil |
| @@ -372,7 +340,8 @@ that form should be displayed.") | |||
| 372 | ) | 340 | ) |
| 373 | 341 | ||
| 374 | ; pattern to match initial identifier, !, &&, ||, (, or ). | 342 | ; pattern to match initial identifier, !, &&, ||, (, or ). |
| 375 | (defconst hif-token-regexp "^\\(!\\|&&\\|||\\|[()]\\|\\w+\\)") | 343 | ; Added ==, + and -: garyo@avs.com 8/9/94 |
| 344 | (defconst hif-token-regexp "^\\(!\\|&&\\|||\\|[!=]=\\|[()+-]\\|\\w+\\)") | ||
| 376 | (defconst hif-end-of-comment "\\*/") | 345 | (defconst hif-end-of-comment "\\*/") |
| 377 | 346 | ||
| 378 | 347 | ||
| @@ -418,13 +387,16 @@ that form should be displayed.") | |||
| 418 | (cond | 387 | (cond |
| 419 | ((string-equal token "||") 'or) | 388 | ((string-equal token "||") 'or) |
| 420 | ((string-equal token "&&") 'and) | 389 | ((string-equal token "&&") 'and) |
| 390 | ((string-equal token "==") 'equal) | ||
| 391 | ((string-equal token "!=") 'hif-notequal) | ||
| 421 | ((string-equal token "!") 'not) | 392 | ((string-equal token "!") 'not) |
| 422 | ((string-equal token "defined") 'hif-defined) | 393 | ((string-equal token "defined") 'hif-defined) |
| 423 | ((string-equal token "(") 'lparen) | 394 | ((string-equal token "(") 'lparen) |
| 424 | ((string-equal token ")") 'rparen) | 395 | ((string-equal token ")") 'rparen) |
| 396 | ((string-equal token "+") 'hif-plus) | ||
| 397 | ((string-equal token "-") 'hif-minus) | ||
| 425 | (t (intern token))) | 398 | (t (intern token))) |
| 426 | token-list)))) | 399 | token-list)))) |
| 427 | |||
| 428 | (t (error "Bad #if expression: %s" expr-string))))) | 400 | (t (error "Bad #if expression: %s" expr-string))))) |
| 429 | (set-syntax-table current-syntax-table)) | 401 | (set-syntax-table current-syntax-table)) |
| 430 | (nreverse token-list))) | 402 | (nreverse token-list))) |
| @@ -432,6 +404,7 @@ that form should be displayed.") | |||
| 432 | ;;;----------------------------------------------------------------- | 404 | ;;;----------------------------------------------------------------- |
| 433 | ;;; Translate C preprocessor #if expressions using recursive descent. | 405 | ;;; Translate C preprocessor #if expressions using recursive descent. |
| 434 | ;;; This parser is limited to the operators &&, ||, !, and "defined". | 406 | ;;; This parser is limited to the operators &&, ||, !, and "defined". |
| 407 | ;;; Added ==, !=, +, and -. Gary Oberbrunner, garyo@avs.com, 8/9/94 | ||
| 435 | 408 | ||
| 436 | (defun hif-parse-if-exp (token-list) | 409 | (defun hif-parse-if-exp (token-list) |
| 437 | "Parse the TOKEN-LIST. Return translated list in prefix form." | 410 | "Parse the TOKEN-LIST. Return translated list in prefix form." |
| @@ -458,13 +431,35 @@ that form should be displayed.") | |||
| 458 | 431 | ||
| 459 | (defun hif-term () | 432 | (defun hif-term () |
| 460 | "Parse a term of the form | 433 | "Parse a term of the form |
| 461 | term : factor | term '&&' factor." | 434 | term : eq-expr | term '&&' eq-expr." |
| 462 | (let ((result (hif-factor))) | 435 | (let ((result (hif-eq-expr))) |
| 463 | (while (eq token 'and) | 436 | (while (eq token 'and) |
| 464 | (hif-nexttoken) | 437 | (hif-nexttoken) |
| 465 | (setq result (list 'and result (hif-factor)))) | 438 | (setq result (list 'and result (hif-eq-expr)))) |
| 466 | result)) | 439 | result)) |
| 467 | 440 | ||
| 441 | (defun hif-eq-expr () | ||
| 442 | "Parse a term of the form | ||
| 443 | eq-expr : math | eq-expr '=='|'!=' math." | ||
| 444 | (let ((result (hif-math)) | ||
| 445 | (eq-token nil)) | ||
| 446 | (while (or (eq token 'equal) (eq token 'hif-notequal)) | ||
| 447 | (setq eq-token token) | ||
| 448 | (hif-nexttoken) | ||
| 449 | (setq result (list eq-token result (hif-math)))) | ||
| 450 | result)) | ||
| 451 | |||
| 452 | (defun hif-math () | ||
| 453 | "Parse an expression of the form | ||
| 454 | math : factor | math '+|-' factor." | ||
| 455 | (let ((result (hif-factor)) | ||
| 456 | (math-op nil)) | ||
| 457 | (while (or (eq token 'hif-plus) (eq token 'hif-minus)) | ||
| 458 | (setq math-op token) | ||
| 459 | (hif-nexttoken) | ||
| 460 | (setq result (list math-op result (hif-factor)))) | ||
| 461 | result)) | ||
| 462 | |||
| 468 | (defun hif-factor () | 463 | (defun hif-factor () |
| 469 | "Parse a factor of the form | 464 | "Parse a factor of the form |
| 470 | factor : '!' factor | '(' expr ')' | 'defined(' id ')' | id." | 465 | factor : '!' factor | '(' expr ')' | 'defined(' id ')' | id." |
| @@ -505,6 +500,24 @@ that form should be displayed.") | |||
| 505 | )) | 500 | )) |
| 506 | )) | 501 | )) |
| 507 | 502 | ||
| 503 | (defun hif-mathify (val) | ||
| 504 | "Treat VAL as a number: if it's t or nil, use 1 or 0." | ||
| 505 | (cond ((eq val t) | ||
| 506 | 1) | ||
| 507 | ((null val) | ||
| 508 | 0) | ||
| 509 | (t val))) | ||
| 510 | |||
| 511 | (defun hif-plus (a b) | ||
| 512 | "Like ordinary plus but treat t and nil as 1 and 0." | ||
| 513 | (+ (hif-mathify a) (hif-mathify b))) | ||
| 514 | (defun hif-minus (a b) | ||
| 515 | "Like ordinary minus but treat t and nil as 1 and 0." | ||
| 516 | (- (hif-mathify a) (hif-mathify b))) | ||
| 517 | (defun hif-notequal (a b) | ||
| 518 | "Like (not (equal A B)) but as one symbol." | ||
| 519 | (not (equal a b))) | ||
| 520 | |||
| 508 | ;;;----------- end of parser ----------------------- | 521 | ;;;----------- end of parser ----------------------- |
| 509 | 522 | ||
| 510 | 523 | ||
| @@ -898,7 +911,7 @@ is first activated.") | |||
| 898 | (defun hide-ifdef-define (var) | 911 | (defun hide-ifdef-define (var) |
| 899 | "Define a VAR so that #ifdef VAR would be included." | 912 | "Define a VAR so that #ifdef VAR would be included." |
| 900 | (interactive "SDefine what? ") | 913 | (interactive "SDefine what? ") |
| 901 | (hif-set-var var t) | 914 | (hif-set-var var 1) |
| 902 | (if hide-ifdef-hiding (hide-ifdefs))) | 915 | (if hide-ifdef-hiding (hide-ifdefs))) |
| 903 | 916 | ||
| 904 | (defun hide-ifdef-undef (var) | 917 | (defun hide-ifdef-undef (var) |