aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMattias EngdegÄrd2019-05-15 22:44:00 +0200
committerMattias EngdegÄrd2019-05-20 17:56:40 +0200
commitafdc20d73c8588e5a744ecf7bffaf4401a557d20 (patch)
treefa09854d24edb81160a2d709bd450ea7284d83f1 /lisp
parentc2cda3ff4025e8c27bdfc2a5279f3b635c8df260 (diff)
downloademacs-afdc20d73c8588e5a744ecf7bffaf4401a557d20.tar.gz
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')
-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 @@
106;;; Code: 106;;; Code:
107 107
108(require 'cl-lib) 108(require 'cl-lib)
109(require 'cl-extra)
109 110
110;; FIXME: support macros. 111;; FIXME: support macros.
111 112
112(defvar rx-constituents ;Not `const' because some modes extend it. 113(defvar rx-constituents ;Not `const' because some modes extend it.
113 '((and . (rx-and 1 nil)) 114 '((and . (rx-and 0 nil))
114 (seq . and) ; SRE 115 (seq . and) ; SRE
115 (: . and) ; SRE 116 (: . and) ; SRE
116 (sequence . and) ; sregex 117 (sequence . and) ; sregex
117 (or . (rx-or 1 nil)) 118 (or . (rx-or 0 nil))
118 (| . or) ; SRE 119 (| . or) ; SRE
119 (not-newline . ".") 120 (not-newline . ".")
120 (nonl . not-newline) ; SRE 121 (nonl . not-newline) ; SRE
@@ -390,9 +391,11 @@ FORM is of the form `(and FORM1 ...)'."
390 "Parse and produce code from FORM, which is `(or FORM1 ...)'." 391 "Parse and produce code from FORM, which is `(or FORM1 ...)'."
391 (rx-check form) 392 (rx-check form)
392 (rx-group-if 393 (rx-group-if
393 (if (memq nil (mapcar 'stringp (cdr form))) 394 (cond
394 (mapconcat (lambda (x) (rx-form x '|)) (cdr form) "\\|") 395 ((null (cdr form)) regexp-unmatchable)
396 ((cl-every #'stringp (cdr form))
395 (regexp-opt (cdr form) nil t)) 397 (regexp-opt (cdr form) nil t))
398 (t (mapconcat (lambda (x) (rx-form x '|)) (cdr form) "\\|")))
396 (and (memq rx-parent '(: * t)) rx-parent))) 399 (and (memq rx-parent '(: * t)) rx-parent)))
397 400
398 401
@@ -1121,6 +1124,7 @@ CHAR
1121`(seq SEXP1 SEXP2 ...)' 1124`(seq SEXP1 SEXP2 ...)'
1122`(sequence SEXP1 SEXP2 ...)' 1125`(sequence SEXP1 SEXP2 ...)'
1123 matches what SEXP1 matches, followed by what SEXP2 matches, etc. 1126 matches what SEXP1 matches, followed by what SEXP2 matches, etc.
1127 Without arguments, matches the empty string.
1124 1128
1125`(submatch SEXP1 SEXP2 ...)' 1129`(submatch SEXP1 SEXP2 ...)'
1126`(group SEXP1 SEXP2 ...)' 1130`(group SEXP1 SEXP2 ...)'
@@ -1136,7 +1140,7 @@ CHAR
1136`(| SEXP1 SEXP2 ...)' 1140`(| SEXP1 SEXP2 ...)'
1137 matches anything that matches SEXP1 or SEXP2, etc. If all 1141 matches anything that matches SEXP1 or SEXP2, etc. If all
1138 args are strings, use `regexp-opt' to optimize the resulting 1142 args are strings, use `regexp-opt' to optimize the resulting
1139 regular expression. 1143 regular expression. Without arguments, never matches anything.
1140 1144
1141`(minimal-match SEXP)' 1145`(minimal-match SEXP)'
1142 produce a non-greedy regexp for SEXP. Normally, regexps matching 1146 produce a non-greedy regexp for SEXP. Normally, regexps matching