emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117024: * lisp/progmodes/perl-mode.el (perl--syntax


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r117024: * lisp/progmodes/perl-mode.el (perl--syntax-exp-intro-regexp): New var.
Date: Fri, 25 Apr 2014 19:22:31 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117024
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2014-04-25 15:22:26 -0400
message:
  * lisp/progmodes/perl-mode.el (perl--syntax-exp-intro-regexp): New var.
  (perl-syntax-propertize-function): Use it.  Extend handling of
  here-docs to the unquoted case.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/perl-mode.el    perlmode.el-20091113204419-o5vbwnq5f7feedwu-402
  test/indent/perl.perl          perl.perl-20121031024456-cjjxr53eeyg5rvml-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-04-25 16:11:07 +0000
+++ b/lisp/ChangeLog    2014-04-25 19:22:26 +0000
@@ -1,7 +1,13 @@
+2014-04-25  Stefan Monnier  <address@hidden>
+
+       * progmodes/perl-mode.el (perl--syntax-exp-intro-regexp): New var.
+       (perl-syntax-propertize-function): Use it.  Extend handling of
+       here-docs to the unquoted case.
+
 2014-04-25  Eli Zaretskii  <address@hidden>
 
-       * tooltip.el (tooltip-show-help-non-mode, tooltip-show-help): Use
-       equal-including-properties to compare help-echo strings.  (Bug#17331)
+       * tooltip.el (tooltip-show-help-non-mode, tooltip-show-help):
+       Use equal-including-properties to compare help-echo strings (bug#17331).
 
 2014-04-25  Leo Liu  <address@hidden>
 

=== modified file 'lisp/progmodes/perl-mode.el'
--- a/lisp/progmodes/perl-mode.el       2014-04-23 01:56:18 +0000
+++ b/lisp/progmodes/perl-mode.el       2014-04-25 19:22:26 +0000
@@ -66,22 +66,7 @@
 ;; a rich language; writing a more suitable parser would be a big job):
 ;; 2)  The globbing syntax <pattern> is not recognized, so special
 ;;       characters in the pattern string must be backslashed.
-;; 3)  The << quoting operators are not recognized; see below.
-;; 5)  To make '$' work correctly, $' is not recognized as a variable.
-;;     Use "$'" or $POSTMATCH instead.
 ;;
-;; If you don't use font-lock, additional problems will appear:
-;; 1)  Regular expression delimiters do not act as quotes, so special
-;;       characters such as `'"#:;[](){} may need to be backslashed
-;;       in regular expressions and in both parts of s/// and tr///.
-;; 4)  The q and qq quoting operators are not recognized; see below.
-;; 5)  To make variables such a $' and $#array work, perl-mode treats
-;;       $ just like backslash, so '$' is not treated correctly.
-;; 6)  Unfortunately, treating $ like \ makes ${var} be treated as an
-;;       unmatched }.  See below.
-;; 7)  When ' (quote) is used as a package name separator, perl-mode
-;;       doesn't understand, and thinks it is seeing a quoted string.
-
 ;; Here are some ugly tricks to bypass some of these problems:  the perl
 ;; expression /`/ (that's a back-tick) usually evaluates harmlessly,
 ;; but will trick perl-mode into starting a quoted string, which
@@ -218,6 +203,13 @@
 (defvar perl-quote-like-pairs
   '((?\( . ?\)) (?\[ . ?\]) (?\{ . ?\}) (?\< . ?\>)))
 
+(eval-and-compile
+  (defconst perl--syntax-exp-intro-regexp
+    (concat "\\(?:\\(?:^\\|[^$@&%[:word:]]\\)"
+            (regexp-opt '("split" "if" "unless" "until" "while" "print"
+                          "grep" "map" "not" "or" "and" "for" "foreach"))
+            "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*")))
+
 ;; FIXME: handle here-docs and regexps.
 ;; <<EOF <<"EOF" <<'EOF' (no space)
 ;; see `man perlop'
@@ -278,10 +270,7 @@
       ;; *opening* slash.  We can afford to mis-match the closing ones
       ;; here, because they will be re-treated separately later in
       ;; perl-font-lock-special-syntactic-constructs.
-      ((concat "\\(?:\\(?:^\\|[^$@&%[:word:]]\\)"
-               (regexp-opt '("split" "if" "unless" "until" "while" "split"
-                             "grep" "map" "not" "or" "and" "for" "foreach"))
-               "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*\\(/\\)")
+      ((concat perl--syntax-exp-intro-regexp "\\(/\\)")
        (2 (ignore
            (if (and (match-end 1)       ; / at BOL.
                     (save-excursion
@@ -316,10 +305,15 @@
                                   (string-to-syntax "\"")))
              (perl-syntax-propertize-special-constructs end)))))
       ;; Here documents.
-      ;; TODO: Handle <<WORD.  These are trickier because you need to
-      ;; disambiguate with the shift operator.
-      ("<<[ 
\t]*\\('[^'\n]*'\\|\"[^\"\n]*\"\\|\\\\[[:alpha:]][[:alnum:]]*\\).*\\(\n\\)"
-       (2 (let* ((st (get-text-property (match-beginning 2) 'syntax-table))
+      ((concat
+        "\\(?:"
+        ;; << "EOF", << 'EOF', or << \EOF
+        "<<[ \t]*\\('[^'\n]*'\\|\"[^\"\n]*\"\\|\\\\[[:alpha:]][[:alnum:]]*\\)"
+        ;; The <<EOF case which needs perl--syntax-exp-intro-regexp, to
+        ;; disambiguate with the left-bitshift operator.
+        "\\|" perl--syntax-exp-intro-regexp "<<\\(?1:\\sw+\\)\\)"
+        ".*\\(\n\\)")
+       (3 (let* ((st (get-text-property (match-beginning 3) 'syntax-table))
                  (name (match-string 1)))
             (goto-char (match-end 1))
             (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0))))
@@ -329,7 +323,8 @@
                     ;; Remember the names of heredocs found on this line.
                     (cons (pcase (aref name 0)
                             (`?\\ (substring name 1))
-                            (_ (substring name 1 -1)))
+                            ((or `?\" `?\' `?\`) (substring name 1 -1))
+                            (_ name))
                           (cdr st)))))))
       ;; We don't call perl-syntax-propertize-special-constructs directly
       ;; from the << rule, because there might be other elements (between

=== modified file 'test/indent/perl.perl'
--- a/test/indent/perl.perl     2014-04-23 01:56:18 +0000
+++ b/test/indent/perl.perl     2014-04-25 19:22:26 +0000
@@ -3,7 +3,11 @@
 
 if ($c && /====/){xyz;}
 
-print <<"EOF1" . s/he"llo/th'ere/;
+print "a" . <<EOF . s/he"llo/th'ere/;
+It's a surprise!
+EOF
+
+print <<\EOF1 . s/he"llo/th'ere/;
 foo
 EOF2
 bar


reply via email to

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