From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#37659: rx additions: anychar, unmatchable, unordered-or Date: Wed, 23 Oct 2019 11:15:47 +0200 Message-ID: <1A5B8E3D-B147-4B89-BFAE-50DCB0A64D3B@acm.org> References: <88571301-3F15-428F-82F9-60A23D817EF8@acm.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="75636"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 37659@debbugs.gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 23 11:17:36 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iNClr-000JWC-PT for geb-bug-gnu-emacs@m.gmane.org; Wed, 23 Oct 2019 11:17:36 +0200 Original-Received: from localhost ([::1]:58040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNClp-0006ul-UM for geb-bug-gnu-emacs@m.gmane.org; Wed, 23 Oct 2019 05:17:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54993) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNClM-0006t0-Fh for bug-gnu-emacs@gnu.org; Wed, 23 Oct 2019 05:17:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNClL-0007kf-5J for bug-gnu-emacs@gnu.org; Wed, 23 Oct 2019 05:17:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52024) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNClK-0007kP-ND for bug-gnu-emacs@gnu.org; Wed, 23 Oct 2019 05:17:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iNClK-0003Vy-GG for bug-gnu-emacs@gnu.org; Wed, 23 Oct 2019 05:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 23 Oct 2019 09:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37659 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 37659-submit@debbugs.gnu.org id=B37659.157182217110989 (code B ref 37659); Wed, 23 Oct 2019 09:17:02 +0000 Original-Received: (at 37659) by debbugs.gnu.org; 23 Oct 2019 09:16:11 +0000 Original-Received: from localhost ([127.0.0.1]:60845 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iNCkU-0002qZ-SD for submit@debbugs.gnu.org; Wed, 23 Oct 2019 05:16:11 -0400 Original-Received: from mail212c50.megamailservers.eu ([91.136.10.222]:48510 helo=mail194c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iNCkQ-0002hP-Rg for 37659@debbugs.gnu.org; Wed, 23 Oct 2019 05:16:09 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1571822149; bh=PAxkF6XGK3BAsAbxc1IK+jjqt3YjlzHSBLhNfxf4wSw=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=ENnnNrc9X7jo5v1P7kU4ff4z11onRXkcbBlOga6zyfSCDK5v56lH+1Gk+HJcKt7Ow 9F7COKJAnsvUmcMY2j/KzvVIOCUnzfJw4K9EmwyxbxNYgUPij5PQuj/TDPCHUzA+W4 jy49I3KxyPCR+Ui9bIDBBC529NsJRJePtpG8YbMM= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c188-150-171-71.bredband.comhem.se [188.150.171.71]) (authenticated bits=0) by mail194c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x9N9Fl56019790; Wed, 23 Oct 2019 09:15:49 +0000 In-Reply-To: X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A0B0205.5DB01A45.0054, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=TbLoSiYh c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=M51BFTxLslgA:10 a=_a7OQLmI6xoJ9uaYqNcA:9 a=9kUatgwqPKuF6Lr3:21 a=A-WMwPS5_FwBuQNe:21 a=CjuIK1q_8ugA:10 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:170036 Archived-At: 22 okt. 2019 kl. 19.33 skrev Paul Eggert : >> 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. >=20 > 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. The restriction is simple and easy to document. It is not necessary to = know the underlying reason for it in order to use the construct = effectively. > Moreover, if greed is the longstanding tradition for regexp-opt, = shouldn't plain "or" be greedy, to be consistent with other operators? Yes, I very much favour switching to a DFA engine; is there another way? = Even then a backtracking engine would be needed for backrefs and other = messy cases. However, that's a completely different amount of work. = (Meanwhile, we have 'posix-string-match' etc for those who want greed at = any cost.) The problem that I'm trying to solve here is: how do we make it easy to = match one of multiple strings --- keywords, say --- in rx? Currently, = the answer is something like (regexp (regexp-opt my-keywords)), which = doesn't integrate well with rx user definitions. In addition, the output = of one regexp-opt cannot be used as input to another. 'or-max' would allow a user to say (rx-define veggies (or-max "carrot" "tomato" "cucumber")) (rx-define meats (or-max "beef" "chicken" "pork")) ... (rx (or-max veggies meats)) ... and get a regexp that is guaranteed to be greedy, well-optimised as if = all strings were passed to 'regexp-opt' at once, and robust: a small = change won't change the behaviour radically, and the user won't have to = game or second-guess the engine in order to produce the desired result. If, in the future, 'or' becomes greedy, then 'or-max' will just be a = synonym. > 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. That would make rx strictly less useful than string regexps. That is why = 'unordered-or' was a mistake: the unpredictability made it useless in = many cases, and everyone would just have used regexp-opt (or skipped rx = altogether). It is desirable to have the semantics for 'or' in rx and \| in string = regexps; otherwise, translating and understanding become unnecessarily = difficult. We could say that 'or' and \| either match greedily or in left-to-right = order. However, I'm not sure this solves any problem right now.