From 6420d28b9ab9c09b69992e05e0e63c3bbaf2646d Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Sat, 18 Jun 2011 17:12:33 -0400 Subject: 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. --- lisp/emacs-lisp/rx.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index 7122de4789c..56efd142198 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el @@ -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 @@ FORM is either `(repeat N FORM1)' or `(repeat N M FORMS...)'." (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 @@ CHAR 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 -- cgit v1.2.3 From bfbbb27d9246153517e7f94caa9dc57abffcdb87 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Sun, 19 Jun 2011 20:36:16 -0700 Subject: * emacs-lisp/syntax.el (syntax-ppss): Further improve docstring. --- lisp/ChangeLog | 4 ++++ lisp/emacs-lisp/syntax.el | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cafd440f650..ef76dc69fdc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2011-06-20 Daniel Colascione + + * emacs-lisp/syntax.el (syntax-ppss): Further improve docstring. + 2011-06-19 Chong Yidong * files.el (auto-mode-alist): Entry for m2-mode (Bug#8852). diff --git a/lisp/emacs-lisp/syntax.el b/lisp/emacs-lisp/syntax.el index 7ba7b13af44..200b3a6389b 100644 --- a/lisp/emacs-lisp/syntax.el +++ b/lisp/emacs-lisp/syntax.el @@ -398,8 +398,9 @@ point (where the PPSS is equivalent to nil).") (defun syntax-ppss (&optional pos) "Parse-Partial-Sexp State at POS, defaulting to point. -The returned value is the same as `parse-partial-sexp' except that -values 2 and 6 values of the returned state cannot be relied upon. +The returned value is the same as that of `parse-partial-sexp' +run from point-min to POS except that values at positions 2 and 6 +in the returned list (counting from 0) cannot be relied upon. Point is at POS when this function returns." ;; Default values. (unless pos (setq pos (point))) -- cgit v1.2.3