unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefankangas@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: Ugly regexps
Date: Tue, 2 Mar 2021 19:32:23 -0600	[thread overview]
Message-ID: <CADwFkm=8qfh1RQkK6qbvEt=-Ch_vXKCe5NvJ_L_OVXsnf=DpZg@mail.gmail.com> (raw)
In-Reply-To: <jwvk0qpjd31.fsf-monnier+emacs@gnu.org>

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> BTW, while this theme of ugly regexps keeps coming up, how 'bout we add
> a new function `ere` which converts between the ERE style of regexps
> where grouping parens are not escaped (and plain chars meant to match
> an actual paren need to be escaped instead) to ELisp-style regexps?
>
> So you can do
>
>     (string-match (ere "\\(def(macro|un|subst) .{1,}"))
>
> instead of
>
>     (string-match "(def\\(macro\\|un\\|subst\\) .\\{1,\\}")
>
> ?

Sounds good to me.

I was going to ask why not just do PCRE, but then I realized I'm not
exactly sure what the syntactical differences are.  (We obviously lack
some features.)  AFAIR, Emacs regexps don't exactly match GNU grep,
egrep, Perl, or anything else really.

So I cranked out my dusty old copy of Mastering Regular Expressions and
found this overview:

    grep           egrep          Emacs          Perl
    \? \+ \|      ? + |          ? + \|         ? + |
    \( \)          ( )            \( \)          ( )
                  \< \>         \< \> \b \B   \b \B

    (Excerpt from Mastering Regular Expressions: Table 3-3: A (Very)
    Superficial Look at the Flavor of a Few Common Tools)

This shows the differences that most commonly bites you, in my
experience.

While we're at it, has it ever been discussed to add support for the
pcre library side-by-side with our homegrown regexp.c?  It would give us
sane (standard) syntax and some useful features "for free"
(e.g. lookaround).  I didn't test but a priori I would also assume the
code to be much more performant than anything we could ever cook up
ourselves.  It is used by several high-profile projects.

I would imagine we'd introduce entirely new function names for it.
Perhaps even a completely new and improved API like Lars suggested a
while back.



  reply	other threads:[~2021-03-03  1:32 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03  0:32 Ugly regexps Stefan Monnier
2021-03-03  1:32 ` Stefan Kangas [this message]
2021-03-03  2:08   ` Stefan Kangas
2021-03-03  6:19     ` Eli Zaretskii
2021-03-03 20:46   ` Alan Mackenzie
2021-03-04 18:35     ` Stefan Kangas
2021-03-03  6:00 ` Eli Zaretskii
2021-03-03 15:46   ` Stefan Monnier
2021-03-03 16:30     ` Eli Zaretskii
2021-03-03 17:44       ` Stefan Monnier
2021-03-03 18:46         ` Stefan Kangas
2021-03-03 19:21           ` Eli Zaretskii
2021-03-03 19:50             ` Stefan Kangas
2021-03-03 20:16               ` Stefan Kangas
2021-03-03 19:50             ` Stefan Kangas
2021-03-03 19:58             ` Dmitry Gutov
2021-03-03 20:07               ` [External] : " Drew Adams
2021-03-03 20:31                 ` Stefan Kangas
2021-03-03 22:17                   ` Drew Adams
2021-03-03 22:32                     ` Stefan Monnier
2021-03-03 20:32                 ` Stefan Monnier
2021-03-04  5:47               ` Eli Zaretskii
2021-03-04 10:49                 ` Lars Ingebrigtsen
2021-03-04 11:25                   ` Mattias Engdegård
2021-03-04 11:28                   ` Alan Mackenzie
2021-03-04 14:11                   ` Eli Zaretskii
2021-03-04 14:25                 ` Dmitry Gutov
2021-03-04 14:50                   ` tomas
2021-03-04 15:04                     ` Dmitry Gutov
2021-03-05  5:45                       ` Richard Stallman
2021-03-05 11:47                         ` Dmitry Gutov
2021-03-06  5:11                           ` Richard Stallman
2021-03-04 15:05                     ` Dmitry Gutov
2021-03-04 15:11                   ` Eli Zaretskii
2021-03-03 19:32           ` [External] : " Drew Adams
2021-03-03  7:09 ` Helmut Eller
2021-03-03 14:11   ` Stefan Kangas
2021-03-03 16:40     ` Stefan Monnier
2021-03-03 15:49   ` Stefan Monnier
2021-03-03 12:17 ` Dmitry Gutov
2021-03-03 15:48   ` Stefan Monnier
2021-03-03 13:57 ` Lars Ingebrigtsen

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='CADwFkm=8qfh1RQkK6qbvEt=-Ch_vXKCe5NvJ_L_OVXsnf=DpZg@mail.gmail.com' \
    --to=stefankangas@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).