From: Mattias EngdegÄrd Date: Wed, 16 Jan 2019 13:57:12 +0000 (+0100) Subject: Make the rx operators \? and \?? behave correctly X-Git-Tag: emacs-27.0.90~3699 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=decdff76fb185f87145940cc3b91549f84600a87;p=emacs.git 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. --- diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index a39fe55c322..8b4551d0d36 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 392a38ab95b..f15e1016f7c 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.