unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Luc Teirlinck <teirllm@dms.auburn.edu>
Cc: rudalics@gmx.at, emacs-devel@gnu.org, schwab@suse.de
Subject: Re: Unquoted special characters in regexps
Date: Mon, 27 Feb 2006 18:30:13 -0600 (CST)	[thread overview]
Message-ID: <200602280030.k1S0UDE07149@raven.dms.auburn.edu> (raw)
In-Reply-To: <E1FDneo-00050N-Nn@fencepost.gnu.org> (message from Richard Stallman on Mon, 27 Feb 2006 14:03:42 -0500)

None of the messages I sent on this (or on anything else) in the last
few days made it to emacs-devel, although all other people's
responses did, be it after some delay.  I just got messages saying
that local delivery failed.  So I will have to repeat some things that
I already said before.

Richard Stallman wrote:

   However, that doesn't necessarily mean the manual is wrong.
   There is more than one way to understand the word "special".
   At the most literal level, ] is not special; if you write it
   without \\, the regexp compiler won't misunderstand it.

`]', like `-' are only special in the context of a character
alternative, that is if, before you type them, you are in a character
alternative.   By contrast, `['  and all other special characters
(except `^') are  only special outside that context.

All characters that are special outside character alternatives are
never special if you precede them with a backslash.  This is true even
for `^'.  This is why it is good to precede them with a backslash even
if they are not special.  That way, the reader can see that they are
not special, without studying the regexp.

On the other hand, a backslash, _never_ eliminates the special meaning
of a `]' or `-' with a special meaning. 

There are two questions here.  Whether a `]' outside a character
alternative should be quoted or not and whether any changes to the
Elisp manual are required.  In this posting, I will only discuss the
first.

First of all, there are (surprisingly) many occurrences of "\\]" in
the Emacs source, where the `]' _is_ special and closes a character
alternative that contains a slash.  Reportedly quoting a `]' with a
backslash _inside_ a character alternative works in some other regexp
implementations such as AWK.  So if I see "\\]" I have to worry about
three possibilities:  it might deliberately close a character
alternative which includes a slash, it might do so by accident because
the author tried to quote a `]' inside a character alternative (and
hence the regexp is buggy), or it might be a deliberately quoted `]'
outside a character alternative.

If I see `]' without preceding "\\", I only have to worry about
whether or not it closes a character alternative, and not about the
third possibility of a bug.

