From: Paul Eggert <eggert@cs.ucla.edu>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: 37659@debbugs.gnu.org
Subject: bug#37659: rx additions: anychar, unmatchable, unordered-or
Date: Tue, 22 Oct 2019 10:33:40 -0700 [thread overview]
Message-ID: <aadc4bf6-555d-7639-5713-96e96ee0ef9f@cs.ucla.edu> (raw)
In-Reply-To: <88571301-3F15-428F-82F9-60A23D817EF8@acm.org>
On 10/22/19 8:14 AM, Mattias Engdegård wrote:
> 'regexp-opt' always generates a regexp preferring long matches. This is undocumented, but useful enough that I would be surprised if this property wasn't exploited (perhaps unknowingly) by callers. It's quite natural: given a set of strings, surely the caller want them all to be candidates for a match, even if there is no following anchoring pattern.
Yes, the longstanding tradition is that regular expressions are greedy.
> Thus, instead of 'unordered-or', define the operator in terms of long matches: 'or-max' (working name) would work like 'or' but guarantee a longest match, and only permit strings and 'or-max' forms as arguments.
That's an odd restriction. I'm not sure it's a good idea to add an
operator with such a restriction. That is, I know why the restriction is
there (it's because of limitations in the Emacs regexp matcher), but
it's not clear that users should have to know and understand these details.
Moreover, if greed is the longstanding tradition for regexp-opt,
shouldn't plain "or" be greedy, to be consistent with other operators?
That is true for POSIX regular expressions involving "|". For example,
the shell command:
echo abbc |
awk '{n=split($0, a, /b|bb/); for (i=1;i<=n;i++) print a[i]}'
outputs the two lines "a" and "c" (not the three lines "a", "", and "c")
because the "b|bb" matches greedily.
If it's too much trouble to make plain "or" greedy, I suggest just
documenting it as possibly being greedy and possibly not (that is,
document it as being unordered, even if it happens to be ordered now).
This will give us more opportunity for optimization later.
More generally, surely it would be better to improve the underlying
Emacs regular expression matcher to have a greedy "or", or a stingy
"or", or whatever.
next prev parent reply other threads:[~2019-10-22 17:33 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-08 9:36 bug#37659: rx additions: anychar, unmatchable, unordered-or Mattias Engdegård
2019-10-09 8:59 ` Mattias Engdegård
2019-10-11 23:07 ` bug#37659: Mattias Engdegård <mattiase <at> acm.org> Paul Eggert
2019-10-12 10:47 ` Mattias Engdegård
2019-10-13 16:52 ` Paul Eggert
2019-10-13 19:48 ` Mattias Engdegård
2019-10-22 15:14 ` bug#37659: rx additions: anychar, unmatchable, unordered-or Mattias Engdegård
2019-10-22 15:27 ` Robert Pluim
2019-10-22 17:33 ` Paul Eggert [this message]
2019-10-23 9:15 ` Mattias Engdegård
2019-10-23 23:14 ` Paul Eggert
2019-10-24 1:56 ` Drew Adams
2019-10-24 9:09 ` Mattias Engdegård
2019-10-24 14:24 ` Drew Adams
2019-10-24 9:17 ` Phil Sainty
2019-10-24 14:32 ` Drew Adams
2019-10-24 8:58 ` Mattias Engdegård
2019-10-27 11:53 ` Mattias Engdegård
2020-02-11 12:57 ` Mattias Engdegård
2020-02-11 15:43 ` Eli Zaretskii
2020-02-11 19:17 ` Mattias Engdegård
2020-02-12 0:52 ` Paul Eggert
2020-02-12 11:22 ` Mattias Engdegård
2020-02-13 18:38 ` Mattias Engdegård
2020-02-13 18:50 ` Paul Eggert
2020-02-13 19:16 ` Mattias Engdegård
2020-02-13 19:30 ` Eli Zaretskii
2020-02-13 22:23 ` Mattias Engdegård
2020-02-14 7:45 ` Eli Zaretskii
2020-02-14 16:15 ` Paul Eggert
2020-02-14 20:49 ` Mattias Engdegård
2020-03-01 10:09 ` Mattias Engdegård
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=aadc4bf6-555d-7639-5713-96e96ee0ef9f@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=37659@debbugs.gnu.org \
--cc=mattiase@acm.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 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).