]> git.eshelyaron.com Git - emacs.git/commitdiff
(js-syntax-propertize-regexp): Recognize "slash in a character class"
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 23 Dec 2014 16:17:55 +0000 (11:17 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 23 Dec 2014 16:17:55 +0000 (11:17 -0500)
Fixes: debbugs:19397
* lisp/progmodes/js.el (js--syntax-propertize-regexp-syntax-table): New var.
(js-syntax-propertize-regexp): Use it to recognize "slash in
a character class".

lisp/ChangeLog
lisp/progmodes/js.el
test/indent/js.js

index d8bb1c89f1fcd23d00d15cfd9936ab345d7c172d..12430b69fb7cc0ede5c0890236dab8d38ed92546 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-23  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * progmodes/js.el (js--syntax-propertize-regexp-syntax-table): New var.
+       (js-syntax-propertize-regexp): Use it to recognize "slash in
+       a character class" (bug#19397).
+
 2014-12-22  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * completion.el: Use post-self-insert-hook (bug#19400).
index c2c45aa4ef825714f659e5141adcc40d8af8f576..45074d338d305d310fc3ec0f616d1556af133b0d 100644 (file)
@@ -1637,12 +1637,29 @@ This performs fontification according to `js--class-styles'."
                                    js--font-lock-keywords-3)
   "Font lock keywords for `js-mode'.  See `font-lock-keywords'.")
 
+(defconst js--syntax-propertize-regexp-syntax-table
+  (let ((st (make-char-table 'syntax-table (string-to-syntax "."))))
+    (modify-syntax-entry ?\[ "(]" st)
+    (modify-syntax-entry ?\] ")[" st)
+    (modify-syntax-entry ?\\ "\\" st)
+    st))
+
 (defun js-syntax-propertize-regexp (end)
-  (when (eq (nth 3 (syntax-ppss)) ?/)
-    ;; A /.../ regexp.
-    (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/" end 'move)
-      (put-text-property (1- (point)) (point)
-                         'syntax-table (string-to-syntax "\"/")))))
+  (let ((ppss (syntax-ppss)))
+    (when (eq (nth 3 ppss) ?/)
+      ;; A /.../ regexp.
+      (while
+          (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/"
+                                   end 'move)
+            (if (nth 1 (with-syntax-table
+                           js--syntax-propertize-regexp-syntax-table
+                         (let ((parse-sexp-lookup-properties nil))
+                           (parse-partial-sexp (nth 8 ppss) (point)))))
+                ;; A / within a character class is not the end of a regexp.
+                t
+              (put-text-property (1- (point)) (point)
+                                 'syntax-table (string-to-syntax "\"/"))
+              nil))))))
 
 (defun js-syntax-propertize (start end)
   ;; Javascript allows immediate regular expression objects, written /.../.
index 1924094e9d860778b9e137d16c471be731db89cf..2d458e1b769cd2404b27870944962ff25c91eb8c 100644 (file)
@@ -7,6 +7,11 @@ let c = 1,
 var e = 100500,
     + 1;
 
+function test ()
+{
+     return /[/]/.test ('/')     // (bug#19397)
+}
+
 var f = bar('/protocols/')
 baz();