[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#37659: rx additions: anychar, unmatchable, unordered-or
From: |
Paul Eggert |
Subject: |
bug#37659: rx additions: anychar, unmatchable, unordered-or |
Date: |
Tue, 22 Oct 2019 10:33:40 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 |
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.
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Mattias Engdegård, 2019/10/08
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Mattias Engdegård, 2019/10/09
- bug#37659: Mattias Engdegård <mattiase <at> acm.org>, Paul Eggert, 2019/10/11
- bug#37659: Mattias Engdegård <mattiase <at> acm.org>, Mattias Engdegård, 2019/10/12
- bug#37659: Mattias Engdegård <mattiase <at> acm.org>, Paul Eggert, 2019/10/13
- bug#37659: Mattias Engdegård <mattiase <at> acm.org>, Mattias Engdegård, 2019/10/13
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Mattias Engdegård, 2019/10/22
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Robert Pluim, 2019/10/22
- bug#37659: rx additions: anychar, unmatchable, unordered-or,
Paul Eggert <=
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Mattias Engdegård, 2019/10/23
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Paul Eggert, 2019/10/23
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Drew Adams, 2019/10/23
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Mattias Engdegård, 2019/10/24
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Drew Adams, 2019/10/24
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Phil Sainty, 2019/10/24
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Drew Adams, 2019/10/24
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Mattias Engdegård, 2019/10/24
- bug#37659: rx additions: anychar, unmatchable, unordered-or, Mattias Engdegård, 2019/10/27