emacs-devel
[Top][All Lists]
Advanced

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

Re: Fixing ill-conditioned regular expressions. Proof of concept.


From: Stefan Monnier
Subject: Re: Fixing ill-conditioned regular expressions. Proof of concept.
Date: Thu, 26 Feb 2015 14:12:32 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>> >     R*\(\)R*
>> > , but anybody who writes such regexps deserves what she gets.
>> What is it that I deserve to get?
> You deserve, perhaps, to lose (match-beginning 1) and (match-end 1),
> which were ill-defined anyway.

Why do you think so?  They seem perfectly well-defined to me.
They're just always equal to one another, of course, but to the extent
that the regexp syntax only forces me to put "named positions" in pairs,
if I need a single position, it's fairly natural to just use \(\).

> Have you really written a regexp like this (apart from for testing
> purposes)?.  If so, what's it for?

   grep '\\\\(\\\\)' **/*.el

finds 27 matches.  Taking one example from the list:

   lisp/emacs-lisp/smie.el:     ((looking-at "\\s(\\|\\s)\\(\\)")

what this does is to let me use (match-beginning 1) to figure out which
of the two alternatives was matched.  I could have written this as

       ((looking-at "\\s(\\|\\(\\s)\\)")

but this would be (marginally) slower, because we'd always push
a "group-start" marker before try to match "\\s)", whereas with the
other rule, we only do that when we know "\\s)" has matched.

> By the way, how do you see the prospects of this file becoming
> incorporated into Emacs at some stage?

To be honest, I haven't looked at it at all, yet.
The vague understanding I have of what it might be sounds interesting.
It's just a patch trying to cover up the worst aspects of the
current regexp engine, but since there doesn't seem to be much interest
in improving/overhauling the regexp engine, maybe it's a good stop-gap.


        Stefan



reply via email to

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