Function: rx--pcase-macroexpander

rx--pcase-macroexpander is an autoloaded function defined in rx.el.gz.

Signature

(rx--pcase-macroexpander &rest REGEXPS)

Documentation

A pattern that matches strings against rx REGEXPS in sexp form.

REGEXPS are interpreted as in rx. The pattern matches any string that is a match for REGEXPS, as if by string-match.

In addition to the usual rx syntax, REGEXPS can contain the following constructs:

  (let REF RX...) binds the symbol REF to a submatch that matches
                   the regular expressions RX. REF is bound in
                   CODE to the string of the submatch or nil, but
                   can also be used in backref.
  (backref REF) matches whatever the submatch REF matched.
                   REF can be a number, as usual, or a name
                   introduced by a previous (let REF ...)
                   construct.

Probably introduced at or before Emacs version 26.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/rx.el.gz
;; Could not find source code, showing raw function object.
#[(&rest regexps)
  ((let*
       ((rx--pcase-vars nil)
	(regexp
	 (rx--to-expr (rx--pcase-transform (cons 'seq regexps)))))
     `(and (pred stringp)
	   ,(pcase (length rx--pcase-vars)
	      (0 `(pred (string-match ,regexp)))
	      (1
	       `(app
		 (lambda (s)
		   (if (string-match ,regexp s) (match-string 1 s) 0))
		 (and ,(car rx--pcase-vars) (pred (not numberp)))))
	      (nvars
	       `(app
		 (lambda (s)
		   (and (string-match ,regexp s)
			,(rx--reduce-right
			  (lambda (a b) `(cons ,a ,b))
			  (mapcar (lambda (i) `(match-string ,i s))
				  (number-sequence 1 nvars)))))
		 ,(list '\`
			(rx--reduce-right #'cons
					  (mapcar
					   (lambda (name)
					     (list '\, name))
					   (reverse rx--pcase-vars))))))))))
  (t) nil
  "A pattern that matches strings against `rx' REGEXPS in sexp form.\nREGEXPS are interpreted as in `rx'.  The pattern matches any\nstring that is a match for REGEXPS, as if by `string-match'.\n\nIn addition to the usual `rx' syntax, REGEXPS can contain the\nfollowing constructs:\n\n  (let REF RX...)  binds the symbol REF to a submatch that matches\n                   the regular expressions RX.  REF is bound in\n                   CODE to the string of the submatch or nil, but\n                   can also be used in `backref'.\n  (backref REF)    matches whatever the submatch REF matched.\n                   REF can be a number, as usual, or a name\n                   introduced by a previous (let REF ...)\n                   construct."]