summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Jörg <haj@posteo.de>2021-06-08 23:23:25 +0200
committerHarald Jörg <haj@posteo.de>2021-06-08 23:23:25 +0200
commit90f54aad5e978653f5a590cdfb68090a0f9a25fc (patch)
tree67a8c81503178253413aeb6d94876305fbee4605
parent9625e3026b516cba3117d0096fe33ad7e523482b (diff)
downloademacs-90f54aad5e978653f5a590cdfb68090a0f9a25fc.tar.gz
; perl-mode.el: Detect regexes immediately after "|&"
* lisp/progmodes/perl-mode.el (perl-syntax-propertize-function): Add "|&" to the list of characters after which a slash starts a regular expression (Bug#23992). * test/lisp/progmodes/cperl-mode-tests.el (cperl-test-ppss): Correct the docstring. (cperl-test-bug-23992): New test for Bug#23992. (cperl-test-bug-42168): Adapt inline comments to the current code. * test/lisp/progmodes/cperl-mode-resources/cperl-bug-23992.pl: Resource file with example code from the bug report.
-rw-r--r--lisp/progmodes/perl-mode.el2
-rw-r--r--test/lisp/progmodes/cperl-mode-resources/cperl-bug-23992.pl10
-rw-r--r--test/lisp/progmodes/cperl-mode-tests.el30
3 files changed, 36 insertions, 6 deletions
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index fd23683bc0a..d13c9053d57 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-23992.pl b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-23992.pl
new file mode 100644
index 00000000000..1db639c6aa2
--- /dev/null
+++ b/test/lisp/progmodes/cperl-mode-resources/cperl-bug-23992.pl
@@ -0,0 +1,10 @@
+# Test file for Bug#23992
+#
+# The "||" case is directly from the report,
+# the "&&" case has been added for symmetry.
+
+s/LEFT/L/g || s/RIGHT/R/g || s/aVALUE\D+//g;
+s/LEFT/L/g||s/RIGHT/R/g||s/aVALUE\D+//g;
+
+s/LEFT/L/g && s/RIGHT/R/g && s/aVALUE\D+//g;
+s/LEFT/L/g&&s/RIGHT/R/g&&s/aVALUE\D+//g;
diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmodes/cperl-mode-tests.el
index 7cdfa45d6f7..036e20d7cca 100644
--- a/test/lisp/progmodes/cperl-mode-tests.el
+++ b/test/lisp/progmodes/cperl-mode-tests.el
@@ -37,7 +37,7 @@
;;; Utilities
(defun cperl-test-ppss (text regexp)
- "Return the `syntax-ppss' of the first character matched by REGEXP in TEXT."
+ "Return the `syntax-ppss' after the last character matched by REGEXP in TEXT."
(interactive)
(with-temp-buffer
(insert text)
@@ -377,6 +377,26 @@ documentation it does the right thing anyway."
(cperl-indent-command)
(forward-line 1))))
+(ert-deftest cperl-test-bug-23992 ()
+ "Verify that substitutions are fontified directly after \"|&\".
+Regular expressions are strings in both perl-mode and cperl-mode."
+ (with-temp-buffer
+ (insert-file-contents (ert-resource-file "cperl-bug-23992.pl"))
+ (funcall cperl-test-mode)
+ (goto-char (point-min))
+ ;; "or" operator, with spaces
+ (search-forward "RIGHT")
+ (should (nth 3 (syntax-ppss)))
+ ;; "or" operator, without spaces
+ (search-forward "RIGHT")
+ (should (nth 3 (syntax-ppss)))
+ ;; "and" operator, with spaces
+ (search-forward "RIGHT")
+ (should (nth 3 (syntax-ppss)))
+ ;; "and" operator, without spaces
+ (search-forward "RIGHT")
+ (should (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
@@ -448,14 +468,14 @@ If seen as regular expression, then the slash is displayed using
font-lock-constant-face. If seen as a division, then it doesn't
have a face property."
:tags '(:fontification)
- ;; The next two Perl expressions have divisions. Perl "punctuation"
- ;; operators don't get a face.
+ ;; The next two Perl expressions have divisions. The slash does not
+ ;; start a string.
(let ((code "{ $a++ / $b }"))
(should (equal (nth 8 (cperl-test-ppss code "/")) nil)))
(let ((code "{ $a-- / $b }"))
(should (equal (nth 8 (cperl-test-ppss code "/")) nil)))
- ;; The next two Perl expressions have regular expressions. The
- ;; delimiter of a RE is fontified with font-lock-constant-face.
+ ;; The next two Perl expressions have regular expressions. The slash
+ ;; starts a string.
(let ((code "{ $a+ / $b } # /"))
(should (equal (nth 8 (cperl-test-ppss code "/")) 7)))
(let ((code "{ $a- / $b } # /"))