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: Thu, 24 Oct 2019 10:58:43 +0200 Message-ID: <6B3E322E-6058-4D8B-A73C-07847411AE1D@acm.org> References: <88571301-3F15-428F-82F9-60A23D817EF8@acm.org> <1A5B8E3D-B147-4B89-BFAE-50DCB0A64D3B@acm.org> <9016eb3d-7d58-5950-862a-13db4c7ff32b@cs.ucla.edu> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_A495D9D4-7179-4C9B-A2F0-18A2279CAF78" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="83938"; 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 Thu Oct 24 10:59:16 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 1iNYxe-000LfS-MT for geb-bug-gnu-emacs@m.gmane.org; Thu, 24 Oct 2019 10:59:15 +0200 Original-Received: from localhost ([::1]:35716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNYxd-0003Cq-81 for geb-bug-gnu-emacs@m.gmane.org; Thu, 24 Oct 2019 04:59:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42336) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNYxW-00037Q-At for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2019 04:59:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNYxU-0004u4-Ou for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2019 04:59:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54739) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNYxU-0004tg-Eu for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2019 04:59:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iNYxS-0000xl-Ft for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2019 04:59:04 -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: Thu, 24 Oct 2019 08:59: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.15719075413694 (code B ref 37659); Thu, 24 Oct 2019 08:59:02 +0000 Original-Received: (at 37659) by debbugs.gnu.org; 24 Oct 2019 08:59:01 +0000 Original-Received: from localhost ([127.0.0.1]:35327 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iNYxR-0000xV-6K for submit@debbugs.gnu.org; Thu, 24 Oct 2019 04:59:01 -0400 Original-Received: from mail230c50.megamailservers.eu ([91.136.10.240]:45814 helo=mail37c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iNYxN-0000xK-8j for 37659@debbugs.gnu.org; Thu, 24 Oct 2019 04:58:58 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1571907525; bh=mtqaKeAGwJalH1GYaTbPJcmVn9C7k3Pr9HQOsLXz1I8=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=VN8L1wxFMODommZsjd+BcV70xVLSo3Wx9KEi4UiB/qCJ/NFUOOQlr4vJK+gEoyi9k KH9s5O3tsFpEwNFu5Ir1CFXiV2ju3w58MlAKNIMGLpbS/1V4kMUyaL1hjtkJEe1g0e fAnDUXyfag7b2obgX7yZ8KeqGuHicxrkkJNZisb4= 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 mail37c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x9O8whgH024571; Thu, 24 Oct 2019 08:58:45 +0000 In-Reply-To: <9016eb3d-7d58-5950-862a-13db4c7ff32b@cs.ucla.edu> X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A0B0204.5DB167C5.008D, 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=eN1tc0h1 c=1 sm=1 tr=0 a=SF+I6pRkHZhrawxbOkkvaA==:117 a=SF+I6pRkHZhrawxbOkkvaA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=M51BFTxLslgA:10 a=OxGMLzmZiu-U-OjVW_kA:9 a=CjuIK1q_8ugA:10 a=kG-5aEGYk6W-mD7-phYA:9 a=B2y7HmGcmWMA: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:170112 Archived-At: --Apple-Mail=_A495D9D4-7179-4C9B-A2F0-18A2279CAF78 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 24 okt. 2019 kl. 01.14 skrev Paul Eggert : >=20 >> how do we make it easy to match one of multiple strings --- keywords, = say --- in rx? >=20 > If that's the real problem, perhaps the name should be "or-tokens" or = something like that, to help remind the reader of the limitations of the = proposed operator: it's meant only for greedy tokenization and it isn't = suited for regular expressions in general. A problem with the name = "or-max" is that it implies a more-general functionality than the = implementation really has. 'or-strings' then perhaps, since there is nothing really restricting it = to 'tokens' (which is a bit hazardous terminology given that regexps are = commonly used for tokenising). In particular, there is no delimiting; = (or-max "IN" "OUT") will match the first part of "INSPECT", which may be = unexpected of something ostensibly matching tokens. On the other hand, 'or-strings' sort of precludes a future relaxation of = the argument restriction. > What happens if you apply or-tokens to arguments that aren't strings = or other or-tokens? Does rx diagnose this? I hope it does. Yes, of course. Working patch attached (it still uses the name = 'or-max'). 'or-max' isn't a vital addition; it just seemed to fill a gap, after = experience with traditional regexp usage. It clearly shouldn't be added = it on a whim. I wanted to get it in place for 27.1, but such a version = rush has rarely resulted in good design. > I was thinking of something more-compatible: we could say that \| is = left-to-right (for users who need compatibility with regexp "|"), and = that 'or' is not necessarily left-to-right (to make room for future = extensions that make 'or' greedy, or more efficient, or both). Sorry, by '\|' I meant the string regexp operator; I take it you propose = separate semantics for the rx '|' and 'or' operators? Maybe we should = worry about that if we ever get near the point of replacing the engine. = There are other concerns, such as how capture groups are set (even if = two branches match equally long texts). I honestly don't think much would break if '\|' (in string regexps) = became greedy overnight, but there is plenty of room to confuse the user = if we introduce subtle distinctions between what has hitherto been = perceived as synonyms. --Apple-Mail=_A495D9D4-7179-4C9B-A2F0-18A2279CAF78 Content-Disposition: attachment; filename=0003-Add-the-rx-or-max-operator.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0003-Add-the-rx-or-max-operator.patch" Content-Transfer-Encoding: quoted-printable =46rom=20b6e1900e64803dc28e915f38febd9a9389acb697=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Wed,=2023=20Oct=202019=2012:47:53=20+0200=0A= Subject:=20[PATCH=203/3]=20Add=20the=20rx=20'or-max'=20operator=0A=0A*=20= doc/lispref/searching.texi=20(Rx=20Constructs):=0A*=20= lisp/emacs-lisp/rx.el=20(rx--or-max-strings,=20rx--translate-or-max)=0A= (rx--translate-form,=20rx--builtin-forms,=20rx):=0A*=20= test/lisp/emacs-lisp/rx-tests.el=20(rx-or-max-def):=0AAdd=20'or-max'.=0A= ---=0A=20doc/lispref/searching.texi=20=20=20=20=20=20=20|=20=207=20= +++++++=0A=20lisp/emacs-lisp/rx.el=20=20=20=20=20=20=20=20=20=20=20=20|=20= 22=20+++++++++++++++++++++-=0A=20test/lisp/emacs-lisp/rx-tests.el=20|=20= 13=20+++++++++++++=0A=203=20files=20changed,=2041=20insertions(+),=201=20= deletion(-)=0A=0Adiff=20--git=20a/doc/lispref/searching.texi=20= b/doc/lispref/searching.texi=0Aindex=205178575a3b..3feaebc16d=20100644=0A= ---=20a/doc/lispref/searching.texi=0A+++=20b/doc/lispref/searching.texi=0A= @@=20-1084,6=20+1084,13=20@@=20Rx=20Constructs=0A=20Without=20arguments,=20= the=20expression=20will=20not=20match=20anything=20at=20all.@*=0A=20= Corresponding=20string=20regexp:=20@samp{@var{A}\|@var{B}\|@dots{}}.=0A=20= =0A+@item=20@code{(or-max=20@var{rx}@dots{})}=0A+@cindex=20@code{or-max}=20= in=20rx=0A+Like=20@code{or},=20but=20always=20favours=20the=20longest=20= possible=20match.=20=20The=0A+@var{rx}s=20must=20be=20strings=20or=20= @code{or-max}=20forms.=20=20The=20resulting=0A+expression=20may=20be=20= more=20efficient=20in=20matching=20than=20the=20corresponding=0A= +@code{or}=20form.=0A+=0A=20@item=20@code{unmatchable}=0A=20@cindex=20= @code{unmatchable}=20in=20rx=0A=20Refuse=20any=20match.=20=20Equivalent=20= to=20@code{(or)}.=0Adiff=20--git=20a/lisp/emacs-lisp/rx.el=20= b/lisp/emacs-lisp/rx.el=0Aindex=20d7677f1444..9afa17c617=20100644=0A---=20= a/lisp/emacs-lisp/rx.el=0A+++=20b/lisp/emacs-lisp/rx.el=0A@@=20-293,6=20= +293,24=20@@=20rx--translate-or=0A=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(cdr=20body)))=0A=20=20=20=20=20= =20=20=20=20=20=20nil))))=0A=20=0A+(defun=20rx--or-max-strings=20(args)=0A= +=20=20"List=20of=20string=20arguments=20in=20an=20'or-max'=20= construct."=0A+=20=20(mapcan=20(lambda=20(item)=0A+=20=20=20=20=20=20=20=20= =20=20=20=20(cond=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20;;=20FIXME:=20= Allow=20single=20characters=20as=20well?=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20((stringp=20item)=20(list=20item))=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20((and=20(consp=20item)=20(eq=20(car=20item)=20'or-max))=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20(rx--or-max-strings=20(cdr=20= item)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20((let=20((expanded=20= (rx--expand-def=20item)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(and=20expanded=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(rx--or-max-strings=20(list=20expanded)))))=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20(t=20(error=20"Illegal=20`or-max'=20argument:=20= %S"=20item))))=0A+=20=20=20=20=20=20=20=20=20=20args))=0A+=0A+(defun=20= rx--translate-or-max=20(body)=0A+=20=20"Translate=20(or-max=20BODY...).=20= =20Return=20(REGEXP=20.=20PRECEDENCE)."=0A+=20=20(cons=20(list=20= (regexp-opt=20(rx--or-max-strings=20body)))=20t))=0A+=0A=20(defun=20= rx--string-to-intervals=20(str)=0A=20=20=20"Decode=20STR=20as=20= intervals:=20A-Z=20becomes=20(?A=20.=20?Z),=20and=20the=20single=0A=20= character=20X=20becomes=20(?X=20.=20?X).=20=20Return=20the=20intervals=20= in=20a=20list."=0A@@=20-854,6=20+872,7=20@@=20rx--translate-form=0A=20=20= =20=20=20(pcase=20(car=20form)=0A=20=20=20=20=20=20=20((or=20'seq=20:=20= 'and=20'sequence)=20(rx--translate-seq=20body))=0A=20=20=20=20=20=20=20= ((or=20'or=20'|)=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (rx--translate-or=20body))=0A+=20=20=20=20=20=20('or-max=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(rx--translate-or-max=20body))=0A=20=20= =20=20=20=20=20((or=20'any=20'in=20'char)=20=20=20=20=20=20= (rx--translate-any=20nil=20body))=0A=20=20=20=20=20=20=20('not-char=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(rx--translate-any=20t=20= body))=0A=20=20=20=20=20=20=20('not=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(rx--translate-not=20nil=20body))=0A@@=20-915,7=20= +934,7=20@@=20rx--translate-form=0A=20=20=20=20=20=20=20=20=20(t=20= (error=20"Unknown=20rx=20form=20`%s'"=20op)))))))=0A=20=0A=20(defconst=20= rx--builtin-forms=0A-=20=20'(seq=20sequence=20:=20and=20or=20|=20any=20= in=20char=20not-char=20not=0A+=20=20'(seq=20sequence=20:=20and=20or=20|=20= or-max=20any=20in=20char=20not-char=20not=0A=20=20=20=20=20repeat=20=3D=20= >=3D=20**=0A=20=20=20=20=20zero-or-more=200+=20*=0A=20=20=20=20=20= one-or-more=201+=20+=0A@@=20-1006,6=20+1025,7=20@@=20rx=0A=20=0A=20(seq=20= RX...)=20=20=20=20Match=20the=20RXs=20in=20sequence.=20=20Alias:=20:,=20= sequence,=20and.=0A=20(or=20RX...)=20=20=20=20=20Match=20one=20of=20the=20= RXs.=20=20Alias:=20|.=0A+(or-max=20RX...)=20Match=20one=20of=20the=20RXs=20= (strings=20and=20or-max=20only),=20longest=20match.=0A=20=0A=20= (zero-or-more=20RX...)=20Match=20RXs=20zero=20or=20more=20times.=20=20= Alias:=200+.=0A=20(one-or-more=20RX...)=20=20Match=20RXs=20one=20or=20= more=20times.=20=20Alias:=201+.=0Adiff=20--git=20= a/test/lisp/emacs-lisp/rx-tests.el=20b/test/lisp/emacs-lisp/rx-tests.el=0A= index=20ef2541d83a..f60932e670=20100644=0A---=20= a/test/lisp/emacs-lisp/rx-tests.el=0A+++=20= b/test/lisp/emacs-lisp/rx-tests.el=0A@@=20-49,6=20+49,19=20@@=20rx-or=0A=20= =20=20(should=20(equal=20(rx=20(|))=0A=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20"\\`a\\`")))=0A=20=0A+(ert-deftest=20rx-or-max=20()=0A= +=20=20(should=20(equal=20(rx=20(or-max=20"ab"=20"abc"))=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20"\\(?:abc?\\)"))=0A+=20=20(should=20= (equal=20(rx=20(or-max=20(or-max=20"a"=20"xy")=20(or-max=20"ab"=20= "abcd")))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "\\(?:a\\(?:b\\(?:cd\\)?\\)?\\|xy\\)")))=0A+=0A+(ert-deftest=20= rx-or-max-def=20()=0A+=20=20(rx-let=20((a=20(or-max=20"a"=20"xy"))=0A+=20= =20=20=20=20=20=20=20=20=20=20(b=20a)=0A+=20=20=20=20=20=20=20=20=20=20=20= (c=20(or-max=20"ab"=20"abcd")))=0A+=20=20=20=20(should=20(equal=20(rx=20= (or-max=20c=20b))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20"\\(?:a\\(?:b\\(?:cd\\)?\\)?\\|xy\\)"))))=0A+=0A=20(ert-deftest=20= rx-char-any=20()=0A=20=20=20"Test=20character=20alternatives=20with=20= `]'=20and=20`-'=20(Bug#25123)."=0A=20=20=20(should=20(equal=0A--=20=0A= 2.21.0=20(Apple=20Git-122)=0A=0A= --Apple-Mail=_A495D9D4-7179-4C9B-A2F0-18A2279CAF78--