Function: rst-re

rst-re is a byte-compiled function defined in rst.el.gz.

Signature

(rst-re &rest ARGS)

Documentation

Interpret ARGS as regular expressions and return a regex string.

Each element of ARGS may be one of the following:

A string which is inserted unchanged.

A character which is resolved to a quoted regex.

A symbol which is resolved to a string using rst-re-alist-def.

A list with a keyword in the car. Each element of the cdr of such a list is recursively interpreted as ARGS. The results of this interpretation are concatenated according to the keyword.

For the keyword :seq the results are simply concatenated.

For the keyword :shy the results are concatenated and surrounded by a shy-group ("\\(?:...\\)").

For the keyword :alt the results form an alternative ("\\|") which is shy-grouped ("\\(?:...\\)").

For the keyword :grp the results are concatenated and form a referenceable group ("\\(...\\)").

After interpretation of ARGS the results are concatenated as for
:seq.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/rst.el.gz
(defun rst-re (&rest args)
  ;; testcover: ok.
  "Interpret ARGS as regular expressions and return a regex string.
Each element of ARGS may be one of the following:

A string which is inserted unchanged.

A character which is resolved to a quoted regex.

A symbol which is resolved to a string using `rst-re-alist-def'.

A list with a keyword in the car.  Each element of the cdr of such
a list is recursively interpreted as ARGS.  The results of this
interpretation are concatenated according to the keyword.

For the keyword `:seq' the results are simply concatenated.

For the keyword `:shy' the results are concatenated and
surrounded by a shy-group (\"\\(?:...\\)\").

For the keyword `:alt' the results form an alternative (\"\\|\")
which is shy-grouped (\"\\(?:...\\)\").

For the keyword `:grp' the results are concatenated and form a
referenceable group (\"\\(...\\)\").

After interpretation of ARGS the results are concatenated as for
`:seq'."
  (apply #'concat
	 (mapcar
          (lambda (re)
            (cond
             ((stringp re)
              re)
             ((symbolp re)
              (cadr (assoc re rst-re-alist)))
             ((characterp re)
              (regexp-quote (char-to-string re)))
             ((listp re)
              (let ((nested
                     (mapcar #'rst-re (cdr re))))
                (cond
                 ((eq (car re) :seq)
                  (mapconcat #'identity nested ""))
                 ((eq (car re) :shy)
                  (concat "\\(?:" (mapconcat #'identity nested "") "\\)"))
                 ((eq (car re) :grp)
                  (concat "\\(" (mapconcat #'identity nested "") "\\)"))
                 ((eq (car re) :alt)
                  (concat "\\(?:" (mapconcat #'identity nested "\\|") "\\)"))
                 (t
                  (error "Unknown list car: %s" (car re))))))
             (t
              (error "Unknown object type for building regex: %s" re))))
	  args)))