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: Mon, 25 Feb 2019 15:57:44 +0100 Message-ID: <9995071F-D58F-4D84-958B-58D3DA5F6F20@acm.org> References: <876191vfou.fsf@fencepost.gnu.org> Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_9D48340B-8194-4BF2-BA40-049C8F42275B" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="220762"; mail-complaints-to="usenet@blaine.gmane.org" To: 20307@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Feb 25 15:58:19 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 1gyHhz-000vHx-Af for geb-bug-gnu-emacs@m.gmane.org; Mon, 25 Feb 2019 15:58:19 +0100 Original-Received: from localhost ([127.0.0.1]:38656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyHhy-0005rq-9L for geb-bug-gnu-emacs@m.gmane.org; Mon, 25 Feb 2019 09:58:18 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:60110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyHhl-0005rl-Qy for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 09:58:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyHhl-00069m-3b for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 09:58:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38085) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyHhi-000694-Ce for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 09:58:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gyHhi-0004Nm-8V for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 09:58:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <876191vfou.fsf@fencepost.gnu.org> Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 25 Feb 2019 14:58: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.155110667016828 (code B ref 20307); Mon, 25 Feb 2019 14:58:02 +0000 Original-Received: (at 20307) by debbugs.gnu.org; 25 Feb 2019 14:57:50 +0000 Original-Received: from localhost ([127.0.0.1]:51629 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gyHhW-0004NM-8d for submit@debbugs.gnu.org; Mon, 25 Feb 2019 09:57:50 -0500 Original-Received: from mail85c50.megamailservers.eu ([91.136.10.95]:59858 helo=mail18c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gyHhT-0004NB-VH for 20307@debbugs.gnu.org; Mon, 25 Feb 2019 09:57:48 -0500 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1551106666; bh=yVOfBZNgv7XDRNrdCKGqRSxEDD8CmZvXJpua8VgyFyI=; h=From:Subject:Date:To:From; b=NTAQarqAm6wmoi09BPJhOzF9/3AZ298AB9DRF+NhgsrqwZO+axYq17Yd7/zWu3rkc g0ZcTd+CSHsUNqeFeThgQTLJAS3PriuWKNfDLR3mPekbnhtxoymCiFJ3bbuO9GB+pd c2Yk/KF4hK1Mmrav7+BcgQmiZ9PQOgZLV6UOcnsQ= 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 mail18c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x1PEviiV023897 for <20307@debbugs.gnu.org>; Mon, 25 Feb 2019 14:57:46 +0000 X-Mailer: Apple Mail (2.3445.102.3) X-CTCH-RefID: str=0001.0A0B0205.5C74026A.002E, 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=KOR08mNo c=1 sm=1 tr=0 a=M+GU/qJco4WXjv8D6jB2IA==:117 a=M+GU/qJco4WXjv8D6jB2IA==:17 a=fsFqxQCvgtBoYdUYAIEA:9 a=CjuIK1q_8ugA:10 a=gYc2_6Fn8gx6W6a85KMA: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:155767 Archived-At: --Apple-Mail=_9D48340B-8194-4BF2-BA40-049C8F42275B Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Here is a patch (moved from Bug#34641 where it was independently reported). --Apple-Mail=_9D48340B-8194-4BF2-BA40-049C8F42275B 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=208efe696f635c948496e3bcfe1e69e902264b957c=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=2073a7304a3b..0b944a2711=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= empty,=20the=20return=20value=20is=20a=20regexp=20that=20never=0A= +matches=20anything.=0A+=0A=20The=20optional=20argument=20@var{paren}=20= can=20be=20any=20of=20the=20following:=0A=20=0A=20@table=20@asis=0Adiff=20= --git=20a/etc/NEWS=20b/etc/NEWS=0Aindex=205f7616429b..6506a1c6b5=20= 100644=0A---=20a/etc/NEWS=0A+++=20b/etc/NEWS=0A@@=20-1624,6=20+1624,12=20= @@=20in=20any=20order.=20=20If=20the=20new=20third=20argument=20is=20= non-nil,=20the=20match=20is=0A=20guaranteed=20to=20be=20performed=20in=20= the=20order=20given,=20as=20if=20the=20strings=20were=0A=20made=20into=20= a=20regexp=20by=20joining=20them=20with=20'\|'.=0A=20=0A++++=0A+**=20The=20= function=20'regexp-opt',=20when=20given=20an=20empty=20list=20of=20= strings,=20now=0A+returns=20a=20regexp=20that=20never=20matches=20= anything,=20which=20is=20an=20identity=20for=0A+this=20operation.=20=20= Previously,=20the=20empty=20string=20was=20returned=20in=20this=0A+case.=0A= +=0A=20=0C=0A=20*=20Changes=20in=20Emacs=2027.1=20on=20Non-Free=20= Operating=20Systems=0A=20=0Adiff=20--git=20= a/lisp/emacs-lisp/regexp-opt.el=20b/lisp/emacs-lisp/regexp-opt.el=0A= index=2033a5b770a0..107b453637=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=20empty,=20the=20return=20value=20is=20a=20regexp=20that=20= never=0A+matches=20anything.=0A+=0A=20The=20optional=20argument=20PAREN=20= can=20be=20any=20of=20the=20following:=0A=20=0A=20a=20string=0A@@=20= -139,14=20+142,18=20@@=20usually=20more=20efficient=20than=20that=20of=20= a=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=_9D48340B-8194-4BF2-BA40-049C8F42275B--