unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: How are regexen implemented in Emacs?
Date: Tue, 13 Dec 2022 06:01:22 +0100	[thread overview]
Message-ID: <Y5gHIkN9IMulVPr5@tuxteam.de> (raw)
In-Reply-To: <jwviligfhqt.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1576 bytes --]

On Mon, Dec 12, 2022 at 04:19:19PM -0500, Stefan Monnier wrote:
> > The linked article sounded a bit like "only idiots implement regexen
> > in the naive way", and I was pretty sure Emacs devs are not idiots - but
> > now I understand the reasons better.

There comes my favourite motto: "all generalizations suck" (Michael
Heerdegen enjoyed it a couple of threads back).

Whoever uses a library these days uses PCRE, and this is, AFAIK, a
DFA-with-backtracking thingy. Note that I haven't read the code,
so I might well be wrong.

> I fully agree that it doesn't make sense to *start* with
> a backtracking implementation, yes.
> But once you've invested in one, it's harder to move to
> something better.
> 
> This said, it *would* be better.  Not only in terms of eliminating the
> pathological blow ups, but it also offers opportunity to get new
> functionality, such as the ability to capture the state of a regexp
> match at a specific buffer position (so you can perform a multiline
> regexp match one line at a time).  It could also make it much more
> reasonable to add the possibility to run ELisp code from within the
> regexp match engine (e.g. add a \p(NAME) entry which calls the NAME
> ELisp function).

Perl does the latter. That has saved my bacon from time to time.
So that seems possible with a backtracker, too. Don't ask me how,
though :-)

Saving state at any point would be cool -- you could easily invert
control (feeding the regexp machine a spoonful at a time). Think
network or an abstract buffer.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2022-12-13  5:01 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-12 17:15 How are regexen implemented in Emacs? Marcin Borkowski
2022-12-12 18:16 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-12-12 19:09   ` Marcin Borkowski
2022-12-12 19:17     ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-12-12 20:31       ` Marcin Borkowski
2022-12-12 21:19         ` Stefan Monnier
2022-12-13  5:01           ` tomas [this message]
2022-12-13 16:16             ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-12-15  5:22             ` Emanuel Berg
2022-12-16 17:39               ` Akib Azmain Turja
2022-12-17  0:31                 ` Emanuel Berg
2022-12-18  0:54                   ` Jean Louis
2022-12-19 20:31                     ` Emanuel Berg
2022-12-12 20:01     ` tomas
2022-12-12 20:32       ` Marcin Borkowski
2022-12-12 21:24         ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-12-15  5:18       ` Emanuel Berg
2022-12-15 13:38         ` tomas
2022-12-15 16:46       ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-12-15 17:56         ` tomas
2022-12-17  0:13           ` Emanuel Berg
2022-12-15  3:45     ` Emanuel Berg
2022-12-15 13:22       ` tomas
2022-12-15  3:41 ` Emanuel Berg

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=Y5gHIkN9IMulVPr5@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@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.
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).