emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r102708: * lisp/emacs-lisp/rx.el: Mak


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r102708: * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Date: Sun, 26 Dec 2010 18:17:09 -0500
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 102708
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Sun 2010-12-26 18:17:09 -0500
message:
  * 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.
renamed:
  lisp/emacs-lisp/sregex.el => lisp/obsolete/sregex.el
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/emacs-lisp/edebug.el
  lisp/emacs-lisp/re-builder.el
  lisp/emacs-lisp/rx.el
  lisp/obsolete/sregex.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2010-12-20 11:11:30 +0000
+++ b/etc/NEWS  2010-12-26 23:17:09 +0000
@@ -541,6 +541,8 @@
 
 *** An API for manipulating SQL product definitions has been added.
 
+** sregex.el is now obsolete, since rx.el is a strict superset.
+
 ** s-region.el is now declared obsolete, superceded by shift-select-mode
 enabled by default in 23.1.
 

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-12-25 10:57:02 +0000
+++ b/lisp/ChangeLog    2010-12-26 23:17:09 +0000
@@ -1,3 +1,17 @@
+2010-12-26  Stefan Monnier  <address@hidden>
+
+       * 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.
+       * obsolete/sregex.el: Move from emacs-lisp/.
+       * emacs-lisp/re-builder.el: Remove sregex support.
+       * emacs-lisp/edebug.el (sregexq, rx): Remove redundant defs.
+
 2010-12-25  Eli Zaretskii  <address@hidden>
 
        * mouse.el (mouse-yank-primary): On MS-Windows, try the (emulated)
@@ -19,8 +33,8 @@
 2010-12-21  Daiki Ueno  <address@hidden>
 
        * obsolete/pgg-parse.el, obsolete/pgg-pgp5.el, obsolete/pgg-pgp.el,
-       * obsolete/pgg-gpg.el, obsolete/pgg-def.el, obsolete/pgg.el: Move
-       from lisp/.
+       * obsolete/pgg-gpg.el, obsolete/pgg-def.el, obsolete/pgg.el:
+       Move from lisp/.
 
 2010-12-20  Leo  <address@hidden>
 

=== modified file 'lisp/emacs-lisp/edebug.el'
--- a/lisp/emacs-lisp/edebug.el 2010-11-06 20:23:42 +0000
+++ b/lisp/emacs-lisp/edebug.el 2010-12-26 23:17:09 +0000
@@ -2131,8 +2131,6 @@
 
 (def-edebug-spec with-custom-print body)
 
-(def-edebug-spec sregexq (&rest sexp))
-(def-edebug-spec rx (&rest sexp))
 
 ;;; The debugger itself
 

=== modified file 'lisp/emacs-lisp/re-builder.el'
--- a/lisp/emacs-lisp/re-builder.el     2010-07-27 23:38:46 +0000
+++ b/lisp/emacs-lisp/re-builder.el     2010-12-26 23:17:09 +0000
@@ -60,8 +60,8 @@
 ;; even the auto updates go all the way.  Forcing an update overrides
 ;; this limit allowing an easy way to see all matches.
 
-;; Currently `re-builder' understands five different forms of input,
-;; namely `read', `string', `rx', and `sregex' syntax.  Read
+;; Currently `re-builder' understands three different forms of input,
+;; namely `read', `string', and `rx' syntax.  Read
 ;; syntax and string syntax are both delimited by `"'s and behave
 ;; according to their name.  With the `string' syntax there's no need
 ;; to escape the backslashes and double quotes simplifying the editing
@@ -75,7 +75,7 @@
 ;; When editing a symbolic regular expression, only the first
 ;; expression in the RE Builder buffer is considered, which helps
 ;; limiting the extent of the expression like the `"'s do for the text
