emacs-diffs
[Top][All Lists]
Advanced

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

master dd9385b: ; perl-mode.el: Detect quote-like operator immediately a


From: Harald Jörg
Subject: master dd9385b: ; perl-mode.el: Detect quote-like operator immediately after =>
Date: Wed, 9 Jun 2021 17:04:55 -0400 (EDT)

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

    ; perl-mode.el: Detect quote-like operator immediately after =>
    
    * lisp/progmodes/perl-mode.el (perl-syntax-propertize-function):
    Detect a quotelike operator immediately after a fat comma "=>"
    (Bug#25098)
    
    * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-bug-25098):
    Test case for the bug with code from the bug report.
    
    * test/lisp/progmodes/cperl-mode-resources/cperl-bug-25098.pl:
    Resource file for the test.
---
 lisp/progmodes/perl-mode.el                         |  2 +-
 .../cperl-mode-resources/cperl-bug-25098.pl         | 21 +++++++++++++++++++++
 test/lisp/progmodes/cperl-mode-tests.el             | 18 ++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index d13c905..a208876 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -285,7 +285,7 @@
              (put-text-property (match-beginning 2) (match-end 2)
                                 'syntax-table (string-to-syntax "\""))
              (perl-syntax-propertize-special-constructs end)))))
-      ("\\(^\\|[?:.,;=|&!~({[ 
\t]\\)\\([msy]\\|q[qxrw]?\\|tr\\)\\>\\s-*\\(?:\\([^])}>= 
\n\t]\\)\\|\\(?3:=\\)[^>]\\)"
+      ("\\(^\\|[?:.,;=|&!~({[ 
\t]\\|=>\\)\\([msy]\\|q[qxrw]?\\|tr\\)\\>\\s-*\\(?:\\([^])}>= 
\n\t]\\)\\|\\(?3:=\\)[^>]\\)"
        ;; Nasty cases:
        ;; /foo/m  $a->m  $#m $m @m %m
        ;; \s (appears often in regexps).
diff --git a/test/lisp/progmodes/cperl-mode-resources/cperl-bug-25098.pl 
b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-25098.pl
new file mode 100644
index 0000000..0987b4e
--- /dev/null
+++ b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-25098.pl
@@ -0,0 +1,21 @@
+# Code from the bug report Bug#25098
+
+my $good = XML::LibXML->load_xml( string => q{<div class="clearfix">});
+my $bad  = XML::LibXML->load_xml( string =>q{<div class="clearfix">});
+
+# Related: Method calls are no quotelike operators.  That's why you
+# can't just add '>' to the character class.
+
+my $method_call  = $object->q(argument);
+
+# Also related, still not fontified correctly:
+#
+#     my $method_call  = $object -> q (argument);
+#
+# perl-mode interprets the method call as a quotelike op (because it
+# is preceded by a space).
+# cperl-mode gets the argument right, but marks q as a quotelike op.
+#
+#     my $greater = 2>q/1/;
+#
+# perl-mode doesn't identify this as a quotelike op.
diff --git a/test/lisp/progmodes/cperl-mode-tests.el 
b/test/lisp/progmodes/cperl-mode-tests.el
index 036e20d..dcf4f39 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -397,6 +397,24 @@ Regular expressions are strings in both perl-mode and 
cperl-mode."
     (search-forward "RIGHT")
     (should (nth 3 (syntax-ppss)))))
 
+(ert-deftest cperl-test-bug-25098 ()
+  "Verify that a quotelike operator is recognized after a fat comma \"=>\".
+Related, check that calling a method named q is not mistaken as a
+quotelike operator."
+  (with-temp-buffer
+    (insert-file-contents (ert-resource-file "cperl-bug-25098.pl"))
+    (funcall cperl-test-mode)
+    (goto-char (point-min))
+    ;; good example from the bug report, with a space
+    (search-forward "q{")
+    (should (nth 3 (syntax-ppss)))
+    ;; bad (but now fixed) example from the bug report, without space
+    (search-forward "q{")
+    (should (nth 3 (syntax-ppss)))
+    ;; calling a method "q" (parens instead of braces to make it valid)
+    (search-forward "q(")
+    (should-not (nth 3 (syntax-ppss)))))
+
 (ert-deftest cperl-test-bug-28650 ()
   "Verify that regular expressions are recognized after 'return'.
 The test uses the syntax property \"inside a string\" for the



reply via email to

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