* lisp/emacs-lisp/rx.el (rx-regexp, rx-literal): Check the cadr of the
form for stringness, not the form itself.
* test/lisp/emacs-lisp/rx-tests.el (rx-to-string-lisp-forms): New test.
(defun rx-regexp (form)
"Parse and produce code from FORM, which is `(regexp STRING)'."
- (cond ((stringp form)
+ (cond ((stringp (cadr form))
(rx-group-if (cadr form) rx-parent))
(rx--compile-to-lisp
;; Always group non-string forms, since we can't be sure they
(defun rx-literal (form)
"Parse and produce code from FORM, which is `(literal STRING-EXP)'."
- (cond ((stringp form)
+ (cond ((stringp (cadr form))
;; This is allowed, but makes little sense, you could just
;; use STRING directly.
(rx-group-if (regexp-quote (cadr form)) rx-parent))
(rx-tests--match (rx "c" (minimal-match (0+ (regexp ad))) "a") "cdaaada" "cda")
(rx-tests--match (rx "c" (maximal-match (0+ (regexp ad))) "a") "cdaaada" "cdaaada")))
+(ert-deftest rx-to-string-lisp-forms ()
+ (rx-tests--match (rx-to-string '(seq "a" (literal "b") "c")) "abc")
+ (rx-tests--match (rx-to-string '(seq "a" (regexp "b") "c")) "abc"))
+
(provide 'rx-tests)
;; rx-tests.el ends here.