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: Sun, 27 Oct 2019 12:53:05 +0100 Message-ID: <4406A98D-708A-4B04-881A-AD90F7EFF36C@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> <6B3E322E-6058-4D8B-A73C-07847411AE1D@acm.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_5744ECC2-8B96-4382-A0BF-1BF65F99EE87" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="58200"; 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 Sun Oct 27 12:54:13 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 1iOh7c-000Ezp-Ph for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 Oct 2019 12:54:13 +0100 Original-Received: from localhost ([::1]:44978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOh7b-0007Bf-JF for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 Oct 2019 07:54:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51965) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOh7V-00079p-3u for bug-gnu-emacs@gnu.org; Sun, 27 Oct 2019 07:54:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOh7T-0002ro-6M for bug-gnu-emacs@gnu.org; Sun, 27 Oct 2019 07:54:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:32932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iOh7R-0002rX-M3 for bug-gnu-emacs@gnu.org; Sun, 27 Oct 2019 07:54:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iOh7R-0005J9-KD for bug-gnu-emacs@gnu.org; Sun, 27 Oct 2019 07:54:01 -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: Sun, 27 Oct 2019 11:54:01 +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.157217720320354 (code B ref 37659); Sun, 27 Oct 2019 11:54:01 +0000 Original-Received: (at 37659) by debbugs.gnu.org; 27 Oct 2019 11:53:23 +0000 Original-Received: from localhost ([127.0.0.1]:41753 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iOh6o-0005IE-Q6 for submit@debbugs.gnu.org; Sun, 27 Oct 2019 07:53:23 -0400 Original-Received: from mail211c50.megamailservers.eu ([91.136.10.221]:38368 helo=mail194c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iOh6m-0005I4-DB for 37659@debbugs.gnu.org; Sun, 27 Oct 2019 07:53:21 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1572177188; bh=tQsqiJ71bXWPTB4eRK30t3Spij9v8n9F2j8uGMr0Gz4=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=loa69Zt+5f8938C4UP565IfD1GUqFcYnDQesrdJwuIU1xLGI/aReiocJlL/6Bc9T/ zsDcIfYmu6+57r5bK2J/dmnuXEgyA73grCJg94Y1G/2lnXt15bli55BUhut4x0lLS5 qpvqYvPv+kqH1i8b2LukqcwdYImqIhWOzjH7FBNc= 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 x9RBr5Ov006861; Sun, 27 Oct 2019 11:53:07 +0000 In-Reply-To: <6B3E322E-6058-4D8B-A73C-07847411AE1D@acm.org> X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A0B0203.5DB58524.0009, 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=M51BFTxLslgA:10 a=qFqvdvABBfdTmC8CgSsA:9 a=CjuIK1q_8ugA:10 a=Fo7r8Ynid4JQh3uN0QgA: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:170242 Archived-At: --Apple-Mail=_5744ECC2-8B96-4382-A0BF-1BF65F99EE87 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii An observation is that 'or-max' cannot currently be defined by the user, = because there is no way to expand rx forms explicitly. One way to fill = that hole is to add the function (rx-expand-definitions RX-FORM) which would expand RX-FORM until it no longer is a user-defined form. This would permit or-max to be defined as (rx-define or-max (&rest forms) (eval `(regexp ,(regexp-opt (or-max-strings (list forms)))))) (defun or-max-strings (args) (mapcan (lambda (item) (pcase item ((pred stringp) (list item)) (`(or-max . ,rest) (or-max-strings rest)) (_ (error "Illegal `or-max' argument: %S" item)))) (mapcar #'rx-expand-definitions args))) Of course, if the 'or-max' operator is generally useful, it would = probably still make sense to define it as a primitive. --Apple-Mail=_5744ECC2-8B96-4382-A0BF-1BF65F99EE87 Content-Disposition: attachment; filename=0001-Add-rx-expand-definitions.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Add-rx-expand-definitions.patch" Content-Transfer-Encoding: quoted-printable =46rom=2052df813cac0ecb38f62d6740082ee6741ca0e167=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Sun,=2027=20Oct=202019=2012:50:15=20+0100=0A= Subject:=20[PATCH]=20Add=20`rx-expand-definitions'=0A=0A*=20= lisp/emacs-lisp/rx.el=20(rx-expand-definitions):=20New=20function.=0A*=20= test/lisp/emacs-lisp/rx-tests.el=20(rx-expand-definitions):=20Test.=0A=0A= Add=20`rx-expand-definitions',=20allowing=20explicit=20expansion=20of=20= rx=20forms=0Ainside=20(eval=20...).=20(Bug#37659)=0A---=0A=20= lisp/emacs-lisp/rx.el=20=20=20=20=20=20=20=20=20=20=20=20|=20=208=20= ++++++++=0A=20test/lisp/emacs-lisp/rx-tests.el=20|=2017=20= +++++++++++++++++=0A=202=20files=20changed,=2025=20insertions(+)=0A=0A= diff=20--git=20a/lisp/emacs-lisp/rx.el=20b/lisp/emacs-lisp/rx.el=0Aindex=20= 52a35ffa2a..660b336efd=20100644=0A---=20a/lisp/emacs-lisp/rx.el=0A+++=20= b/lisp/emacs-lisp/rx.el=0A@@=20-143,6=20+143,14=20@@=20rx--expand-def=0A=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20op=20(cdr=20= form)=20(nth=200=20def)=20(nth=201=20def))=0A=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(error=20"Not=20an=20`rx'=20form=20= definition:=20%s"=20op)))))))=0A=20=0A+(defun=20rx-expand-definitions=20= (form)=0A+=20=20"Expand=20FORM=20until=20it=20is=20no=20longer=20a=20= user-defined=20rx=20construct.=0A+Then=20return=20the=20result."=0A+=20=20= (let=20((expanded=20(rx--expand-def=20form)))=0A+=20=20=20=20(if=20= expanded=0A+=20=20=20=20=20=20=20=20(rx-expand-definitions=20expanded)=0A= +=20=20=20=20=20=20form)))=0A+=0A=20;;=20TODO:=20Additions=20to=20= consider:=0A=20;;=20-=20A=20construct=20like=20`or'=20but=20without=20= the=20match=20order=20guarantee,=0A=20;;=20=20=20maybe=20`unordered-or'.=20= =20Useful=20for=20composition=20or=20generation=20of=0Adiff=20--git=20= a/test/lisp/emacs-lisp/rx-tests.el=20b/test/lisp/emacs-lisp/rx-tests.el=0A= index=204ecc805aea..369dab83f6=20100644=0A---=20= a/test/lisp/emacs-lisp/rx-tests.el=0A+++=20= b/test/lisp/emacs-lisp/rx-tests.el=0A@@=20-419,6=20+419,23=20@@=20= rx-def-in-not=0A=20=20=20=20=20(should=20(equal=20(rx=20(not=20(d=20?m))=20= (not=20(e=20symbol)))=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20"[^amz]\\S_"))))=0A=20=0A+(ert-deftest=20rx-expand-definitions=20= ()=0A+=20=20(rx-let=20((a=20b)=0A+=20=20=20=20=20=20=20=20=20=20=20(b=20= (*=20nonl)))=0A+=20=20=20=20(should=20(equal=20(rx=20(eval=20= (rx-expand-definitions=20'space)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20"[[:space:]]"))=0A+=20=20=20=20(should=20(equal=20= (rx=20(eval=20(rx-expand-definitions=20'a)))=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20".*")))=0A+=20=20(rx-let-eval=20'((f=20(x)=20= (seq=20?a=20x=20?b))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (g=20(y)=20(f=20(+=20y))))=0A+=20=20=20=20(should=20(equal=20= (rx-to-string=20'(eval=20(rx-expand-definitions=20'digit))=20t)=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20"[[:digit:]]"))=0A+=20= =20=20=20(should=20(equal=20(rx-to-string=20'(eval=20= (rx-expand-definitions=20'(g=20?c)))=20t)=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20"ac+b")))=0A+=20=20(rx-define=20rx--g=20"z")=0A= +=20=20(should=20(equal=20(rx=20(eval=20(rx-expand-definitions=20= 'rx--g)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20"z")))=0A= +=0A=20(ert-deftest=20rx-constituents=20()=0A=20=20=20(let=20= ((rx-constituents=0A=20=20=20=20=20=20=20=20=20=20(append=20'((beta=20.=20= gamma)=0A--=20=0A2.21.0=20(Apple=20Git-122)=0A=0A= --Apple-Mail=_5744ECC2-8B96-4382-A0BF-1BF65F99EE87--