-;; modes.  For the `sregex' syntax the function `sregex' is applied to
+;; modes.  For the `rx' syntax the function `rx-to-string' is applied to
 ;; the evaluated expression read.  So you can use quoted arguments
 ;; with something like '("findme") or you can construct arguments to
 ;; your hearts delight with a valid ELisp expression.  (The compiled
@@ -126,11 +126,10 @@
 
 (defcustom reb-re-syntax 'read
   "Syntax for the REs in the RE Builder.
-Can either be `read', `string', `sregex', or `rx'."
+Can either be `read', `string', or `rx'."
   :group 're-builder
   :type '(choice (const :tag "Read syntax" read)
                 (const :tag "String syntax" string)
-                (const :tag "`sregex' syntax" sregex)
                 (const :tag "`rx' syntax" rx)))
 
 (defcustom reb-auto-match-limit 200
@@ -279,10 +278,8 @@
   emacs-lisp-mode "RE Builder Lisp"
   "Major mode for interactively building symbolic Regular Expressions."
   ;; Pull in packages as needed
-  (cond        ((eq reb-re-syntax 'sregex)     ; sregex is not autoloaded
-        (require 'sregex))             ; right now..
-       ((eq reb-re-syntax 'rx)         ; rx-to-string is autoloaded
-        (require 'rx)))                ; require rx anyway
+  (cond        ((memq reb-re-syntax '(sregex rx)) ; rx-to-string is autoloaded
+        (require 'rx)))                   ; require rx anyway
   (reb-mode-common))
 
 ;; Use the same "\C-c" keymap as `reb-mode' and use font-locking from
@@ -612,9 +609,7 @@
 
 (defun reb-cook-regexp (re)
   "Return RE after processing it according to `reb-re-syntax'."
-  (cond ((eq reb-re-syntax 'sregex)
-        (apply 'sregex (eval (car (read-from-string re)))))
-       ((eq reb-re-syntax 'rx)
+  (cond ((memq reb-re-syntax '(sregex rx))
         (rx-to-string (eval (car (read-from-string re)))))
        (t re)))
 

=== modified file 'lisp/emacs-lisp/rx.el'
--- a/lisp/emacs-lisp/rx.el     2010-09-05 09:44:55 +0000
+++ b/lisp/emacs-lisp/rx.el     2010-12-26 23:17:09 +0000
@@ -120,19 +120,17 @@
     (nonl              . not-newline)  ; SRE
     (anything          . (rx-anything 0 nil))
     (any               . (rx-any 1 nil rx-check-any)) ; inconsistent with SRE
+    (any               . ".")          ; sregex
     (in                        . any)
     (char              . any)          ; sregex
     (not-char          . (rx-not-char 1 nil rx-check-any)) ; sregex
     (not               . (rx-not 1 1 rx-check-not))
-    ;; Partially consistent with sregex, whose `repeat' is like our
-    ;; `**'.  (`repeat' with optional max arg and multiple sexp forms
-    ;; is ambiguous.)
-    (repeat            . (rx-repeat 2 3))
+    (repeat            . (rx-repeat 2 nil))
     (=                 . (rx-= 2 nil))    ; SRE
     (>=                        . (rx->= 2 nil))   ; SRE
     (**                        . (rx-** 2 nil))   ; SRE
     (submatch          . (rx-submatch 1 nil)) ; SRE
-    (group             . submatch)
+    (group             . submatch)     ; sregex
     (zero-or-more      . (rx-kleene 1 nil))
     (one-or-more       . (rx-kleene 1 nil))
     (zero-or-one       . (rx-kleene 1 nil))
@@ -175,6 +173,7 @@
     (category          . (rx-category 1 1 rx-check-category))
     (eval              . (rx-eval 1 1))
     (regexp            . (rx-regexp 1 1 stringp))
+    (regex             . regexp)       ; sregex
     (digit             . "[[:digit:]]")
     (numeric           . digit)        ; SRE
     (num               . digit)        ; SRE
@@ -295,15 +294,27 @@
 `zero-or-more', and `one-or-more'.  Dynamically bound.")
 
 
-(defun rx-info (op)
+(defun rx-info (op head)
   "Return parsing/code generation info for OP.
 If OP is the space character ASCII 32, return info for the symbol `?'.
 If OP is the character `?', return info for the symbol `??'.
-See also `rx-constituents'."
+See also `rx-constituents'.
+If HEAD is non-nil, then OP is the head of a sexp, otherwise it's
+a standalone symbol."
   (cond ((eq op ? ) (setq op '\?))
        ((eq op ??) (setq op '\??)))
-  (while (and (not (null op)) (symbolp op))
-    (setq op (cdr (assq op rx-constituents))))
+  (let (old-op)
+    (while (and (not (null op)) (symbolp op))
+      (setq old-op op)
+      (setq op (cdr (assq op rx-constituents)))
+      (when (if head (stringp op) (consp op))
+        ;; We found something but of the wrong kind.  Let's look for an
+        ;; alternate definition for the other case.
+        (let ((new-op
+               (cdr (assq old-op (cdr (memq (assq old-op rx-constituents)
+                                            rx-constituents))))))
+          (if (and new-op (not (if head (stringp new-op) (consp new-op))))
+              (setq op new-op))))))
   op)
 
 
@@ -311,7 +322,7 @@
   "Check FORM according to its car's parsing info."
   (unless (listp form)
     (error "rx `%s' needs argument(s)" form))
-  (let* ((rx (rx-info (car form)))
+  (let* ((rx (rx-info (car form) 'head))
         (nargs (1- (length form)))
         (min-args (nth 1 rx))
         (max-args (nth 2 rx))
@@ -643,14 +654,17 @@
 (defun rx-** (form)
   "Parse and produce code from FORM `(** N M ...)'."
   (rx-check form)
-  (setq form (cons 'repeat (cdr (rx-trans-forms form 2))))
-  (rx-form form '*))
+  (rx-form (cons 'repeat (cdr (rx-trans-forms form 2))) '*))
 
 
 (defun rx-repeat (form)
   "Parse and produce code from FORM.
-FORM is either `(repeat N FORM1)' or `(repeat N M FORM1)'."
+FORM is either `(repeat N FORM1)' or `(repeat N M FORMS...)'."
   (rx-check form)
+  (if (> (length form) 4)
+      (setq form (rx-trans-forms form 2)))
+  (if (null (nth 2 form))
+      (setq form (list* (nth 0 form) (nth 1 form) (nthcdr 3 form))))
   (cond ((= (length form) 3)
         (unless (and (integerp (nth 1 form))
                      (> (nth 1 form) 0))
@@ -749,15 +763,18 @@
   "Parse and produce code from FORM, which is `(syntax SYMBOL)'."
   (rx-check form)
   (let* ((sym (cadr form))
-        (syntax (assq sym rx-syntax)))
+        (syntax (cdr (assq sym rx-syntax))))
     (unless syntax
       ;; Try sregex compatibility.
-      (let ((name (symbol-name sym)))
-       (if (= 1 (length name))
-           (setq syntax (rassq (aref name 0) rx-syntax))))
+      (cond
+       ((character sym) (setq syntax sym))
+       ((symbolp sym)
+        (let ((name (symbol-name sym)))
+          (if (= 1 (length name))
+              (setq syntax (aref name 0))))))
       (unless syntax
-       (error "Unknown rx syntax `%s'" (cadr form))))
-    (format "\\s%c" (cdr syntax))))
+       (error "Unknown rx syntax `%s'" sym)))
+    (format "\\s%c" syntax)))
 
 
 (defun rx-check-category (form)
@@ -811,7 +828,7 @@
     (cond ((integerp form)
           (regexp-quote (char-to-string form)))
          ((symbolp form)
-          (let ((info (rx-info form)))
+          (let ((info (rx-info form nil)))
             (cond ((stringp info)
                    info)
                   ((null info)
@@ -819,7 +836,7 @@
                   (t
                    (funcall (nth 0 info) form)))))
          ((consp form)
-          (let ((info (rx-info (car form))))
+          (let ((info (rx-info (car form) 'head)))
             (unless (consp info)
               (error "Unknown rx form `%s'" (car form)))
             (funcall (nth 0 info) form)))

=== renamed file 'lisp/emacs-lisp/sregex.el' => 'lisp/obsolete/sregex.el'
--- a/lisp/emacs-lisp/sregex.el 2010-01-13 08:35:10 +0000
+++ b/lisp/obsolete/sregex.el   2010-12-26 23:17:09 +0000
@@ -6,6 +6,7 @@
 ;; Author: Bob Glickstein <address@hidden>
 ;; Maintainer: Bob Glickstein <address@hidden>
 ;; Keywords: extensions
+;; Obsolete-since: 24.1
 
 ;; This file is part of GNU Emacs.
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]