Function: rx--to-expr

rx--to-expr is a byte-compiled function defined in rx.el.gz.

Signature

(rx--to-expr FORM)

Documentation

Translate the rx-expression FORM to a Lisp expression yielding a regexp.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/rx.el.gz
(defun rx--to-expr (form)
  "Translate the rx-expression FORM to a Lisp expression yielding a regexp."
  (let* ((rx--local-definitions
          ;; Retrieve local definitions from the macroexpansion environment.
          ;; (It's unclear whether the previous value of `rx--local-definitions'
          ;; should be included, and if so, in which order.)
          (cdr (assq :rx-locals macroexpand-all-environment)))
         (rx--delayed-evaluation t)
         (elems (car (rx--translate form)))
         (args nil))
    ;; Merge adjacent strings.
    (while elems
      (let ((strings nil))
        (while (and elems (stringp (car elems)))
          (push (car elems) strings)
          (setq elems (cdr elems)))
        (let ((s (apply #'concat (nreverse strings))))
          (unless (zerop (length s))
            (push s args))))
      (when elems
        (push (car elems) args)
        (setq elems (cdr elems))))
    (cond ((null args) "")                             ; 0 args
          ((cdr args) (cons 'concat (nreverse args)))  ; ≥2 args
          (t (car args)))))                            ; 1 arg