aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schwab2002-03-06 15:12:01 +0000
committerAndreas Schwab2002-03-06 15:12:01 +0000
commit2dc2ec3d4976d285fbc76b942dfa14182643f1b5 (patch)
tree62cf2034a2e3b70cab573a4ee27ab11749d3e272
parent8b5eabe078efd10203fb0a428b2e99926fc6d0ba (diff)
downloademacs-2dc2ec3d4976d285fbc76b942dfa14182643f1b5.tar.gz
emacs-2dc2ec3d4976d285fbc76b942dfa14182643f1b5.zip
Augment expression parser to handle conditional expressions.
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/progmodes/hideif.el32
2 files changed, 37 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2dc2615aba8..4ddb998e60e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
12002-03-06 Andreas Schwab <schwab@suse.de>
2
3 * progmodes/hideif.el: Augment expression parser to handle
4 conditional expressions.
5 (hif-token-regexp): Also match `?' and `:'.
6 (hif-tokenize): Handle `?' and ':' as tokens.
7 (hif-expr): Parse conditional expressions.
8 (hif-or-expr): Parse `||' expressions.
9 (hif-and-expr): Renamed from hif-term.
10 (hif-conditional): New function to evaluate a conditional
11 expression.
12
12002-03-06 Gerd Moellmann <gerd@gnu.org> 132002-03-06 Gerd Moellmann <gerd@gnu.org>
2 14
3 * vc.el (vc-branch-part): Add autoload cookie. This function can 15 * vc.el (vc-branch-part): Add autoload cookie. This function can
diff --git a/lisp/progmodes/hideif.el b/lisp/progmodes/hideif.el
index e814f296f0e..0c88bc46fa1 100644
--- a/lisp/progmodes/hideif.el
+++ b/lisp/progmodes/hideif.el
@@ -1,6 +1,6 @@
1;;; hideif.el --- hides selected code within ifdef 1;;; hideif.el --- hides selected code within ifdef
2 2
3;; Copyright (C) 1988,1994,2001 Free Software Foundation, Inc. 3;; Copyright (C) 1988,1994,2001, 2002 Free Software Foundation, Inc.
4 4
5;; Author: Daniel LaLiberte <liberte@holonexus.org> 5;; Author: Daniel LaLiberte <liberte@holonexus.org>
6;; Maintainer: FSF 6;; Maintainer: FSF
@@ -309,7 +309,7 @@ that form should be displayed.")
309;; pattern to match initial identifier, !, &&, ||, (, or ). 309;; pattern to match initial identifier, !, &&, ||, (, or ).
310;; Added ==, + and -: garyo@avs.com 8/9/94 310;; Added ==, + and -: garyo@avs.com 8/9/94
311(defconst hif-token-regexp 311(defconst hif-token-regexp
312 "\\(&&\\|||\\|[!=]=\\|!\\|[()+-]\\|[<>]=?\\|\\w+\\)") 312 "\\(&&\\|||\\|[!=]=\\|!\\|[()+?:-]\\|[<>]=?\\|\\w+\\)")
313 313
314(defun hif-tokenize (start end) 314(defun hif-tokenize (start end)
315 "Separate string between START and END into a list of tokens." 315 "Separate string between START and END into a list of tokens."
@@ -342,6 +342,8 @@ that form should be displayed.")
342 ((string-equal token "<=") 'hif-less-equal) 342 ((string-equal token "<=") 'hif-less-equal)
343 ((string-equal token "+") 'hif-plus) 343 ((string-equal token "+") 'hif-plus)
344 ((string-equal token "-") 'hif-minus) 344 ((string-equal token "-") 'hif-minus)
345 ((string-equal token "?") 'hif-conditional)
346 ((string-equal token ":") 'hif-colon)
345 ((string-match "\\`[0-9]*\\'" token) 347 ((string-match "\\`[0-9]*\\'" token)
346 (string-to-number token)) 348 (string-to-number token))
347 (t (intern token))) 349 (t (intern token)))
@@ -368,15 +370,29 @@ that form should be displayed.")
368 370
369(defun hif-expr () 371(defun hif-expr ()
370 "Parse an expression as found in #if. 372 "Parse an expression as found in #if.
371 expr : term | expr '||' term." 373 expr : or-expr | or-expr '?' expr ':' expr."
372 (let ((result (hif-term))) 374 (let ((result (hif-or-expr))
375 middle)
376 (while (eq hif-token 'hif-conditional)
377 (hif-nexttoken)
378 (setq middle (hif-expr))
379 (if (eq hif-token 'hif-colon)
380 (progn
381 (hif-nexttoken)
382 (setq result (list 'hif-conditional result middle (hif-expr))))
383 (error "Error: unexpected token: %s" hif-token)))
384 result))
385
386(defun hif-or-expr ()
387 "Parse n or-expr : and-expr | or-expr '||' and-expr."
388 (let ((result (hif-and-expr)))
373 (while (eq hif-token 'or) 389 (while (eq hif-token 'or)
374 (hif-nexttoken) 390 (hif-nexttoken)
375 (setq result (list 'hif-or result (hif-term)))) 391 (setq result (list 'hif-or result (hif-and-expr))))
376 result)) 392 result))
377 393
378(defun hif-term () 394(defun hif-and-expr ()
379 "Parse a term : eq-expr | term '&&' eq-expr." 395 "Parse an and-expr : eq-expr | and-expr '&&' eq-expr."
380 (let ((result (hif-eq-expr))) 396 (let ((result (hif-eq-expr)))
381 (while (eq hif-token 'and) 397 (while (eq hif-token 'and)
382 (hif-nexttoken) 398 (hif-nexttoken)
@@ -449,6 +465,8 @@ that form should be displayed.")
449 ((null val) 0) 465 ((null val) 0)
450 (t val))) 466 (t val)))
451 467
468(defun hif-conditional (a b c)
469 (if (not (zerop (hif-mathify a))) (hif-mathify b) (hif-mathify c)))
452(defun hif-and (a b) 470(defun hif-and (a b)
453 (and (not (zerop (hif-mathify a))) (not (zerop (hif-mathify b))))) 471 (and (not (zerop (hif-mathify a))) (not (zerop (hif-mathify b)))))
454(defun hif-or (a b) 472(defun hif-or (a b)