1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-12 16:23:57 +00:00

; 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.
This commit is contained in:
Harald Jörg 2021-06-09 22:58:53 +02:00
parent ff65ea932c
commit dd9385b404
3 changed files with 40 additions and 1 deletions

View File

@ -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).

View File

@ -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.

View File

@ -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