all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: will we ever have zero width assertions in regexps?
Date: Fri, 28 Jan 2011 21:51:55 -0500	[thread overview]
Message-ID: <jwvzkqke8n4.fsf-monnier+gnu.emacs.help@gnu.org> (raw)
In-Reply-To: slrnik6lh5.rji.nospam-abuse@powdermilk.math.berkeley.edu

>> To get rid of the occasional pathological case where matching takes
>> forever and Emacs appears to be frozen.  Programmers who are used to
>> backtracking matchers will usually intuitively stay away from regexps
>> that can show such behaviors, but not all programmers do, and even if
>> you're careful there are cases that are hard to avoid.
> Did you try it with Perl recently (last 10 years or so)?

No, but neither have I bumped into pathological cases in Perl before
that (when I did use it).

> As I said, I put some optimizations which in most (AFAIK) practical
> senses remove such pathologies.  (The underlying problems remain; the
> optimizations are only "heuristic"; but one needs to be extra
> inventive to circumvent the optimizations.)

A typical case could look something like "foo *(.*?) *bar". when
matching "foo ..<many space>.. baZ".
Emacs's regexp engine is not very clever and doesn't do much in terms of
avoiding backtracking (it mostly takes care of <foo>*<bar> when <foo>
can only match a single char and <bar> can only start with a char that's
not matched by <foo>), but I can't think of too many ways to handle the
above one efficiently within a "backtracking regexp matcher" framework.

>> Another minor reason is that it can be handy to have an incremental
>> matching primitive, so you can match over a long string one chunk at
>> a time.  I'm not sure how often this would be useful, but I've come
>> across a few cases where it seemed like it could be put to good use
>> (tho, for lack of experience with it, I can't sweat that it would turn
>> out to be a good idea).
> Do not know what you mean by this...

Basically, provide a primitive like (match-string RE STRING LIMIT) that
can not only say "matched between START and END", but also "reached
LIMIT within yet finding a match, here's the suspended SEARCH-STATE at
LIMIT", so you can later resume the search starting at LIMIT by passing
that state.


        Stefan


  reply	other threads:[~2011-01-29  2:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1.1296054361.23496.help-gnu-emacs@gnu.org>
2011-01-26 15:58 ` will we ever have zero width assertions in regexps? Stefan Monnier
2011-01-27  1:45   ` Le Wang
     [not found]   ` <mailman.6.1296092730.6982.help-gnu-emacs@gnu.org>
2011-01-27  2:21     ` Stefan Monnier
2011-01-27  6:34       ` Ilya Zakharevich
2011-01-27 16:10         ` Stefan Monnier
2011-01-28 23:49           ` Ilya Zakharevich
2011-01-29  2:51             ` Stefan Monnier [this message]
2011-01-29 22:28               ` Ilya Zakharevich
2011-01-31 16:08                 ` Stefan Monnier
2011-01-31 17:10                   ` Ilya Zakharevich
2011-01-31 21:29                     ` Stefan Monnier
2011-02-02 15:09                       ` Ilya Zakharevich
2011-02-07 20:30                         ` Stefan Monnier
2011-02-08 22:41                           ` Ilya Zakharevich
2011-01-26 14:55 Le Wang

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=jwvzkqke8n4.fsf-monnier+gnu.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --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.
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.