[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scan of regexps in Emacs (March 17)

From: Stefan Monnier
Subject: Re: Scan of regexps in Emacs (March 17)
Date: Tue, 19 Mar 2019 22:20:53 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> I also fixed a couple of other problems if I happened to run across
> them. First, the regexp [a-b-c] is ambiguous according to POSIX,

Maybe according to POSIX, but not according to Emacs Lisp's reference

    To include a ‘]’ in a character alternative, you must make it the
    first character.  For example, ‘[]a]’ matches ‘]’ or ‘a’.  To
    include a ‘-’, write ‘-’ as the first or last character of the
    character alternative, or put it after a range.  Thus, ‘[]-]’
    matches both ‘]’ and ‘-’.  (As explained below, you cannot use ‘\]’
    to include a ‘]’ inside a character alternative, since ‘\’ is not
    special there.)

> and should be avoided.

Maybe I could go along with that.
[ I wish Elisp regexps just used \ as an escape char in ranges instead
  of relying on those special convention of where `-` and `]` can appear
  in order to count as themselves.  ]

> Second, a regexp like [[:alnum:]-z] is also ambiguous for the
> same reason.

I think the doc above was written for we had those char classes, but if
[a-b-c] is not ambiguous then I think it's only natural to declare that
[[:alnum:]-z] is not ambiguous either.

> Perhaps these regexps currently have a particular behavior in
> Emacs but it's not documented as far as I know and code should avoid
> them.  Perhaps the trawler could be modified to catch them.

I wonder why the doc doesn't just say that `-` should be the last
character and not mention the other possibilities which just make the
rule unnecessarily complex.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]