emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r104629: Add rx.el support for number


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104629: Add rx.el support for numbered groups (Bug#8776).
Date: Sat, 18 Jun 2011 17:12:33 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104629
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sat 2011-06-18 17:12:33 -0400
message:
  Add rx.el support for numbered groups (Bug#8776).
  
  * lisp/emacs-lisp/rx.el (rx-constituents): Add support for numbered groups.
  (rx-submatch-n): New function.
  (rx): Document it.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/emacs-lisp/rx.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2011-06-11 17:54:53 +0000
+++ b/etc/NEWS  2011-06-18 21:12:33 +0000
@@ -1051,6 +1051,9 @@
 ** `set-auto-mode' now respects mode: local variables at the end of files,
 as well as those in the -*- line.
 
+---
+** rx.el has a new `group-n' construct for explicitly numbered groups.
+
 
 * Changes in Emacs 24.1 on non-free operating systems
 

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-06-18 20:17:30 +0000
+++ b/lisp/ChangeLog    2011-06-18 21:12:33 +0000
@@ -1,5 +1,10 @@
 2011-06-18  Chong Yidong  <address@hidden>
 
+       * emacs-lisp/rx.el (rx-constituents): Add support for numbered
+       groups (Bug#8776).
+       (rx-submatch-n): New function.
+       (rx): Document it.
+
        * dired-x.el (dired-mark-unmarked-files): Fix interactive spec
        (Bug#8768).
 

=== modified file 'lisp/emacs-lisp/rx.el'
--- a/lisp/emacs-lisp/rx.el     2011-01-25 04:08:28 +0000
+++ b/lisp/emacs-lisp/rx.el     2011-06-18 21:12:33 +0000
@@ -130,6 +130,8 @@
     (**                        . (rx-** 2 nil))   ; SRE
     (submatch          . (rx-submatch 1 nil)) ; SRE
     (group             . submatch)     ; sregex
+    (submatch-n                . (rx-submatch-n 2 nil))
+    (group-n           . submatch-n)
     (zero-or-more      . (rx-kleene 1 nil))
     (one-or-more       . (rx-kleene 1 nil))
     (zero-or-one       . (rx-kleene 1 nil))
@@ -690,6 +692,16 @@
             (mapconcat (lambda (re) (rx-form re ':)) (cdr form) nil))
           "\\)"))
 
+(defun rx-submatch-n (form)
+  "Parse and produce code from FORM, which is `(submatch-n N ...)'."
+  (let ((n (nth 1 form)))
+    (concat "\\(?" (number-to-string n) ":"
+           (if (= 3 (length form))
+               ;; Only one sub-form.
+               (rx-form (nth 2 form))
+             ;; Several sub-forms implicitly concatenated.
+             (mapconcat (lambda (re) (rx-form re ':)) (cddr form) nil))
+           "\\)")))
 
 (defun rx-backref (form)
   "Parse and produce code from FORM, which is `(backref N)'."
@@ -1072,6 +1084,11 @@
      like `and', but makes the match accessible with `match-end',
      `match-beginning', and `match-string'.
 
+`(submatch-n N SEXP1 SEXP2 ...)'
+`(group-n N SEXP1 SEXP2 ...)'
+     like `group', but make it an explicitly-numbered group with
+     group number N.
+
 `(or SEXP1 SEXP2 ...)'
 `(| SEXP1 SEXP2 ...)'
      matches anything that matches SEXP1 or SEXP2, etc.  If all


reply via email to

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