diff options
| author | Stefan Monnier | 2010-12-26 18:17:09 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2010-12-26 18:17:09 -0500 |
| commit | 723ee192a5b3c6ebf589d325d5d004e57ce42652 (patch) | |
| tree | 64cf94c5c7fdda8f84f87767c8a612e58e27a8e6 | |
| parent | e77714da30b53ec866d2bbfd88527b215a715bb0 (diff) | |
| download | emacs-723ee192a5b3c6ebf589d325d5d004e57ce42652.tar.gz emacs-723ee192a5b3c6ebf589d325d5d004e57ce42652.zip | |
* lisp/emacs-lisp/rx.el: Make it a superset of sregex.
(rx-constituents): Add `any => "."', mark `repeat' as taking any number
of args, add `regex' alias.
(rx-info): Add arg to distinguish head and standalone forms.
(rx-check, rx-form): Pass the corresponding arg.
(rx-**): Simplify.
(rx-repeat): Make it work for any number of args.
(rx-syntax): Make it accept syntax chars as is.
* lisp/obsolete/sregex.el: Move from emacs-lisp/.
* lisp/emacs-lisp/re-builder.el: Remove sregex support.
* lisp/emacs-lisp/edebug.el (sregexq, rx): Remove redundant defs.
| -rw-r--r-- | etc/NEWS | 2 | ||||
| -rw-r--r-- | lisp/ChangeLog | 18 | ||||
| -rw-r--r-- | lisp/emacs-lisp/edebug.el | 2 | ||||
| -rw-r--r-- | lisp/emacs-lisp/re-builder.el | 19 | ||||
| -rw-r--r-- | lisp/emacs-lisp/rx.el | 59 | ||||
| -rw-r--r-- | lisp/obsolete/sregex.el (renamed from lisp/emacs-lisp/sregex.el) | 1 |
6 files changed, 64 insertions, 37 deletions
| @@ -541,6 +541,8 @@ listing object name completions when being sent text via | |||
| 541 | 541 | ||
| 542 | *** An API for manipulating SQL product definitions has been added. | 542 | *** An API for manipulating SQL product definitions has been added. |
| 543 | 543 | ||
| 544 | ** sregex.el is now obsolete, since rx.el is a strict superset. | ||
| 545 | |||
| 544 | ** s-region.el is now declared obsolete, superceded by shift-select-mode | 546 | ** s-region.el is now declared obsolete, superceded by shift-select-mode |
| 545 | enabled by default in 23.1. | 547 | enabled by default in 23.1. |
| 546 | 548 | ||
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ccf5b5c40ea..21d90eee903 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | 2010-12-26 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/rx.el: Make it a superset of sregex. | ||
| 4 | (rx-constituents): Add `any => "."', mark `repeat' as taking any number | ||
| 5 | of args, add `regex' alias. | ||
| 6 | (rx-info): Add arg to distinguish head and standalone forms. | ||
| 7 | (rx-check, rx-form): Pass the corresponding arg. | ||
| 8 | (rx-**): Simplify. | ||
| 9 | (rx-repeat): Make it work for any number of args. | ||
| 10 | (rx-syntax): Make it accept syntax chars as is. | ||
| 11 | * obsolete/sregex.el: Move from emacs-lisp/. | ||
| 12 | * emacs-lisp/re-builder.el: Remove sregex support. | ||
| 13 | * emacs-lisp/edebug.el (sregexq, rx): Remove redundant defs. | ||
| 14 | |||
| 1 | 2010-12-25 Eli Zaretskii <eliz@gnu.org> | 15 | 2010-12-25 Eli Zaretskii <eliz@gnu.org> |
| 2 | 16 | ||
| 3 | * mouse.el (mouse-yank-primary): On MS-Windows, try the (emulated) | 17 | * mouse.el (mouse-yank-primary): On MS-Windows, try the (emulated) |
| @@ -19,8 +33,8 @@ | |||
| 19 | 2010-12-21 Daiki Ueno <ueno@unixuser.org> | 33 | 2010-12-21 Daiki Ueno <ueno@unixuser.org> |
| 20 | 34 | ||
| 21 | * obsolete/pgg-parse.el, obsolete/pgg-pgp5.el, obsolete/pgg-pgp.el, | 35 | * obsolete/pgg-parse.el, obsolete/pgg-pgp5.el, obsolete/pgg-pgp.el, |
| 22 | * obsolete/pgg-gpg.el, obsolete/pgg-def.el, obsolete/pgg.el: Move | 36 | * obsolete/pgg-gpg.el, obsolete/pgg-def.el, obsolete/pgg.el: |
| 23 | from lisp/. | 37 | Move from lisp/. |
| 24 | 38 | ||
| 25 | 2010-12-20 Leo <sdl.web@gmail.com> | 39 | 2010-12-20 Leo <sdl.web@gmail.com> |
| 26 | 40 | ||
diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index 77953b37021..d4af24aaaff 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el | |||
| @@ -2131,8 +2131,6 @@ expressions; a `progn' form will be returned enclosing these forms." | |||
| 2131 | 2131 | ||
| 2132 | (def-edebug-spec with-custom-print body) | 2132 | (def-edebug-spec with-custom-print body) |
| 2133 | 2133 | ||
| 2134 | (def-edebug-spec sregexq (&rest sexp)) | ||
| 2135 | (def-edebug-spec rx (&rest sexp)) | ||
| 2136 | 2134 | ||
| 2137 | ;;; The debugger itself | 2135 | ;;; The debugger itself |
| 2138 | 2136 | ||
diff --git a/lisp/emacs-lisp/re-builder.el b/lisp/emacs-lisp/re-builder.el index 1845effd5bb..eacabf72c95 100644 --- a/lisp/emacs-lisp/re-builder.el +++ b/lisp/emacs-lisp/re-builder.el | |||
| @@ -60,8 +60,8 @@ | |||
| 60 | ;; even the auto updates go all the way. Forcing an update overrides | 60 | ;; even the auto updates go all the way. Forcing an update overrides |
| 61 | ;; this limit allowing an easy way to see all matches. | 61 | ;; this limit allowing an easy way to see all matches. |
| 62 | 62 | ||
| 63 | ;; Currently `re-builder' understands five different forms of input, | 63 | ;; Currently `re-builder' understands three different forms of input, |
| 64 | ;; namely `read', `string', `rx', and `sregex' syntax. Read | 64 | ;; namely `read', `string', and `rx' syntax. Read |
| 65 | ;; syntax and string syntax are both delimited by `"'s and behave | 65 | ;; syntax and string syntax are both delimited by `"'s and behave |
| 66 | ;; according to their name. With the `string' syntax there's no need | 66 | ;; according to their name. With the `string' syntax there's no need |
| 67 | ;; to escape the backslashes and double quotes simplifying the editing | 67 | ;; to escape the backslashes and double quotes simplifying the editing |
| @@ -75,7 +75,7 @@ | |||
| 75 | ;; When editing a symbolic regular expression, only the first | 75 | ;; When editing a symbolic regular expression, only the first |
| 76 | ;; expression in the RE Builder buffer is considered, which helps | 76 | ;; expression in the RE Builder buffer is considered, which helps |
| 77 | ;; limiting the extent of the expression like the `"'s do for the text | 77 | ;; limiting the extent of the expression like the `"'s do for the text |
| 78 | ;; modes. For the `sregex' syntax the function `sregex' is applied to | 78 | ;; modes. For the `rx' syntax the function `rx-to-string' is applied to |
| 79 | ;; the evaluated expression read. So you can use quoted arguments | 79 | ;; the evaluated expression read. So you can use quoted arguments |
| 80 | ;; with something like '("findme") or you can construct arguments to | 80 | ;; with something like '("findme") or you can construct arguments to |
| 81 | ;; your hearts delight with a valid ELisp expression. (The compiled | 81 | ;; your hearts delight with a valid ELisp expression. (The compiled |
| @@ -126,11 +126,10 @@ | |||
| 126 | 126 | ||
| 127 | (defcustom reb-re-syntax 'read | 127 | (defcustom reb-re-syntax 'read |
| 128 | "Syntax for the REs in the RE Builder. | 128 | "Syntax for the REs in the RE Builder. |
| 129 | Can either be `read', `string', `sregex', or `rx'." | 129 | Can either be `read', `string', or `rx'." |
| 130 | :group 're-builder | 130 | :group 're-builder |
| 131 | :type '(choice (const :tag "Read syntax" read) | 131 | :type '(choice (const :tag "Read syntax" read) |
| 132 | (const :tag "String syntax" string) | 132 | (const :tag "String syntax" string) |
| 133 | (const :tag "`sregex' syntax" sregex) | ||
| 134 | (const :tag "`rx' syntax" rx))) | 133 | (const :tag "`rx' syntax" rx))) |
| 135 | 134 | ||
| 136 | (defcustom reb-auto-match-limit 200 | 135 | (defcustom reb-auto-match-limit 200 |
| @@ -279,10 +278,8 @@ Except for Lisp syntax this is the same as `reb-regexp'.") | |||
| 279 | emacs-lisp-mode "RE Builder Lisp" | 278 | emacs-lisp-mode "RE Builder Lisp" |
| 280 | "Major mode for interactively building symbolic Regular Expressions." | 279 | "Major mode for interactively building symbolic Regular Expressions." |
| 281 | ;; Pull in packages as needed | 280 | ;; Pull in packages as needed |
| 282 | (cond ((eq reb-re-syntax 'sregex) ; sregex is not autoloaded | 281 | (cond ((memq reb-re-syntax '(sregex rx)) ; rx-to-string is autoloaded |
| 283 | (require 'sregex)) ; right now.. | 282 | (require 'rx))) ; require rx anyway |
| 284 | ((eq reb-re-syntax 'rx) ; rx-to-string is autoloaded | ||
| 285 | (require 'rx))) ; require rx anyway | ||
| 286 | (reb-mode-common)) | 283 | (reb-mode-common)) |
| 287 | 284 | ||
| 288 | ;; Use the same "\C-c" keymap as `reb-mode' and use font-locking from | 285 | ;; Use the same "\C-c" keymap as `reb-mode' and use font-locking from |
| @@ -612,9 +609,7 @@ optional fourth argument FORCE is non-nil." | |||
| 612 | 609 | ||
| 613 | (defun reb-cook-regexp (re) | 610 | (defun reb-cook-regexp (re) |
| 614 | "Return RE after processing it according to `reb-re-syntax'." | 611 | "Return RE after processing it according to `reb-re-syntax'." |
| 615 | (cond ((eq reb-re-syntax 'sregex) | 612 | (cond ((memq reb-re-syntax '(sregex rx)) |
| 616 | (apply 'sregex (eval (car (read-from-string re))))) | ||
| 617 | ((eq reb-re-syntax 'rx) | ||
| 618 | (rx-to-string (eval (car (read-from-string re))))) | 613 | (rx-to-string (eval (car (read-from-string re))))) |
| 619 | (t re))) | 614 | (t re))) |
| 620 | 615 | ||
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index 522d452c2dc..b3b88c3ce4f 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el | |||
| @@ -120,19 +120,17 @@ | |||
| 120 | (nonl . not-newline) ; SRE | 120 | (nonl . not-newline) ; SRE |
| 121 | (anything . (rx-anything 0 nil)) | 121 | (anything . (rx-anything 0 nil)) |
| 122 | (any . (rx-any 1 nil rx-check-any)) ; inconsistent with SRE | 122 | (any . (rx-any 1 nil rx-check-any)) ; inconsistent with SRE |
| 123 | (any . ".") ; sregex | ||
| 123 | (in . any) | 124 | (in . any) |
| 124 | (char . any) ; sregex | 125 | (char . any) ; sregex |
| 125 | (not-char . (rx-not-char 1 nil rx-check-any)) ; sregex | 126 | (not-char . (rx-not-char 1 nil rx-check-any)) ; sregex |
| 126 | (not . (rx-not 1 1 rx-check-not)) | 127 | (not . (rx-not 1 1 rx-check-not)) |
| 127 | ;; Partially consistent with sregex, whose `repeat' is like our | 128 | (repeat . (rx-repeat 2 nil)) |
| 128 | ;; `**'. (`repeat' with optional max arg and multiple sexp forms | ||
| 129 | ;; is ambiguous.) | ||
| 130 | (repeat . (rx-repeat 2 3)) | ||
| 131 | (= . (rx-= 2 nil)) ; SRE | 129 | (= . (rx-= 2 nil)) ; SRE |
| 132 | (>= . (rx->= 2 nil)) ; SRE | 130 | (>= . (rx->= 2 nil)) ; SRE |
| 133 | (** . (rx-** 2 nil)) ; SRE | 131 | (** . (rx-** 2 nil)) ; SRE |
| 134 | (submatch . (rx-submatch 1 nil)) ; SRE | 132 | (submatch . (rx-submatch 1 nil)) ; SRE |
| 135 | (group . submatch) | 133 | (group . submatch) ; sregex |
| 136 | (zero-or-more . (rx-kleene 1 nil)) | 134 | (zero-or-more . (rx-kleene 1 nil)) |
| 137 | (one-or-more . (rx-kleene 1 nil)) | 135 | (one-or-more . (rx-kleene 1 nil)) |
| 138 | (zero-or-one . (rx-kleene 1 nil)) | 136 | (zero-or-one . (rx-kleene 1 nil)) |
| @@ -175,6 +173,7 @@ | |||
| 175 | (category . (rx-category 1 1 rx-check-category)) | 173 | (category . (rx-category 1 1 rx-check-category)) |
| 176 | (eval . (rx-eval 1 1)) | 174 | (eval . (rx-eval 1 1)) |
| 177 | (regexp . (rx-regexp 1 1 stringp)) | 175 | (regexp . (rx-regexp 1 1 stringp)) |
| 176 | (regex . regexp) ; sregex | ||
| 178 | (digit . "[[:digit:]]") | 177 | (digit . "[[:digit:]]") |
| 179 | (numeric . digit) ; SRE | 178 | (numeric . digit) ; SRE |
| 180 | (num . digit) ; SRE | 179 | (num . digit) ; SRE |
| @@ -295,15 +294,27 @@ regular expression strings.") | |||
| 295 | `zero-or-more', and `one-or-more'. Dynamically bound.") | 294 | `zero-or-more', and `one-or-more'. Dynamically bound.") |
| 296 | 295 | ||
| 297 | 296 | ||
| 298 | (defun rx-info (op) | 297 | (defun rx-info (op head) |
| 299 | "Return parsing/code generation info for OP. | 298 | "Return parsing/code generation info for OP. |
| 300 | If OP is the space character ASCII 32, return info for the symbol `?'. | 299 | If OP is the space character ASCII 32, return info for the symbol `?'. |
| 301 | If OP is the character `?', return info for the symbol `??'. | 300 | If OP is the character `?', return info for the symbol `??'. |
| 302 | See also `rx-constituents'." | 301 | See also `rx-constituents'. |
| 302 | If HEAD is non-nil, then OP is the head of a sexp, otherwise it's | ||
| 303 | a standalone symbol." | ||
| 303 | (cond ((eq op ? ) (setq op '\?)) | 304 | (cond ((eq op ? ) (setq op '\?)) |
| 304 | ((eq op ??) (setq op '\??))) | 305 | ((eq op ??) (setq op '\??))) |
| 305 | (while (and (not (null op)) (symbolp op)) | 306 | (let (old-op) |
| 306 | (setq op (cdr (assq op rx-constituents)))) | 307 | (while (and (not (null op)) (symbolp op)) |
| 308 | (setq old-op op) | ||
| 309 | (setq op (cdr (assq op rx-constituents))) | ||
| 310 | (when (if head (stringp op) (consp op)) | ||
| 311 | ;; We found something but of the wrong kind. Let's look for an | ||
| 312 | ;; alternate definition for the other case. | ||
| 313 | (let ((new-op | ||
| 314 | (cdr (assq old-op (cdr (memq (assq old-op rx-constituents) | ||
| 315 | rx-constituents)))))) | ||
| 316 | (if (and new-op (not (if head (stringp new-op) (consp new-op)))) | ||
| 317 | (setq op new-op)))))) | ||
| 307 | op) | 318 | op) |
| 308 | 319 | ||
| 309 | 320 | ||
| @@ -311,7 +322,7 @@ See also `rx-constituents'." | |||
| 311 | "Check FORM according to its car's parsing info." | 322 | "Check FORM according to its car's parsing info." |
| 312 | (unless (listp form) | 323 | (unless (listp form) |
| 313 | (error "rx `%s' needs argument(s)" form)) | 324 | (error "rx `%s' needs argument(s)" form)) |
| 314 | (let* ((rx (rx-info (car form))) | 325 | (let* ((rx (rx-info (car form) 'head)) |
| 315 | (nargs (1- (length form))) | 326 | (nargs (1- (length form))) |
| 316 | (min-args (nth 1 rx)) | 327 | (min-args (nth 1 rx)) |
| 317 | (max-args (nth 2 rx)) | 328 | (max-args (nth 2 rx)) |
| @@ -643,14 +654,17 @@ If SKIP is non-nil, allow that number of items after the head, i.e. | |||
| 643 | (defun rx-** (form) | 654 | (defun rx-** (form) |
| 644 | "Parse and produce code from FORM `(** N M ...)'." | 655 | "Parse and produce code from FORM `(** N M ...)'." |
| 645 | (rx-check form) | 656 | (rx-check form) |
| 646 | (setq form (cons 'repeat (cdr (rx-trans-forms form 2)))) | 657 | (rx-form (cons 'repeat (cdr (rx-trans-forms form 2))) '*)) |
| 647 | (rx-form form '*)) | ||
| 648 | 658 | ||
| 649 | 659 | ||
| 650 | (defun rx-repeat (form) | 660 | (defun rx-repeat (form) |
| 651 | "Parse and produce code from FORM. | 661 | "Parse and produce code from FORM. |
| 652 | FORM is either `(repeat N FORM1)' or `(repeat N M FORM1)'." | 662 | FORM is either `(repeat N FORM1)' or `(repeat N M FORMS...)'." |
| 653 | (rx-check form) | 663 | (rx-check form) |
| 664 | (if (> (length form) 4) | ||
| 665 | (setq form (rx-trans-forms form 2))) | ||
| 666 | (if (null (nth 2 form)) | ||
| 667 | (setq form (list* (nth 0 form) (nth 1 form) (nthcdr 3 form)))) | ||
| 654 | (cond ((= (length form) 3) | 668 | (cond ((= (length form) 3) |
| 655 | (unless (and (integerp (nth 1 form)) | 669 | (unless (and (integerp (nth 1 form)) |
| 656 | (> (nth 1 form) 0)) | 670 | (> (nth 1 form) 0)) |
| @@ -749,15 +763,18 @@ of all atomic regexps." | |||
| 749 | "Parse and produce code from FORM, which is `(syntax SYMBOL)'." | 763 | "Parse and produce code from FORM, which is `(syntax SYMBOL)'." |
| 750 | (rx-check form) | 764 | (rx-check form) |
| 751 | (let* ((sym (cadr form)) | 765 | (let* ((sym (cadr form)) |
| 752 | (syntax (assq sym rx-syntax))) | 766 | (syntax (cdr (assq sym rx-syntax)))) |
| 753 | (unless syntax | 767 | (unless syntax |
| 754 | ;; Try sregex compatibility. | 768 | ;; Try sregex compatibility. |
| 755 | (let ((name (symbol-name sym))) | 769 | (cond |
| 756 | (if (= 1 (length name)) | 770 | ((character sym) (setq syntax sym)) |
| 757 | (setq syntax (rassq (aref name 0) rx-syntax)))) | 771 | ((symbolp sym) |
| 772 | (let ((name (symbol-name sym))) | ||
| 773 | (if (= 1 (length name)) | ||
| 774 | (setq syntax (aref name 0)))))) | ||
| 758 | (unless syntax | 775 | (unless syntax |
| 759 | (error "Unknown rx syntax `%s'" (cadr form)))) | 776 | (error "Unknown rx syntax `%s'" sym))) |
| 760 | (format "\\s%c" (cdr syntax)))) | 777 | (format "\\s%c" syntax))) |
| 761 | 778 | ||
| 762 | 779 | ||
| 763 | (defun rx-check-category (form) | 780 | (defun rx-check-category (form) |
| @@ -811,7 +828,7 @@ shy groups around the result and some more in other functions." | |||
| 811 | (cond ((integerp form) | 828 | (cond ((integerp form) |
| 812 | (regexp-quote (char-to-string form))) | 829 | (regexp-quote (char-to-string form))) |
| 813 | ((symbolp form) | 830 | ((symbolp form) |
| 814 | (let ((info (rx-info form))) | 831 | (let ((info (rx-info form nil))) |
| 815 | (cond ((stringp info) | 832 | (cond ((stringp info) |
| 816 | info) | 833 | info) |
| 817 | ((null info) | 834 | ((null info) |
| @@ -819,7 +836,7 @@ shy groups around the result and some more in other functions." | |||
| 819 | (t | 836 | (t |
| 820 | (funcall (nth 0 info) form))))) | 837 | (funcall (nth 0 info) form))))) |
| 821 | ((consp form) | 838 | ((consp form) |
| 822 | (let ((info (rx-info (car form)))) | 839 | (let ((info (rx-info (car form) 'head))) |
| 823 | (unless (consp info) | 840 | (unless (consp info) |
| 824 | (error "Unknown rx form `%s'" (car form))) | 841 | (error "Unknown rx form `%s'" (car form))) |
| 825 | (funcall (nth 0 info) form))) | 842 | (funcall (nth 0 info) form))) |
diff --git a/lisp/emacs-lisp/sregex.el b/lisp/obsolete/sregex.el index f5e3aac231c..ef4700c15f8 100644 --- a/lisp/emacs-lisp/sregex.el +++ b/lisp/obsolete/sregex.el | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | ;; Author: Bob Glickstein <bobg+sregex@zanshin.com> | 6 | ;; Author: Bob Glickstein <bobg+sregex@zanshin.com> |
| 7 | ;; Maintainer: Bob Glickstein <bobg+sregex@zanshin.com> | 7 | ;; Maintainer: Bob Glickstein <bobg+sregex@zanshin.com> |
| 8 | ;; Keywords: extensions | 8 | ;; Keywords: extensions |
| 9 | ;; Obsolete-since: 24.1 | ||
| 9 | 10 | ||
| 10 | ;; This file is part of GNU Emacs. | 11 | ;; This file is part of GNU Emacs. |
| 11 | 12 | ||