Limit number of GnuTLS handshakes per connection.
[bpt/emacs.git] / lisp / emacs-lisp / rx.el
index cb6756a..c246d02 100644 (file)
@@ -1,7 +1,6 @@
 ;;; rx.el --- sexp notation for regular expressions
 
-;; Copyright (C) 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2001-2012 Free Software Foundation, Inc.
 
 ;; Author: Gerd Moellmann <gerd@gnu.org>
 ;; Maintainer: FSF
     (**                        . (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))
@@ -392,7 +393,7 @@ FORM is of the form `(and FORM1 ...)'."
 (defun rx-anything (form)
   "Match any character."
   (if (consp form)
-      (error "rx `anythng' syntax error: %s" form))
+      (error "rx `anything' syntax error: %s" form))
   (rx-or (list 'or 'not-newline ?\n)))
 
 
@@ -412,7 +413,7 @@ Only both edges of each range is checked."
        (setcdr m (1- char)))))
     ranges))
 
-    
+
 (defun rx-any-condense-range (args)
   "Condense by side effect ARGS as range for Rx `any'."
   (let (str
@@ -575,7 +576,7 @@ ARG is optional."
                                 (condition-case nil
                                     (rx-form arg)
                                   (error ""))))
-             (eq arg 'word-boundary) 
+             (eq arg 'word-boundary)
              (and (consp arg)
                   (memq (car arg) '(not any in syntax category))))
     (error "rx `not' syntax error: %s" arg))
@@ -664,7 +665,7 @@ FORM is either `(repeat N FORM1)' or `(repeat N M FORMS...)'."
   (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))))
+      (setq form (cons (nth 0 form) (cons (nth 1 form) (nthcdr 3 form)))))
   (cond ((= (length form) 3)
         (unless (and (integerp (nth 1 form))
                      (> (nth 1 form) 0))
@@ -691,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)'."
@@ -1073,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
@@ -1161,5 +1177,4 @@ enclosed in `(and ...)'.
 \f
 (provide 'rx)
 
-;; arch-tag: 12d01a63-0008-42bb-ab8c-1c7d63be370b
 ;;; rx.el ends here