emacs-diffs
[Top][All Lists]
Advanced

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

master 90f54aa: ; perl-mode.el: Detect regexes immediately after "|&"


From: Harald Jörg
Subject: master 90f54aa: ; perl-mode.el: Detect regexes immediately after "|&"
Date: Tue, 8 Jun 2021 17:32:58 -0400 (EDT)

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

    ; 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.
---
 lisp/progmodes/perl-mode.el                        |  2 +-
 .../cperl-mode-resources/cperl-bug-23992.pl        | 10 ++++++++
 test/lisp/progmodes/cperl-mode-tests.el            | 30 ++++++++++++++++++----
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index fd23683..d13c905 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 0000000..1db639c
--- /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 7cdfa45..036e20d 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 } # /"))



reply via email to

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