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#20307: [PATCH] make regexp-opt return a no-match return value with empty input Date: Sat, 2 Mar 2019 15:49:07 +0100 Message-ID: <5B234CE2-1C87-4CD9-9867-5F75BF8E03BB@acm.org> References: <876191vfou.fsf@fencepost.gnu.org> <9995071F-D58F-4D84-958B-58D3DA5F6F20@acm.org> <838sxxh2pl.fsf@gnu.org> <4B1C0A42-4905-4E88-9092-A99B0CD38663@acm.org> <831s3pgwz6.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_F16DAB84-34DC-4008-B57A-E1471B8F60B5" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="83480"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 20307@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 02 15:50:14 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.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h05xt-000Lam-DF for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Mar 2019 15:50:13 +0100 Original-Received: from localhost ([127.0.0.1]:55435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h05xs-0002Ue-F5 for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Mar 2019 09:50:12 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:60102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h05xj-0002RX-Qr for bug-gnu-emacs@gnu.org; Sat, 02 Mar 2019 09:50:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h05xi-0006U0-TP for bug-gnu-emacs@gnu.org; Sat, 02 Mar 2019 09:50:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43617) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h05xi-0006Ti-P6 for bug-gnu-emacs@gnu.org; Sat, 02 Mar 2019 09:50:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h05xi-0003GQ-JA for bug-gnu-emacs@gnu.org; Sat, 02 Mar 2019 09:50:02 -0500 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: Sat, 02 Mar 2019 14:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20307 X-GNU-PR-Package: emacs Original-Received: via spool by 20307-submit@debbugs.gnu.org id=B20307.155153815412481 (code B ref 20307); Sat, 02 Mar 2019 14:50:02 +0000 Original-Received: (at 20307) by debbugs.gnu.org; 2 Mar 2019 14:49:14 +0000 Original-Received: from localhost ([127.0.0.1]:57161 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h05ww-0003FF-1w for submit@debbugs.gnu.org; Sat, 02 Mar 2019 09:49:14 -0500 Original-Received: from mail150c50.megamailservers.eu ([91.136.10.160]:53268 helo=mail50c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h05wt-0003F4-8N for 20307@debbugs.gnu.org; Sat, 02 Mar 2019 09:49:12 -0500 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1551538149; bh=S64VfQnpRJrV+ZTLGMjaKbPGz/yphOepZfRQ50uQo60=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=H/xeq8l+WeKl1nOx1v2zvEgngBr8a3alYTdiGqruNbK6tsN+VYKZhV+r3HD6RswEY 2G+BGjF92hppaEKDnR7qfVvLf4DgDxQmpAyJsbVOTx/59bbMT/lZbfdu8dJ9Ob6SWT tbnLvCKyX7zwI63XWiHRP4p/aC/Kvw0S4UzjRfTs= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c83-251-8-17.bredband.comhem.se [83.251.8.17]) (authenticated bits=0) by mail50c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x22En7dO006882; Sat, 2 Mar 2019 14:49:09 +0000 In-Reply-To: <831s3pgwz6.fsf@gnu.org> X-Mailer: Apple Mail (2.3445.102.3) X-CTCH-RefID: str=0001.0A0B020F.5C7A97E5.004A, 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=a4UeC3aF c=1 sm=1 tr=0 a=NAHmi3I8mP0S/Y8gRKeQyA==:117 a=NAHmi3I8mP0S/Y8gRKeQyA==:17 a=PLihtJHLhY2Q8SDdf8AA:9 a=CjuIK1q_8ugA:10 a=IpRf8xZgK0G6DXkBAkYA: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:155964 Archived-At: --Apple-Mail=_F16DAB84-34DC-4008-B57A-E1471B8F60B5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii >> Sorry, I don't understand. Do we in general distinguish nil from the = empty list in documentation? >=20 > I don't know. I thought the reader might not be aware of their > equivalence, so being explicit would be better. >=20 >> Or did you mean that the phrase should be "If STRINGS is the empty = list..."? >=20 > Yes, that would take care of the issue. Now done in the doc string and in searching.texi. New patch attached. --Apple-Mail=_F16DAB84-34DC-4008-B57A-E1471B8F60B5 Content-Disposition: attachment; filename=0001-Correct-regexp-opt-return-value-for-empty-string-lis.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Correct-regexp-opt-return-value-for-empty-string-lis.patch" Content-Transfer-Encoding: quoted-printable =46rom=20944a6100d5d2563fdd355f9f91a6190117a79efc=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Mon,=2025=20Feb=202019=2015:22:02=20+0100=0A= Subject:=20[PATCH]=20Correct=20regexp-opt=20return=20value=20for=20empty=20= string=20list=0A=0AWhen=20regexp-opt=20is=20called=20with=20an=20empty=20= list=20of=20strings,=20return=20a=20regexp=0Athat=20doesn't=20match=20= anything=20instead=20of=20the=20empty=20string=20(Bug#20307).=0A=0A*=20= doc/lispref/searching.texi=20(Regular=20Expression=20Functions):=0A*=20= etc/NEWS:=0ADocument=20the=20new=20behaviour.=0A*=20= lisp/emacs-lisp/regexp-opt.el=20(regexp-opt):=0AReturn=20a=20never-match=20= regexp=20for=20empty=20inputs.=0A---=0A=20doc/lispref/searching.texi=20=20= =20=20|=20=203=20+++=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=206=20++++++=0A=20= lisp/emacs-lisp/regexp-opt.el=20|=2023=20+++++++++++++++--------=0A=203=20= files=20changed,=2024=20insertions(+),=208=20deletions(-)=0A=0Adiff=20= --git=20a/doc/lispref/searching.texi=20b/doc/lispref/searching.texi=0A= index=20fb7f48474d..38e6204055=20100644=0A---=20= a/doc/lispref/searching.texi=0A+++=20b/doc/lispref/searching.texi=0A@@=20= -960,6=20+960,9=20@@=20possible.=20=20A=20hand-tuned=20regular=20= expression=20can=20sometimes=20be=20slightly=0A=20more=20efficient,=20= but=20is=20almost=20never=20worth=20the=20effort.}.=0A=20@c=20E.g.,=20= see=20https://debbugs.gnu.org/2816=0A=20=0A+If=20@var{strings}=20is=20= the=20empty=20list,=20the=20return=20value=20is=20a=20regexp=20that=0A= +never=20matches=20anything.=0A+=0A=20The=20optional=20argument=20= @var{paren}=20can=20be=20any=20of=20the=20following:=0A=20=0A=20@table=20= @asis=0Adiff=20--git=20a/etc/NEWS=20b/etc/NEWS=0Aindex=20= 7c95988ff5..65eb9ba1af=20100644=0A---=20a/etc/NEWS=0A+++=20b/etc/NEWS=0A= @@=20-1649,6=20+1649,12=20@@=20in=20any=20order.=20=20If=20the=20new=20= third=20argument=20is=20non-nil,=20the=20match=20is=0A=20guaranteed=20to=20= be=20performed=20in=20the=20order=20given,=20as=20if=20the=20strings=20= were=0A=20made=20into=20a=20regexp=20by=20joining=20them=20with=20'\|'.=0A= =20=0A++++=0A+**=20The=20function=20'regexp-opt',=20when=20given=20an=20= empty=20list=20of=20strings,=20now=0A+returns=20a=20regexp=20that=20= never=20matches=20anything,=20which=20is=20an=20identity=20for=0A+this=20= operation.=20=20Previously,=20the=20empty=20string=20was=20returned=20in=20= this=0A+case.=0A+=0A=20=0C=0A=20*=20Changes=20in=20Emacs=2027.1=20on=20= Non-Free=20Operating=20Systems=0A=20=0Adiff=20--git=20= a/lisp/emacs-lisp/regexp-opt.el=20b/lisp/emacs-lisp/regexp-opt.el=0A= index=20d0c5f2d3fc..4404b905a6=20100644=0A---=20= a/lisp/emacs-lisp/regexp-opt.el=0A+++=20b/lisp/emacs-lisp/regexp-opt.el=0A= @@=20-90,6=20+90,9=20@@=20Each=20string=20should=20be=20unique=20in=20= STRINGS=20and=20should=20not=20contain=0A=20any=20regexps,=20quoted=20or=20= not.=20=20Optional=20PAREN=20specifies=20how=20the=0A=20returned=20= regexp=20is=20surrounded=20by=20grouping=20constructs.=0A=20=0A+If=20= STRINGS=20is=20the=20empty=20list,=20the=20return=20value=20is=20a=20= regexp=20that=0A+never=20matches=20anything.=0A+=0A=20The=20optional=20= argument=20PAREN=20can=20be=20any=20of=20the=20following:=0A=20=0A=20a=20= string=0A@@=20-140,14=20+143,18=20@@=20usually=20more=20efficient=20than=20= that=20of=20a=20simplified=20version:=0A=20=09=20=20=20(sorted-strings=20= (delete-dups=0A=20=09=09=09=20=20=20=20(sort=20(copy-sequence=20strings)=20= 'string-lessp)))=0A=20=09=20=20=20(re=0A-=20=20=20=20=20=20=20=20=20=20=20= =20;;=20If=20NOREORDER=20is=20non-nil=20and=20the=20list=20contains=20a=20= prefix=0A-=20=20=20=20=20=20=20=20=20=20=20=20;;=20of=20another=20= string,=20we=20give=20up=20all=20attempts=20at=20optimisation.=0A-=20=20=20= =20=20=20=20=20=20=20=20=20;;=20There=20is=20plenty=20of=20room=20for=20= improvement=20(Bug#34641).=0A-=20=20=20=20=20=20=20=20=20=20=20=20(if=20= (and=20noreorder=20(regexp-opt--contains-prefix=20sorted-strings))=0A-=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(concat=20(or=20open=20= "\\(?:")=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(mapconcat=20#'regexp-quote=20strings=20"\\|")=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"\\)")=0A-=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(regexp-opt-group=20sorted-strings=20= (or=20open=20t)=20(not=20open)))))=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;;=20No=20strings:=20= return=20a\`=20which=20cannot=20match=20anything.=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20((null=20strings)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(concat=20(or=20open=20"\\(?:")=20"a\\`\\)"))=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20;;=20If=20we=20cannot=20reorder,=20give=20up=20all=20= attempts=20at=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20;;=20= optimisation.=20=20There=20is=20room=20for=20improvement=20(Bug#34641).=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20((and=20noreorder=20= (regexp-opt--contains-prefix=20sorted-strings))=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20(concat=20(or=20open=20"\\(?:")=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(mapconcat=20#'regexp-quote=20= strings=20"\\|")=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20"\\)"))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20(t=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(regexp-opt-group=20sorted-strings=20= (or=20open=20t)=20(not=20open))))))=0A=20=20=20=20=20=20=20(cond=20((eq=20= paren=20'words)=0A=20=09=20=20=20=20=20(concat=20"\\<"=20re=20"\\>"))=0A=20= =09=20=20=20=20((eq=20paren=20'symbols)=0A--=20=0A2.17.2=20(Apple=20= Git-113)=0A=0A= --Apple-Mail=_F16DAB84-34DC-4008-B57A-E1471B8F60B5--