From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: regular expressions that match nothing Date: Wed, 15 May 2019 23:07:11 +0200 Message-ID: <128EBFB8-78FF-47C3-8F28-C1EF91BFC4BB@acm.org> References: <7a6b23f52418b093a4cf7a6db4306cf425533249.camel@acm.org> <87a7fnzd3u.fsf@web.de> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_008E91CE-1A11-4049-9490-93026A445CA6" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="268911"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Stefan Monnier , emacs-devel@gnu.org To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 15 23:17:24 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hR1H4-0017U3-2s for ged-emacs-devel@m.gmane.org; Wed, 15 May 2019 23:17:18 +0200 Original-Received: from localhost ([127.0.0.1]:42594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hR17c-00035o-7B for ged-emacs-devel@m.gmane.org; Wed, 15 May 2019 17:07:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:60738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hR17O-00034B-1j for emacs-devel@gnu.org; Wed, 15 May 2019 17:07:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hR17N-0002Z5-4C for emacs-devel@gnu.org; Wed, 15 May 2019 17:07:18 -0400 Original-Received: from mail209c50.megamailservers.eu ([91.136.10.219]:40218 helo=mail194c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hR17M-0002Wg-E2 for emacs-devel@gnu.org; Wed, 15 May 2019 17:07:17 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1557954434; bh=lVb+lG/HG9spK04KhIRP2Cf4Kabhli0evuT7wD+Z7Wk=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=En1+RuIm+RyGW2AaxP2/qzFKCmA6kOZXDaf2dB5kXoNTgI/EGPtkKGFQbkNffRKob RKohCbEAmgbtLQqvfposbOAqS5GveTKha5PocJFznSzyxBnOadB2lcSycZd7v10AKO sWbNZhimOw6Uw01ynJhalQlv0SR+gnmF6zyAdLk8= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.1.65] (c-e636e253.032-75-73746f71.bbcust.telenor.se [83.226.54.230]) (authenticated bits=0) by mail194c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x4FL7Ce3009413; Wed, 15 May 2019 21:07:13 +0000 In-Reply-To: <87a7fnzd3u.fsf@web.de> X-Mailer: Apple Mail (2.3445.104.8) X-CTCH-RefID: str=0001.0A0B020F.5CDC7F81.0044, 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=OuZhNR3t c=1 sm=1 tr=0 a=M+GU/qJco4WXjv8D6jB2IA==:117 a=M+GU/qJco4WXjv8D6jB2IA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=g_P7q84f0JQQFQg0RnMA:9 a=CjuIK1q_8ugA:10 a=jPQ0WnQaHDMA:10 a=NN3w1SoFm1sA:10 a=O9ioEQh1jgu5PgwmiloA:9 a=B2y7HmGcmWMA:10 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 91.136.10.219 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:236554 Archived-At: --Apple-Mail=_008E91CE-1A11-4049-9490-93026A445CA6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 15 maj 2019 kl. 22.17 skrev Michael Heerdegen = : >=20 > Should there be an rx regexp form for this? We don't necessarily need a special form for it; we can just make `(or)' = work. Proposed patch attached. (I also added its dual, (seq), since it would = be silly not to.) --Apple-Mail=_008E91CE-1A11-4049-9490-93026A445CA6 Content-Disposition: attachment; filename=0001-Allow-zero-argument-rx-or-and-seq-forms.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Allow-zero-argument-rx-or-and-seq-forms.patch" Content-Transfer-Encoding: quoted-printable =46rom=20b7706f5b398bb360ac1405842efe852ca89b9de8=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Wed,=2015=20May=202019=2022:44:00=20+0200=0A= Subject:=20[PATCH]=20Allow=20zero-argument=20rx=20`or'=20and=20`seq'=20= forms=0A=0AMake=20the=20rx=20`or'=20and=20`seq'=20forms=20accept=20zero=20= arguments=20to=20produce=20a=0Anever-matching=20regexp=20and=20an=20= empty=20string,=20respectively.=0A=0A*=20lisp/emacs-lisp/rx.el=20= (rx-constituents,=20rx-or):=20Permit=20zero=20args.=0A(rx):=20Amend=20= doc=20string=20for=20`or'=20and=20`seq'.=0A*=20= test/lisp/emacs-lisp/rx-tests.el=20(rx-or,=20rx-seq):=20Test=20the=20= change.=0A*=20etc/NEWS=20(Changes=20in=20Specialized=20Modes=20and=20= Packages):=20Mention=20the=20change.=0A---=0A=20etc/NEWS=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=205=20= +++++=0A=20lisp/emacs-lisp/rx.el=20=20=20=20=20=20=20=20=20=20=20=20|=20= 13=20++++++++-----=0A=20test/lisp/emacs-lisp/rx-tests.el=20|=20=208=20= +++++++-=0A=203=20files=20changed,=2020=20insertions(+),=206=20= deletions(-)=0A=0Adiff=20--git=20a/etc/NEWS=20b/etc/NEWS=0Aindex=20= 699a04b524..5f3468596b=20100644=0A---=20a/etc/NEWS=0A+++=20b/etc/NEWS=0A= @@=20-1310,6=20+1310,11=20@@=20when=20given=20in=20a=20string.=20=20= Previously,=20'(any=20"\x80-\xff")'=20would=20match=0A=20characters=20= U+0080...U+00FF.=20=20Now=20the=20expression=20matches=20raw=20bytes=20= in=0A=20the=20128...255=20range,=20as=20expected.=0A=20=0A+***=20The=20= rx=20'or'=20and=20'seq'=20forms=20no=20longer=20require=20any=20= arguments.=0A+The=20zero-argument=20forms=20(or)=20and=20(seq)=20are=20= now=20permitted:=20(or)=0A+produces=20a=20regexp=20that=20never=20= matches=20anything,=20while=20(seq)=20produces=0A+the=20empty=20string,=20= each=20being=20an=20identity=20for=20its=20operation.=0A+=0A=20**=20= Frames=0A=20=0A=20+++=0Adiff=20--git=20a/lisp/emacs-lisp/rx.el=20= b/lisp/emacs-lisp/rx.el=0Aindex=20fdd24317c6..5437927b9e=20100644=0A---=20= a/lisp/emacs-lisp/rx.el=0A+++=20b/lisp/emacs-lisp/rx.el=0A@@=20-111,11=20= +111,11=20@@=0A=20;;=20FIXME:=20support=20macros.=0A=20=0A=20(defvar=20= rx-constituents=20=20=20=20=20=20=20=20=20=20=20=20=20=20;Not=20`const'=20= because=20some=20modes=20extend=20it.=0A-=20=20'((and=09=09.=20(rx-and=20= 1=20nil))=0A+=20=20'((and=09=09.=20(rx-and=200=20nil))=0A=20=20=20=20=20= (seq=09=09.=20and)=09=09;=20SRE=0A=20=20=20=20=20(:=09=09=09.=20and)=09=09= ;=20SRE=0A=20=20=20=20=20(sequence=09=09.=20and)=09=09;=20sregex=0A-=20=20= =20=20(or=09=09=09.=20(rx-or=201=20nil))=0A+=20=20=20=20(or=09=09=09.=20= (rx-or=200=20nil))=0A=20=20=20=20=20(|=09=09=09.=20or)=09=09;=20SRE=0A=20= =20=20=20=20(not-newline=09.=20".")=0A=20=20=20=20=20(nonl=09=09.=20= not-newline)=09;=20SRE=0A@@=20-391,9=20+391,11=20@@=20FORM=20is=20of=20= the=20form=20`(and=20FORM1=20...)'."=0A=20=20=20"Parse=20and=20produce=20= code=20from=20FORM,=20which=20is=20`(or=20FORM1=20...)'."=0A=20=20=20= (rx-check=20form)=0A=20=20=20(rx-group-if=0A-=20=20=20(if=20(memq=20nil=20= (mapcar=20'stringp=20(cdr=20form)))=0A-=20=20=20=20=20=20=20(mapconcat=20= (lambda=20(x)=20(rx-form=20x=20'|))=20(cdr=20form)=20"\\|")=0A+=20=20=20= (cond=0A+=20=20=20=20((null=20(cdr=20form))=20regexp-unmatchable)=0A+=20=20= =20=20((cl-every=20#'stringp=20(cdr=20form))=0A=20=20=20=20=20=20= (regexp-opt=20(cdr=20form)=20nil=20t))=0A+=20=20=20=20(t=20(mapconcat=20= (lambda=20(x)=20(rx-form=20x=20'|))=20(cdr=20form)=20"\\|")))=0A=20=20=20= =20(and=20(memq=20rx-parent=20'(:=20*=20t))=20rx-parent)))=0A=20=0A=20=0A= @@=20-1122,6=20+1124,7=20@@=20CHAR=0A=20`(seq=20SEXP1=20SEXP2=20...)'=0A=20= `(sequence=20SEXP1=20SEXP2=20...)'=0A=20=20=20=20=20=20matches=20what=20= SEXP1=20matches,=20followed=20by=20what=20SEXP2=20matches,=20etc.=0A+=20=20= =20=20=20Without=20arguments,=20matches=20the=20empty=20string.=0A=20=0A=20= `(submatch=20SEXP1=20SEXP2=20...)'=0A=20`(group=20SEXP1=20SEXP2=20...)'=0A= @@=20-1137,7=20+1140,7=20@@=20CHAR=0A=20`(|=20SEXP1=20SEXP2=20...)'=0A=20= =20=20=20=20=20matches=20anything=20that=20matches=20SEXP1=20or=20SEXP2,=20= etc.=20=20If=20all=0A=20=20=20=20=20=20args=20are=20strings,=20use=20= `regexp-opt'=20to=20optimize=20the=20resulting=0A-=20=20=20=20=20regular=20= expression.=0A+=20=20=20=20=20regular=20expression.=20=20Without=20= arguments,=20never=20matches=20anything.=0A=20=0A=20`(minimal-match=20= SEXP)'=0A=20=20=20=20=20=20produce=20a=20non-greedy=20regexp=20for=20= SEXP.=20=20Normally,=20regexps=20matching=0Adiff=20--git=20= a/test/lisp/emacs-lisp/rx-tests.el=20b/test/lisp/emacs-lisp/rx-tests.el=0A= index=204a5919edf0..6f392d616d=20100644=0A---=20= a/test/lisp/emacs-lisp/rx-tests.el=0A+++=20= b/test/lisp/emacs-lisp/rx-tests.el=0A@@=20-107,7=20+107,13=20@@=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20"ab"))=0A=20=20=20=20=20= (should=20(equal=20(and=20(string-match=20(rx=20(or=20"a"=20"ab"=20= "abc"))=20s)=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(match-string=200=20s))=0A-=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20"a"))))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20"a")))=0A+=20=20;;=20Test=20zero-argument=20`or'.=0A+=20= =20(should=20(equal=20(rx=20(or))=20regexp-unmatchable)))=0A+=0A= +(ert-deftest=20rx-seq=20()=0A+=20=20;;=20Test=20zero-argument=20`seq'.=0A= +=20=20(should=20(equal=20(rx=20(seq))=20"")))=0A=20=0A=20(provide=20= 'rx-tests)=0A=20;;=20rx-tests.el=20ends=20here.=0A--=20=0A2.20.1=20= (Apple=20Git-117)=0A=0A= --Apple-Mail=_008E91CE-1A11-4049-9490-93026A445CA6--