In summary I believe that quoting a `]' outside a character
alternative only adds clutter and a third possibility to worry about.

There are places in the Emacs code that quote a `]' outside a
character alternative.  Even if we decide that this is undesirable, I
do not fancy finding and changing them all.  But we could change the
behavior of `regexp-quote' and `regexp-opt' which currently quote
such `]'.  That could be done with the following trivial patch, which
I could install if that is what we decide to do:

===File ~/search.c-diff=====================================
*** search.c	06 Feb 2006 16:02:24 -0600	1.206
--- search.c	27 Feb 2006 00:16:42 -0600	
***************
*** 3066,3072 ****
  
    for (; in != end; in++)
      {
!       if (*in == '[' || *in == ']'
  	  || *in == '*' || *in == '.' || *in == '\\'
  	  || *in == '?' || *in == '+'
  	  || *in == '^' || *in == '$')
--- 3066,3072 ----
  
    for (; in != end; in++)
      {
!       if (*in == '['
  	  || *in == '*' || *in == '.' || *in == '\\'
  	  || *in == '?' || *in == '+'
  	  || *in == '^' || *in == '$')
============================================================

  parent reply	other threads:[~2006-02-28  0:30 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-25 17:23 Unquoted special characters in regexps martin rudalics
2006-02-25 18:42 ` Andreas Schwab
2006-02-25 19:18   ` martin rudalics
2006-02-25 19:31     ` Andreas Schwab
2006-02-25 20:18       ` martin rudalics
2006-02-25 22:09         ` Andreas Schwab
2006-02-26 11:32           ` martin rudalics
2006-02-26 11:50             ` Andreas Schwab
2006-02-26 13:28               ` martin rudalics
2006-02-25 22:13         ` Luc Teirlinck
2006-02-26 13:13           ` martin rudalics
2006-02-26 13:50             ` Andreas Schwab
2006-02-26 16:41               ` Luc Teirlinck
2006-02-26 17:53                 ` martin rudalics
2006-02-26 18:22                   ` Luc Teirlinck
2006-02-26 19:26                     ` martin rudalics
2006-02-26 17:10               ` martin rudalics
2006-02-26 17:42                 ` Luc Teirlinck
2006-02-26 19:06                   ` martin rudalics
2006-02-26 17:56                 ` Andreas Schwab
2006-02-26 19:08                   ` martin rudalics
2006-02-27 19:03                     ` Richard Stallman
2006-02-27 19:36                       ` Andreas Schwab
2006-02-27 20:03                         ` martin rudalics
2006-02-27 20:32                           ` Andreas Schwab
2006-02-27 21:43                             ` martin rudalics
2006-02-27 22:11                               ` Andreas Schwab
2006-02-28  6:19                                 ` Richard Stallman
2006-02-28 10:28                                 ` martin rudalics
2006-02-28  0:30                       ` Luc Teirlinck [this message]
2006-02-28 10:27                         ` martin rudalics
2006-02-28 22:57                           ` Luc Teirlinck
2006-03-01 13:00                             ` martin rudalics
2006-03-01 17:54                         ` Richard Stallman
2006-03-02  4:06                           ` Luc Teirlinck
2006-03-02 19:43                             ` Richard Stallman
2006-03-02  4:54                           ` Luc Teirlinck
2006-03-02 18:40                           ` martin rudalics
2006-03-02 23:26                             ` Luc Teirlinck
2006-03-03  7:42                               ` martin rudalics
2006-03-03 13:51                                 ` Luc Teirlinck
2006-03-03 14:09                                 ` Luc Teirlinck
2006-03-03 18:52                                   ` martin rudalics
2006-03-03 22:41                                     ` Luc Teirlinck
2006-03-03 23:00                                     ` Luc Teirlinck
2006-03-03 10:25                             ` Richard Stallman
2006-03-03 15:20                               ` martin rudalics
2006-03-04 13:37                                 ` Richard Stallman
2006-03-04 14:40                                   ` martin rudalics
2006-03-06  0:48                                     ` Richard Stallman
2006-03-03 10:25                             ` Richard Stallman
2006-03-03 15:51                               ` martin rudalics
2006-03-03 23:48                                 ` Luc Teirlinck
2006-03-04  9:58                                   ` martin rudalics
2006-03-04 23:16                                 ` Luc Teirlinck
2006-03-05  2:54                               ` Luc Teirlinck
2006-03-06  0:49                                 ` Richard Stallman
2006-02-28  0:44                       ` Luc Teirlinck
2006-03-04 21:07                         ` Thien-Thi Nguyen
2006-03-05  3:37                           ` Luc Teirlinck
2006-03-05 11:10                             ` martin rudalics
2006-03-05 15:32                               ` Luc Teirlinck
2006-03-06  7:41                                 ` martin rudalics
2006-03-05 17:04                               ` Luc Teirlinck
2006-03-05 11:54                             ` martin rudalics
2006-03-05 15:35                               ` Andreas Schwab
2006-03-06  8:19                                 ` martin rudalics
2006-03-05 18:36                               ` Luc Teirlinck
2006-03-05 19:14                                 ` Luc Teirlinck
2006-03-06  8:17                                   ` martin rudalics
2006-02-28  0:59                       ` Luc Teirlinck
2006-03-06 12:52                         ` Richard Stallman
2006-03-07  5:52                           ` Luc Teirlinck
2006-03-07  8:53                             ` martin rudalics
2006-02-25 22:34         ` Luc Teirlinck
2006-02-25 22:59           ` Andreas Schwab
2006-02-26 13:20           ` martin rudalics
2006-02-26 16:53             ` Luc Teirlinck
2006-02-26 18:01               ` martin rudalics
2006-02-26 17:19             ` Luc Teirlinck
2006-02-26 18:13               ` martin rudalics

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=200602280030.k1S0UDE07149@raven.dms.auburn.edu \
    --to=teirllm@dms.auburn.edu \
    --cc=emacs-devel@gnu.org \
    --cc=rudalics@gmx.at \
    --cc=schwab@suse.de \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).