emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 330dd51f8bf: ; cperl-mode.el: Do not mistake a left-shift operato


From: Harald Jörg
Subject: master 330dd51f8bf: ; cperl-mode.el: Do not mistake a left-shift operator for a here-doc.
Date: Sat, 14 Oct 2023 12:22:50 -0400 (EDT)

branch: master
commit 330dd51f8bf154fedde2110675fd606400173e23
Author: Harald Jörg <haj@posteo.de>
Commit: Harald Jörg <haj@posteo.de>

    ;cperl-mode.el: Do not mistake a left-shift operator for a here-doc.
    
    * lisp/progmodes/cperl-mode.el (cperl-find-pods-heres): Empty
    unquoted delimiters for here-documents are now forbidden
    (Bug#65834).
    
    * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-65834):
    New test.
    
    * test/lisp/progmodes/cperl-mode-resources/cperl-bug-65834.pl: new
    resource with source code from the bug report.
---
 lisp/progmodes/cperl-mode.el                             |  4 ++--
 .../progmodes/cperl-mode-resources/cperl-bug-65834.pl    |  5 +++++
 test/lisp/progmodes/cperl-mode-tests.el                  | 16 ++++++++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 7b72e3baee5..6ef552137a7 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -3973,8 +3973,8 @@ recursive calls in starting lines of here-documents."
           "\\([^\"'`\n]*\\)"           ; 4 + 1
           "\\4"
           "\\|"
-          ;; Second variant: Identifier or \ID (same as 'ID') or empty
-          "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 5 + 1, 6 + 1
+          ;; Second variant: Identifier or \ID (same as 'ID')
+          "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\)" ; 5 + 1, 6 + 1
           ;; Do not have <<= or << 30 or <<30 or << $blah.
           ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
           "\\)"
diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-bug-65834.pl 
b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-65834.pl
new file mode 100644
index 00000000000..775a113ac17
--- /dev/null
+++ b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-65834.pl
@@ -0,0 +1,5 @@
+# -*- mode: cperl -*-
+if ($t->[3]<<5) {
+  return 0;
+}
+# comment
diff --git a/test/lisp/progmodes/cperl-mode-tests.el 
b/test/lisp/progmodes/cperl-mode-tests.el
index de7a614496f..0af44c8e08d 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -1379,6 +1379,22 @@ as a regex."
        (forward-line 1))))
   (cperl-set-style-back))
 
+(ert-deftest cperl-test-bug-65834 ()
+  "Verify that CPerl mode identifies a left-shift operator.
+Left-shift and here-documents both use the \"<<\" operator.
+In the code provided by this bug report, it needs to be
+detected as left-shift operator."
+  (with-temp-buffer
+    (insert-file-contents (ert-resource-file "cperl-bug-65834.pl"))
+    (funcall cperl-test-mode)
+    (font-lock-ensure)
+    (search-forward "retur")             ; leaves point before the "n"
+    (should (equal (get-text-property (point) 'face)
+                   font-lock-keyword-face))
+    (search-forward "# comm")           ; leaves point before "ent"
+    (should (equal (get-text-property (point) 'face)
+                   font-lock-comment-face))))
+
 (ert-deftest cperl-test-bug-66145 ()
   "Verify that hashes and arrays are only fontified in code.
 In strings, comments and POD the syntaxified faces should



reply via email to

[Prev in Thread] Current Thread [Next in Thread]