GNU bug report logs -
#25529
25.1.90; js-mode: Regexp literal with unbalanced brackets breaks font-lock
Previous Next
Reported by: Mikhail Gusarov <mikhail <at> hola.org>
Date: Wed, 25 Jan 2017 11:15:02 UTC
Severity: minor
Found in version 25.1.90
Done: Tom Tromey <tom <at> tromey.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Tom> I've appended a patch implementing this idea.
Another way is to use a regexp, see appended.
I'll try to write a test for this soon.
Tom
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index e42e014..2b4ae8e 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1694,22 +1694,32 @@ js--syntax-propertize-regexp-syntax-table
(modify-syntax-entry ?\\ "\\" st)
st))
+(defconst js--syntax-propertize-regexp-regexp
+ (rx
+ ;; Start of regexp.
+ "/"
+ (0+ (or
+ ;; Match characters outside of a character class.
+ (not (any ?\[ ?/ ?\\))
+ ;; Match backslash quoted characters.
+ (and "\\" not-newline)
+ ;; Match character class.
+ (and
+ "["
+ (0+ (or
+ (not (any ?\] ?\\))
+ (and "\\" not-newline)))
+ "]")))
+ (group "/")))
+
(defun js-syntax-propertize-regexp (end)
(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))))))
+ (goto-char (nth 8 ppss))
+ (when (looking-at js--syntax-propertize-regexp-regexp)
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'syntax-table (string-to-syntax "\"/"))))))
(defun js-syntax-propertize (start end)
;; JavaScript allows immediate regular expression objects, written /.../.
This bug report was last modified 8 years and 180 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.