--- Begin Message ---
Subject: |
Re: bug#9183: js-mode highlights quotes inside regexp character sets as string |
Date: |
Fri, 05 Aug 2011 12:54:45 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
> The following is valid JavaScript:
> /[']/.test(str)
> js-mode erroneously highlights everything following `'' as a string.
> Same problem with `"'.
I installed the patch below which should fix this case and a few others.
But I don't know how to solve it completely because I don't know
Javascript enough to be sure exactly how to distinguish a /-division
from a /-regexp from a /-comment-starter in all cases:
- is something like
x = 1 + /a/.test("foo");
valid? If so, is there a list of infix operators somewhere?
- I'm giving up on handling a /regexp/ that immediately follows an
implicit semicolon.
Stefan
=== modified file 'lisp/progmodes/js.el'
--- lisp/progmodes/js.el 2011-06-30 16:22:33 +0000
+++ lisp/progmodes/js.el 2011-08-05 16:52:20 +0000
@@ -1658,15 +1658,19 @@
;; below.
(eval-and-compile
(defconst js--regexp-literal
-
"[=(,:]\\(?:\\s-\\|\n\\)*\\(/\\)\\(?:\\\\.\\|[^/*\\]\\)\\(?:\\\\.\\|[^/\\]\\)*\\(/\\)"
+ (concat
+ ;; We want to match regular expressions only at the beginning of
+ ;; expressions.
+ ;; FIXME: Should we also allow /regexp/ after infix operators such as +,
+ ;; /, -, *, >, ...?
+ "\\(?:\\`\\|[=([{,:;]\\)\\(?:\\s-\\|\n\\)*"
+ "\\(/\\)\\(?:\\\\.\\|[^/*\\]\\)\\(?:\\\\.\\|[^/\\]\\)*\\(/\\)")
"Regexp matching a JavaScript regular expression literal.
Match groups 1 and 2 are the characters forming the beginning and
end of the literal."))
(defconst js-syntax-propertize-function
(syntax-propertize-rules
- ;; We want to match regular expressions only at the beginning of
- ;; expressions.
(js--regexp-literal (1 "\"") (2 "\""))))
;;; Indentation
--- End Message ---