summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2019-05-15 22:44:00 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2019-05-20 17:56:40 +0200
commitafdc20d73c8588e5a744ecf7bffaf4401a557d20 (patch)
treefa09854d24edb81160a2d709bd450ea7284d83f1 /lisp/emacs-lisp
parentc2cda3ff4025e8c27bdfc2a5279f3b635c8df260 (diff)
downloademacs-afdc20d73c8588e5a744ecf7bffaf4401a557d20.tar.gz
emacs-afdc20d73c8588e5a744ecf7bffaf4401a557d20.tar.bz2
emacs-afdc20d73c8588e5a744ecf7bffaf4401a557d20.zip
Allow zero-argument rx `or' and `seq' forms
Make the rx `or' and `seq' forms accept zero arguments to produce a never-matching regexp and an empty string, respectively. * lisp/emacs-lisp/rx.el: Require cl-extra. (rx-constituents, rx-or): Permit zero args. (rx): Amend doc string for `or' and `seq'. * test/lisp/emacs-lisp/rx-tests.el (rx-or, rx-seq): Test the change. * etc/NEWS (Changes in Specialized Modes and Packages): Mention the change.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/rx.el14
1 files changed, 9 insertions, 5 deletions
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el
index 9d9028d87d5..ed32490ceee 100644
--- a/lisp/emacs-lisp/rx.el
+++ b/lisp/emacs-lisp/rx.el
@@ -106,15 +106,16 @@
;;; Code:
(require 'cl-lib)
+(require 'cl-extra)
;; FIXME: support macros.
(defvar rx-constituents ;Not `const' because some modes extend it.
- '((and . (rx-and 1 nil))
+ '((and . (rx-and 0 nil))
(seq . and) ; SRE
(: . and) ; SRE
(sequence . and) ; sregex
- (or . (rx-or 1 nil))
+ (or . (rx-or 0 nil))
(| . or) ; SRE
(not-newline . ".")
(nonl . not-newline) ; SRE
@@ -390,9 +391,11 @@ FORM is of the form `(and FORM1 ...)'."
"Parse and produce code from FORM, which is `(or FORM1 ...)'."
(rx-check form)
(rx-group-if
- (if (memq nil (mapcar 'stringp (cdr form)))
- (mapconcat (lambda (x) (rx-form x '|)) (cdr form) "\\|")
+ (cond
+ ((null (cdr form)) regexp-unmatchable)
+ ((cl-every #'stringp (cdr form))
(regexp-opt (cdr form) nil t))
+ (t (mapconcat (lambda (x) (rx-form x '|)) (cdr form) "\\|")))
(and (memq rx-parent '(: * t)) rx-parent)))
@@ -1121,6 +1124,7 @@ CHAR
`(seq SEXP1 SEXP2 ...)'
`(sequence SEXP1 SEXP2 ...)'
matches what SEXP1 matches, followed by what SEXP2 matches, etc.
+ Without arguments, matches the empty string.
`(submatch SEXP1 SEXP2 ...)'
`(group SEXP1 SEXP2 ...)'
@@ -1136,7 +1140,7 @@ CHAR
`(| SEXP1 SEXP2 ...)'
matches anything that matches SEXP1 or SEXP2, etc. If all
args are strings, use `regexp-opt' to optimize the resulting
- regular expression.
+ regular expression. Without arguments, never matches anything.
`(minimal-match SEXP)'
produce a non-greedy regexp for SEXP. Normally, regexps matching