unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#44073: cperl-mode: Cleanup - Delete a misleading comment [PATCH]
@ 2020-10-18 23:55 Harald Jörg
  2020-10-19  8:58 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Jörg @ 2020-10-18 23:55 UTC (permalink / raw)
  To: 44073

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

Severity: minor

With this patch, cperl-mode.el no longer informs the user about "Font
lock bugs" which have been fixed - or worked around - long ago: Some of
Perl's punctuation variables contain string delimiters ($`, $' and $")
but they don't start strings.  Fontification handles this correctly.

The patch eliminates the comment, and it comes with a test to verify
that cperl-mode gets it right in all cases which were listed in the
comment, plus some more.


[-- Attachment #2: 0001-cperl-mode-Delete-a-misleading-comment-add-tests-for.patch --]
[-- Type: text/x-patch, Size: 4362 bytes --]

From d5cc24d57c2653f8c21c7bfe0bb75ff4b2df7ada Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
Date: Mon, 19 Oct 2020 01:34:20 +0200
Subject: [PATCH] cperl-mode: Delete a misleading comment, add tests for
 verification

* test/lisp/progmodes/cperl-mode-tests.el
(cperl-mode-fontify-punct-vars): Add regression tests to verify
that fontification of punctuation variables doesn't start strings.

* lisp/progmodes/cperl-mode.el: Delete a comment which explains a
bug which has been fixed a long time ago.
---
 lisp/progmodes/cperl-mode.el                  |  7 ------
 .../fontify-punctuation-vars.pl               | 20 +++++++++++++++
 test/lisp/progmodes/cperl-mode-tests.el       | 25 +++++++++++++++++++
 3 files changed, 45 insertions(+), 7 deletions(-)
 create mode 100644 test/lisp/progmodes/cperl-mode-resources/fontify-punctuation-vars.pl

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 5b6e50c820..ebbea6bed9 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -71,13 +71,6 @@
 
 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
 
-;;;; Font lock bugs as of v4.32:
-
-;; The following kinds of Perl code erroneously start strings:
-;; \$`  \$'  \$"
-;; $opt::s  $opt_s  $opt{s}  (s => ...)  /\s+.../
-;; likewise with m, tr, y, q, qX instead of s
-
 ;;; Code:
 \f
 ;;; Compatibility with older versions (for publishing on ELPA)
diff --git a/test/lisp/progmodes/cperl-mode-resources/fontify-punctuation-vars.pl b/test/lisp/progmodes/cperl-mode-resources/fontify-punctuation-vars.pl
new file mode 100644
index 0000000000..fa328438cb
--- /dev/null
+++ b/test/lisp/progmodes/cperl-mode-resources/fontify-punctuation-vars.pl
@@ -0,0 +1,20 @@
+# The following Perl punctiation variables contain characters which
+# are classified as string delimiters in the syntax table.  The mode
+# should not be confused by these.
+# The corresponding tests check that two consecutive '#' characters
+# are seen as comments, not as strings.
+my $pre = $`;  ##  $PREMATCH,      use another ` # to balance out
+my $pos = $';  ##  $POSTMATCH,     use another ' # to balance out
+my $lsp = $";  ##  $LIST_SEPARATOR use another " # to balance out
+
+# In the second level, we use the reference constructor \ on these
+# variables.  The backslash is an escape character *only* in strings.
+my $ref = \$`; ## \$PREMATCH,      use another ` # to balance out
+my $rif = \$'; ## \$POSTMATCH,     use another ' # to balance out
+my $raf = \$"; ## \$LIST_SEPARATOR use another " # to balance out
+
+my $opt::s = 0;       ## s is no substitution here
+my $opt_s  = 0;       ## s is no substitution here
+my %opt = (s => 0);   ## s is no substitution here
+$opt{s} = 0;          ## s is no substitution here
+$opt_s =~ /\s+.../    ## s is no substitution here
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index e2af2b5b8d..2a3a759093 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -196,4 +196,29 @@ cperl-mode-test-indent-styles
             (should (equal got expected)))))
       (cperl-set-style "CPerl"))))
 
+(ert-deftest cperl-mode-fontify-punct-vars ()
+  "Test fontification of Perl's punctiation variables.
+Perl has variable names containing unbalanced quotes for the list
+separator $\" and pre- and postmatch $` and $'.  A reference to
+these variables, for example \\$\", should not cause the dollar
+to be escaped, which would then start a string beginning with the
+quote character.  This used to be broken in cperl-mode at some
+point in the distant past, and is still broken in perl-mode. "
+  (skip-unless (eq cperl-test-mode #'cperl-mode))
+  (let ((file (ert-resource-file "fontify-punctuation-vars.pl")))
+    (with-temp-buffer
+      (insert-file-contents file)
+      (goto-char (point-min))
+      (funcall cperl-test-mode)
+      (while (search-forward "##" nil t)
+        ;; The third element of syntax-ppss is true if in a string,
+        ;; which would indicate bad interpretation of the quote.  The
+        ;; fourth element is true if in a comment, which should be the
+        ;; case.
+        (should (equal (nth 3 (syntax-ppss)) nil))
+        (should (equal (nth 4 (syntax-ppss)) t))
+      )
+    )))
+
+
 ;;; cperl-mode-tests.el ends here
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#44073: cperl-mode: Cleanup - Delete a misleading comment [PATCH]
  2020-10-18 23:55 bug#44073: cperl-mode: Cleanup - Delete a misleading comment [PATCH] Harald Jörg
@ 2020-10-19  8:58 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2020-10-19  8:58 UTC (permalink / raw)
  To: Harald Jörg; +Cc: 44073

Harald Jörg <haj@posteo.de> writes:

>
> With this patch, cperl-mode.el no longer informs the user about "Font
> lock bugs" which have been fixed - or worked around - long ago: Some of
> Perl's punctuation variables contain string delimiters ($`, $' and $")
> but they don't start strings.  Fontification handles this correctly.
>
> The patch eliminates the comment, and it comes with a test to verify
> that cperl-mode gets it right in all cases which were listed in the
> comment, plus some more.

Thanks; applied to the trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-19  8:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-18 23:55 bug#44073: cperl-mode: Cleanup - Delete a misleading comment [PATCH] Harald Jörg
2020-10-19  8:58 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).