Function: rx--translate-not

rx--translate-not is a byte-compiled function defined in rx.el.gz.

Signature

(rx--translate-not NEGATED BODY)

Documentation

Translate a (not ...) construct. Return (REGEXP . PRECEDENCE).

If NEGATED, negate the sense (thus making it positive).

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/rx.el.gz
;; TODO: Consider turning `not' into a variadic operator, following SRE:
;; (not A B) = (not (or A B)) = (intersection (not A) (not B)), and
;; (not) = anychar.
;; Maybe allow singleton characters as arguments.

(defun rx--translate-not (negated body)
  "Translate a (not ...) construct.  Return (REGEXP . PRECEDENCE).
If NEGATED, negate the sense (thus making it positive)."
  (unless (and body (null (cdr body)))
    (error "rx `not' form takes exactly one argument"))
  (let ((arg (rx--normalize-char-pattern (car body))))
    (pcase arg
      (`(not . ,args)
       (rx--translate-not      (not negated) args))
      (`(syntax . ,args)
       (rx--translate-syntax   (not negated) args))
      (`(category . ,args)
       (rx--translate-category (not negated) args))
      ('word-boundary                     ; legacy syntax
       (rx--translate-symbol (if negated 'word-boundary 'not-word-boundary)))
      (_ (let ((char (rx--reduce-to-char-alt arg)))
           (if char
               (rx--generate-alt (not negated) (car char) (cdr char))
             (error "Illegal argument to rx `not': %S"
                    (rx--human-readable arg))))))))