[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master decdff7: Make the rx operators \? and \?? behave co
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] master decdff7: Make the rx operators \? and \?? behave correctly |
Date: |
Fri, 1 Feb 2019 04:43:11 -0500 (EST) |
branch: master
commit decdff76fb185f87145940cc3b91549f84600a87
Author: Mattias EngdegÄrd <address@hidden>
Commit: Eli Zaretskii <address@hidden>
Make the rx operators \? and \?? behave correctly
* lisp/emacs-lisp/rx.el (rx-kleene):
Treat \? and \?? like ? and ?? (Bug#34100).
* test/lisp/emacs-lisp/rx-tests.el: Add tests for all repetition operators.
---
lisp/emacs-lisp/rx.el | 4 ++--
test/lisp/emacs-lisp/rx-tests.el | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el
index a39fe55..8b4551d 100644
--- a/lisp/emacs-lisp/rx.el
+++ b/lisp/emacs-lisp/rx.el
@@ -733,8 +733,8 @@ If OP is anything else, produce a greedy regexp if
`rx-greedy-flag'
is non-nil."
(rx-check form)
(setq form (rx-trans-forms form))
- (let ((suffix (cond ((memq (car form) '(* + ?\s)) "")
- ((memq (car form) '(*? +? ??)) "?")
+ (let ((suffix (cond ((memq (car form) '(* + \? ?\s)) "")
+ ((memq (car form) '(*? +? \?? ??)) "?")
(rx-greedy-flag "")
(t "?")))
(op (cond ((memq (car form) '(* *? 0+ zero-or-more)) "*")
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el
index 392a38a..f15e101 100644
--- a/test/lisp/emacs-lisp/rx-tests.el
+++ b/test/lisp/emacs-lisp/rx-tests.el
@@ -65,5 +65,28 @@
(list u v)))
'("1" "3"))))
+(ert-deftest rx-kleene ()
+ "Test greedy and non-greedy repetition operators."
+ (should (equal (rx (* "a") (+ "b") (\? "c") (?\s "d")
+ (*? "e") (+? "f") (\?? "g") (?? "h"))
+ "a*b+c?d?e*?f+?g??h??"))
+ (should (equal (rx (zero-or-more "a") (0+ "b")
+ (one-or-more "c") (1+ "d")
+ (zero-or-one "e") (optional "f") (opt "g"))
+ "a*b*c+d+e?f?g?"))
+ (should (equal (rx (minimal-match
+ (seq (* "a") (+ "b") (\? "c") (?\s "d")
+ (*? "e") (+? "f") (\?? "g") (?? "h"))))
+ "a*b+c?d?e*?f+?g??h??"))
+ (should (equal (rx (minimal-match
+ (seq (zero-or-more "a") (0+ "b")
+ (one-or-more "c") (1+ "d")
+ (zero-or-one "e") (optional "f") (opt "g"))))
+ "a*?b*?c+?d+?e??f??g??"))
+ (should (equal (rx (maximal-match
+ (seq (* "a") (+ "b") (\? "c") (?\s "d")
+ (*? "e") (+? "f") (\?? "g") (?? "h"))))
+ "a*b+c?d?e*?f+?g??h??")))
+
(provide 'rx-tests)
;; rx-tests.el ends here.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master decdff7: Make the rx operators \? and \?? behave correctly,
Eli Zaretskii <=