GNU bug report logs - #47598
cperl-mode: Highlighting confused with ternary and -x

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: "E. Choroba" <choroba@HIDDEN>; Keywords: patch; dated Mon, 5 Apr 2021 00:06:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) patch. Request was from haj@HIDDEN (Harald Jörg) to control <at> debbugs.gnu.org. Full text available.

Message received at 47598 <at> debbugs.gnu.org:


Received: (at 47598) by debbugs.gnu.org; 6 Apr 2021 18:33:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 06 14:33:20 2021
Received: from localhost ([127.0.0.1]:41742 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTqVs-00058S-F8
	for submit <at> debbugs.gnu.org; Tue, 06 Apr 2021 14:33:20 -0400
Received: from mout01.posteo.de ([185.67.36.65]:38169)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <haj@HIDDEN>) id 1lTqVo-00058B-Rx
 for 47598 <at> debbugs.gnu.org; Tue, 06 Apr 2021 14:33:18 -0400
Received: from submission (posteo.de [89.146.220.130]) 
 by mout01.posteo.de (Postfix) with ESMTPS id E1393160061
 for <47598 <at> debbugs.gnu.org>; Tue,  6 Apr 2021 20:33:08 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017;
 t=1617733988; bh=n4vevaqW6BtTcQo2M/UJMLGl2hQgDvtEExLX58CdcWA=;
 h=From:To:Cc:Subject:Date:From;
 b=TKIrWSUzZ3DX2UJ8UnbBf09x/gYjmxV1+Qp8y1lrrg9TAS54T0S/nIW26OcEwvZ9u
 L3ddTxg9Taad4VpREF8R4Pd+pK6BapOTHpsTs7udANVXoWrPl9h+DMcCa5O3dsCHaf
 9c2SnYcdUuM+dlkJY/gR5ZlFJuXRbaqbee1svAq6dqvDmLGdhDsy3umJW0lQAI5EKR
 EB3lhGhmGbL4J3tRxFwBFKGEWvojZudoytYCLUWH7YkD7yOoI0WG3ES3UAj4kEn2XB
 OqWtJqb7wUi11O4FL9gPTSWR1V00axwQj1esVnwsDkyqcnxkhqovWIVMLMVNKAIb+H
 uiENi1iIjqHtg==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4FFGP016xYz6tmK;
 Tue,  6 Apr 2021 20:33:07 +0200 (CEST)
From: haj@HIDDEN (Harald =?utf-8?Q?J=C3=B6rg?=)
To: "E. Choroba" <choroba@HIDDEN>
Subject: Re: bug#47598: cperl-mode: Highlighting confused with ternary and -x
 [PATCH]
In-Reply-To: <alpine.LSU.2.21.2104050157030.2256@silent> (E. Choroba's message
 of "Mon, 5 Apr 2021 02:04:56 +0200 (CEST)")
References: <alpine.LSU.2.21.2104050157030.2256@silent>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
Date: Tue, 06 Apr 2021 20:33:07 +0200
Message-ID: <87zgyb2rh8.fsf@hajtower>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 47598
Cc: 47598 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

--=-=-=
Content-Type: text/plain

E. Choroba writes:

> When combining the ternary operator with file tests using the default
> argument, cperl-mode gets confused.
>
> For example:
>
> my $f = -f ? 'file'
>       : -l ? [readlink]
>       : -d ? 'dir'
>            : 'unknown';
>
> It seems to think the ?'s are not part of a ternary operator, but
> rather a match-once operator. ...

Exactly, that is what is happening here.

> ... Note that m?? without m results in a
> syntax error since Perl 5.22.

Because of that it seems appropriate to stop dealing with bare ?foo?
altogether.  So, the patch eliminates the recognition of bare ?foo?, and
also deletes the corresponding lines from CPerl's builtin short
documentation.  The test in the patch uses the text from the bug report,
and also checks that m?foo? is still processed as a regular expression,
and a bare ?foo?  isn't.
-- 
Cheers,
haj

--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0001-cperl-mode-Eliminate-bad-interpretation-of-foo-bug-4.patch
Content-Description: Don't support ?foo?

