Function: rx--translate-symbol
rx--translate-symbol is a byte-compiled function defined in rx.el.gz.
Signature
(rx--translate-symbol SYM)
Documentation
Translate an rx symbol. Return (REGEXP . PRECEDENCE).
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/rx.el.gz
;; TODO: Additions to consider:
;; - A construct like `or' but without the match order guarantee,
;; maybe `unordered-or'. Useful for composition or generation of
;; alternatives; permits more effective use of regexp-opt.
(defun rx--translate-symbol (sym)
"Translate an rx symbol. Return (REGEXP . PRECEDENCE)."
(pcase sym
;; Use `list' instead of a quoted list to wrap the strings here,
;; since the return value may be mutated.
((or 'nonl 'not-newline 'any) (cons (list ".") t))
((or 'anychar 'anything) (cons (list "[^z-a]") t))
('unmatchable (rx--empty))
((or 'bol 'line-start) (cons (list "^") 'lseq))
((or 'eol 'line-end) (cons (list "$") 'rseq))
((or 'bos 'string-start 'bot 'buffer-start) (cons (list "\\`") t))
((or 'eos 'string-end 'eot 'buffer-end) (cons (list "\\'") t))
('point (cons (list "\\=") t))
((or 'bow 'word-start) (cons (list "\\<") t))
((or 'eow 'word-end) (cons (list "\\>") t))
('word-boundary (cons (list "\\b") t))
('not-word-boundary (cons (list "\\B") t))
('symbol-start (cons (list "\\_<") t))
('symbol-end (cons (list "\\_>") t))
('not-wordchar (cons (list "\\W") t))
(_
(cond
((let ((class (cdr (assq sym rx--char-classes))))
(and class (cons (list (concat "[[:" (symbol-name class) ":]]")) t))))
((let ((expanded (rx--expand-def sym)))
(and expanded (rx--translate expanded))))
;; For compatibility with old rx.
((let ((entry (assq sym rx-constituents)))
(and (progn
(while (and entry (not (stringp (cdr entry))))
(setq entry
(if (symbolp (cdr entry))
;; Alias for another entry.
(assq (cdr entry) rx-constituents)
;; Wrong type, try further down the list.
(assq (car entry)
(cdr (memq entry rx-constituents))))))
entry)
(cons (list (cdr entry)) nil))))
(t (error "Unknown rx symbol `%s'" sym))))))