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 /.../.
;; We can probably just add +, -, !, <, >, %, ^, ~, |, &, ?, : at which
;; point I think only * and / would be missing which could also be added,
;; but need care to avoid affecting the // and */ comment markers.
- ("\\(?:^\\|[=([{,:;]\\)\\(?:[ \t]\\)*\\(/\\)[^/*]"
+ ("\\(?:^\\|[=([{,:;]\\|\\_<return\\_>\\)\\(?:[ \t]\\)*\\(/\\)[^/*]"
(1 (ignore
(forward-char -1)
(when (or (not (memq (char-after (match-beginning 0)) '(?\s ?\t)))
"Regular expression matching variable declaration keywords.")
(defconst js--indent-operator-re
- (concat "[-+*/%<>=&^|?:.]\\([^-+*/]\\|$\\)\\|"
+ (concat "[-+*/%<>&^|?:.]\\([^-+*/]\\|$\\)\\|!?=\\|"
(js--regexp-opt-symbol '("in" "instanceof")))
"Regexp matching operators that affect indentation of continued expressions.")
(save-excursion (backward-char) (not (looking-at "[/*]/")))
(js--looking-at-operator-p)
(and (progn (backward-char)
- (not (looking-at "++\\|--\\|/[/*]"))))))))))
+ (not (looking-at "+\\+\\|--\\|/[/*]"))))))))))
(defun js--end-of-do-while-loop-p ()