From 3e9b727d2b7215ca73bc9334bf5b904916640055 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@HIDDEN>
Date: Tue, 6 Apr 2021 20:21:25 +0200
Subject: [PATCH] ; cperl-mode: Eliminate bad interpretation of ?foo?
 (bug#47598)

* lisp/progmodes/cperl-mode.el (cperl-find-pods-heres): Delete
?? from the allowed bare regexp delimiters.
(cperl-short-docs): Delete ?...? from the documentation.

* test/lisp/progmodes/cperl-mode-tests.el (cperl-bug-47598):
Add tests for good, bad, and ambiguous use of ? as regex
delimiter.
---
 lisp/progmodes/cperl-mode.el            | 16 ++++++---------
 test/lisp/progmodes/cperl-mode-tests.el | 27 +++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 7878e91096..d58b126ae9 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -3585,7 +3585,7 @@ cperl-find-pods-heres
 		"\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT
 		"\\|"
 		;; 1+6+2+1=10 extra () before this:
-		"\\([?/<]\\)"	; /blah/ or ?blah? or <file*glob>
+		"\\([/<]\\)"	; /blah/ or <file*glob>
 		"\\|"
 		;; 1+6+2+1+1=11 extra () before this
 		"\\<" cperl-sub-regexp "\\>" ;  sub with proto/attr
@@ -3920,7 +3920,7 @@ cperl-find-pods-heres
 		;; 1+6+2=9 extra () before this:
 		;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
 		;; "\\|"
-		;; "\\([?/<]\\)"	; /blah/ or ?blah? or <file*glob>
+		;; "\\([/<]\\)"	; /blah/ or <file*glob>
 		(setq b1 (if (match-beginning 10) 10 11)
 		      argument (buffer-substring
 				(match-beginning b1) (match-end b1))
@@ -3958,7 +3958,7 @@ cperl-find-pods-heres
 		(goto-char (match-beginning b1))
 		(cperl-backward-to-noncomment (point-min))
 		(or bb
-		    (if (eq b1 11)	; bare /blah/ or ?blah? or <foo>
+		    (if (eq b1 11)	; bare /blah/ or <foo>
 			(setq argument ""
 			      b1 nil
 			      bb	; Not a regexp?
@@ -3966,7 +3966,7 @@ cperl-find-pods-heres
 			       ;; What is below: regexp-p?
 			       (and
 				(or (memq (preceding-char)
-					  (append (if (memq c '(?\? ?\<))
+					  (append (if (char-equal c ?\<)
 						      ;; $a++ ? 1 : 2
 						      "~{(=|&*!,;:["
 						    "~{(=|&+-*!,;:[") nil))
@@ -3977,14 +3977,11 @@ cperl-find-pods-heres
 					   (forward-sexp -1)
 ;; After these keywords `/' starts a RE.  One should add all the
 ;; functions/builtins which expect an argument, but ...
-					   (if (eq (preceding-char) ?-)
-					       ;; -d ?foo? is a RE
-					       (looking-at "[a-zA-Z]\\>")
 					     (and
 					      (not (memq (preceding-char)
 							 '(?$ ?@ ?& ?%)))
 					      (looking-at
-					       "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\|say\\|return\\)\\>")))))
+					       "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\|say\\|return\\)\\>"))))
 				    (and (eq (preceding-char) ?.)
 					 (eq (char-after (- (point) 2)) ?.))
 				    (bobp))
@@ -7232,8 +7229,7 @@ cperl-short-docs
 ... >= ...	Numeric greater than or equal to.
 ... >> ...	Bitwise shift right.
 ... >>= ...	Bitwise shift right assignment.
-... ? ... : ...	Condition=if-then-else operator.   ?PAT? One-time pattern match.
-?PATTERN?	One-time pattern match.
+... ? ... : ...	Condition=if-then-else operator.
 @ARGV	Command line arguments (not including the command name - see $0).
 @INC	List of places to look for perl scripts during do/include/use.
 @_    Parameter array for subroutines; result of split() unless in list context.
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index 14bc48b92f..1b3a816d87 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -495,4 +495,31 @@ cperl-test-bug-47112
                          'font-lock-constant-face
                        font-lock-string-face))))))
 
+(ert-deftest cperl-test-bug-47598 ()
+  "Check that a file test followed by ? is no longer interpreted
+as a regex."
+  ;; Testing the text from the bug report
+  (with-temp-buffer
+    (insert "my $f = -f ? 'file'\n")
+    (insert "      : -l ? [readlink]\n")
+    (insert "      : -d ? 'dir'\n")
+    (insert "      : 'unknown';\n")
+    (funcall cperl-test-mode)
+    ;; Perl mode doesn't highlight file tests as functions, so we
+    ;; can't test for the function's face.  But we can verify that the
+    ;; function is not a string.
+    (goto-char (point-min))
+    (search-forward "?")
+    (should-not (nth 3 (syntax-ppss (point)))))
+  ;; Testing the actual targets for the regexp: m?foo? (still valid)
+  ;; and ?foo? (invalid since Perl 5.22)
+  (with-temp-buffer
+    (insert "m?foo?;")
+    (funcall cperl-test-mode)
+    (should (nth 3 (syntax-ppss 3))))
+  (with-temp-buffer
+    (insert " ?foo?;")
+    (funcall cperl-test-mode)
+    (should-not (nth 3 (syntax-ppss 3)))))
+
 ;;; cperl-mode-tests.el ends here
-- 
2.20.1


--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47598; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 5 Apr 2021 00:05:19 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 04 20:05:19 2021
Received: from localhost ([127.0.0.1]:36652 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTCk3-00078S-FO
	for submit <at> debbugs.gnu.org; Sun, 04 Apr 2021 20:05:19 -0400
Received: from lists.gnu.org ([209.51.188.17]:41082)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <choroba@HIDDEN>) id 1lTCjz-00078H-UR
 for submit <at> debbugs.gnu.org; Sun, 04 Apr 2021 20:05:18 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:33952)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <choroba@HIDDEN>) id 1lTCjz-0003F7-Q9
 for bug-gnu-emacs@HIDDEN; Sun, 04 Apr 2021 20:05:15 -0400
Received: from ufal-mail.mff.cuni.cz ([195.113.20.158]:59010)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <choroba@HIDDEN>) id 1lTCjx-0007iL-RR
 for bug-gnu-emacs@HIDDEN; Sun, 04 Apr 2021 20:05:15 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
 by ufal-mail.mff.cuni.cz (Postfix) with ESMTP id 9175E736CF0
 for <bug-gnu-emacs@HIDDEN>; Mon,  5 Apr 2021 02:05:06 +0200 (CEST)
Received: from ufal-mail.mff.cuni.cz ([127.0.0.1])
 by localhost (ufal-mail.mff.cuni.cz [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id Qq6utk0wBdcD for <bug-gnu-emacs@HIDDEN>;
 Mon,  5 Apr 2021 02:05:06 +0200 (CEST)
Received: from localhost (localhost.localdomain [127.0.0.1])
 by ufal-mail.mff.cuni.cz (Postfix) with ESMTP id 8667C7502AD
 for <bug-gnu-emacs@HIDDEN>; Mon,  5 Apr 2021 02:05:06 +0200 (CEST)
X-Virus-Scanned: amavisd-new at ufal.mff.cuni.cz
Received: from ufal-mail.mff.cuni.cz ([127.0.0.1])
 by localhost (ufal-mail.mff.cuni.cz [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id wVd0WnxshIjG for <bug-gnu-emacs@HIDDEN>;
 Mon,  5 Apr 2021 02:05:06 +0200 (CEST)
Received: from [192.168.0.200] (83-101-243-80.cust.centrio.cz [80.243.101.83])
 by ufal-mail.mff.cuni.cz (Postfix) with ESMTPSA id 476B27379C2
 for <bug-gnu-emacs@HIDDEN>; Mon,  5 Apr 2021 02:05:06 +0200 (CEST)
Date: Mon, 5 Apr 2021 02:04:56 +0200 (CEST)
From: "E. Choroba" <choroba@HIDDEN>
X-X-Sender: choroba@silent
To: bug-gnu-emacs@HIDDEN
Subject: cperl-mode: Highlighting confused with ternary and -x
Message-ID: <alpine.LSU.2.21.2104050157030.2256@silent>
User-Agent: Alpine 2.21 (LSU 202 2017-01-01)
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset=US-ASCII
Received-SPF: none client-ip=195.113.20.158; envelope-from=choroba@HIDDEN;
 helo=ufal-mail.mff.cuni.cz
X-Spam_score_int: -41
X-Spam_score: -4.2
X-Spam_bar: ----
X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3,
 SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

When combining the ternary operator with file tests using the default 
argument, cperl-mode gets confused.

For example:

my $f = -f ? 'file'
       : -l ? [readlink]
       : -d ? 'dir'
            : 'unknown';

It seems to think the ?'s are not part of a ternary operator, but rather a 
match-once operator. Note that m?? without m results in a syntax error since 
Perl 5.22.

Ch.




Acknowledgement sent to "E. Choroba" <choroba@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#47598; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 9 Apr 2021 10:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.