all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: 34100@debbugs.gnu.org
Subject: bug#34100: 26.1; Incomplete ? and ?? handling in rx
Date: Wed, 16 Jan 2019 12:39:58 +0100	[thread overview]
Message-ID: <58F99E68-AC42-40E9-8ADF-CCC416266C25@acm.org> (raw)

In rx, the ? and ?? operators can be written verbatim as ? and ?? (space and ? character), or by using symbols whose leading character needs to be escaped, \? and \?? respectively. The names come from Olin Shivers's SRE, but ? is not a special character in Scheme syntax, hence the character syntax hack.

However, the symbols only partially work:

(rx (\? "x") (\?? "y"))       --> "x?y?"  ; expected "x?y??"
(rx (minimal-match (\? "x"))) --> "x??"   ; expected "x?"

While it could be argued that only the character-based syntax should be used, the fact is that the symbols are accepted and seem to work, just in a subtly broken way.

The documentation is also not clear on this point, and a programmer knowing the elisp syntax might very well assume that the symbols are the ones to use.

Suggested fix:

diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el
index a39fe55c32..8b4551d0d3 100644
--- a/lisp/emacs-lisp/rx.el
+++ b/lisp/emacs-lisp/rx.el
@@ -733,8 +733,8 @@
 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)) "*")







             reply	other threads:[~2019-01-16 11:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 11:39 Mattias Engdegård [this message]
2019-01-16 14:06 ` bug#34100: rx \? and \??: patch Mattias Engdegård
     [not found] ` <handler.34100.B.154763885119611.ack@debbugs.gnu.org>
2019-01-25 10:09   ` bug#34100: Acknowledgement (26.1; Incomplete ? and ?? handling in rx) Mattias Engdegård
2019-01-28 15:53     ` Michael Heerdegen
2019-02-01  9:44       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58F99E68-AC42-40E9-8ADF-CCC416266C25@acm.org \
    --to=mattiase@acm.org \
    --cc=34100@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.