From: Lennart Borgman <lennart.borgman@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 6384@debbugs.gnu.org
Subject: bug#6384: Teach rx explicitly numbered submatches
Date: Wed, 9 Jun 2010 20:19:52 +0200 [thread overview]
Message-ID: <AANLkTil8YNg_dRodt7YiU5wC1oQJo469i9oDU5Htu7Y3@mail.gmail.com> (raw)
In-Reply-To: <jwviq5sul5p.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 376 bytes --]
On Wed, Jun 9, 2010 at 8:16 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> Explicitly numbered groups are of the form
>
>> \(?nn:...\)
>
>> Here is a patch for it. Someone with good lisp fu might check it.
>
> I see an elisp file, not apatch. Can you resend it as a patch, please?
Ah, wrote the wrong buffer ... ;-)
Here it is, it is very small.
[-- Attachment #2: rx-submatch-n-1.diff --]
[-- Type: text/x-patch, Size: 1240 bytes --]
=== modified file 'lisp/emacs-lisp/rx.el'
--- trunk/lisp/emacs-lisp/rx.el 2010-01-13 08:35:10 +0000
+++ patched/lisp/emacs-lisp/rx.el 2010-06-09 17:18:56 +0000
@@ -132,6 +132,7 @@
(>= . (rx->= 2 nil)) ; SRE
(** . (rx-** 2 nil)) ; SRE
(submatch . (rx-submatch 1 nil)) ; SRE
+ (submatch-n . (rx-submatch-n 2 nil))
(group . submatch)
(zero-or-more . (rx-kleene 1 nil))
(one-or-more . (rx-kleene 1 nil))
@@ -674,6 +675,19 @@
(mapconcat (lambda (re) (rx-form re ':)) (cdr form) nil))
"\\)"))
+(defun rx-submatch-n (form)
+ "Parse and produce code from FORM, which is `(submatch-n ...)'."
+ (unless (and (integerp (nth 1 form))
+ (> (nth 1 form) 0))
+ (error "rx `submatch-n' requires positive integer first arg"))
+ (concat "\\(\?"
+ (format "%d:" (nth 1 form))
+ (if (= 3 (length form))
+ ;; Only one sub-form.
+ (rx-form (caddr 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)'."
next prev parent reply other threads:[~2010-06-09 18:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-09 17:22 bug#6384: Teach rx explicitly numbered submatches Lennart Borgman
2010-06-09 18:16 ` Stefan Monnier
2010-06-09 18:19 ` Lennart Borgman [this message]
2010-06-10 15:51 ` Juri Linkov
2010-06-10 16:21 ` Lennart Borgman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTil8YNg_dRodt7YiU5wC1oQJo469i9oDU5Htu7Y3@mail.gmail.com \
--to=lennart.borgman@gmail.com \
--cc=6384@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).