Function: rx--substitute
rx--substitute is a byte-compiled function defined in rx.el.gz.
Signature
(rx--substitute BINDINGS FORM)
Documentation
Substitute BINDINGS in FORM. BINDINGS is an alist of (NAME . VALUES) where VALUES is a list to splice into FORM wherever NAME occurs. Return the substitution result wrapped in a list, since a single value can expand to any number of values.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/rx.el.gz
(defun rx--substitute (bindings form)
"Substitute BINDINGS in FORM. BINDINGS is an alist of (NAME . VALUES)
where VALUES is a list to splice into FORM wherever NAME occurs.
Return the substitution result wrapped in a list, since a single value
can expand to any number of values."
(cond ((symbolp form)
(let ((binding (assq form bindings)))
(if binding
(cdr binding)
(list form))))
((consp form)
(if (listp (cdr form))
;; Proper list. We substitute variables even in the head
;; position -- who knows, might be handy one day.
(list (mapcan (lambda (x) (copy-sequence
(rx--substitute bindings x)))
form))
;; Cons pair (presumably an interval).
(let ((first (rx--substitute bindings (car form)))
(second (rx--substitute bindings (cdr form))))
(if (and first (not (cdr first))
second (not (cdr second)))
(list (cons (car first) (car second)))
(error
"Cannot substitute a &rest parameter into a dotted pair")))))
(t (list form))))