]> git.eshelyaron.com Git - emacs.git/commitdiff
Recognize the backslash operator in perl-mode
authorMauro Aranda <maurooaranda@gmail.com>
Tue, 20 Sep 2022 14:18:45 +0000 (11:18 -0300)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 20 Sep 2022 19:11:40 +0000 (21:11 +0200)
* lisp/progmodes/perl-mode.el (perl-syntax-propertize-function):
Add new rule to detect a backslash operator.  (Bug#11996)

* test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-11996): New
test.

* test/lisp/progmodes/cperl-mode-resources/cperl-bug-11996.pl: New
file.

lisp/progmodes/perl-mode.el
test/lisp/progmodes/cperl-mode-resources/cperl-bug-11996.pl [new file with mode: 0644]
test/lisp/progmodes/cperl-mode-tests.el

index bd8f4ecd1c0d3ac07b03760554f46bc591213a0c..7b7a2cdf01935a96a38c5f4a540cf9baec85a826 100644 (file)
                                          (not (nth 3 (syntax-ppss
                                                       (match-beginning 0))))))
                             (string-to-syntax ". p"))))
+      ;; If "\" is acting as a backslash operator, it shouldn't start an
+      ;; escape sequence, so change its syntax.  This allows us to handle
+      ;; correctly the \() construct (Bug#11996) as well as references
+      ;; to string values.
+      ("\\(\\\\\\)['`\"($]" (1 (unless (nth 3 (syntax-ppss))
+                                       (string-to-syntax "."))))
       ;; Handle funny names like $DB'stop.
       ("\\$ ?{?\\^?[_[:alpha:]][_[:alnum:]]*\\('\\)[_[:alpha:]]" (1 "_"))
       ;; format statements
diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-bug-11996.pl b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-11996.pl
new file mode 100644 (file)
index 0000000..566b7e7
--- /dev/null
@@ -0,0 +1,8 @@
+{
+    my @zzzz=(\%seen_couchrequsts, \%seen_people );
+    my @zzzz=\(%seen_couchrequsts, %seen_people );
+    my @zzzz=(\%seen_couchrequsts, \%seen_people );
+}
+
+print "\"Watch out\"";
+$ref = \"howdy";
index 66039d6fc7f531fd64374cdd3d247ed1e1b5b2da..1bb206e7040820507118fb03b666e4a5199e6765 100644 (file)
@@ -788,6 +788,36 @@ under timeout control."
       (should (string-match
                "poop ('foo', \n      'bar')" (buffer-string))))))
 
+(ert-deftest cperl-test-bug-11996 ()
+  "Verify that we give the right syntax property to a backslash operator."
+  (with-temp-buffer
+    (insert-file-contents (ert-resource-file "cperl-bug-11996.pl"))
+    (funcall cperl-test-mode)
+    (font-lock-ensure)
+    (goto-char (point-min))
+    (re-search-forward "\\(\\\\(\\)")
+    (save-excursion
+      (goto-char (match-beginning 1))
+      (should (equal (syntax-after (point)) (string-to-syntax ".")))
+      ;; `forward-sexp' shouldn't complain.
+      (forward-sexp)
+      (should (char-equal (char-after) ?\;)))
+    (re-search-forward "\\(\\\\\"\\)")
+    (save-excursion
+      (goto-char (match-beginning 1))
+      (should (equal (syntax-after (point)) (string-to-syntax "\\")))
+      (should (equal (get-text-property (point) 'face) 'font-lock-string-face)))
+    (re-search-forward "\\(\\\\\"\\)")
+    (save-excursion
+      (goto-char (match-beginning 1))
+      (should (equal (syntax-after (point)) (string-to-syntax "\\"))))
+    (re-search-forward "\\(\\\\\"\\)")
+    (save-excursion
+      (goto-char (match-beginning 1))
+      (should (equal (syntax-after (point)) (string-to-syntax ".")))
+      (should (equal (get-text-property (1+ (point)) 'face)
+                     'font-lock-string-face)))))
+
 (ert-deftest cperl-test-bug-14343 ()
   "Verify that inserting text into a HERE-doc string with Elisp
 does not break fontification."