diff options
Diffstat (limited to 'lisp/progmodes/js.el')
| -rw-r--r-- | lisp/progmodes/js.el | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index e42e01481b6..b42b2bca822 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el | |||
| @@ -1687,29 +1687,36 @@ This performs fontification according to `js--class-styles'." | |||
| 1687 | js--font-lock-keywords-3) | 1687 | js--font-lock-keywords-3) |
| 1688 | "Font lock keywords for `js-mode'. See `font-lock-keywords'.") | 1688 | "Font lock keywords for `js-mode'. See `font-lock-keywords'.") |
| 1689 | 1689 | ||
| 1690 | (defconst js--syntax-propertize-regexp-syntax-table | 1690 | (defconst js--syntax-propertize-regexp-regexp |
| 1691 | (let ((st (make-char-table 'syntax-table (string-to-syntax ".")))) | 1691 | (rx |
| 1692 | (modify-syntax-entry ?\[ "(]" st) | 1692 | ;; Start of regexp. |
| 1693 | (modify-syntax-entry ?\] ")[" st) | 1693 | "/" |
| 1694 | (modify-syntax-entry ?\\ "\\" st) | 1694 | (0+ (or |
| 1695 | st)) | 1695 | ;; Match characters outside of a character class. |
| 1696 | (not (any ?\[ ?/ ?\\)) | ||
| 1697 | ;; Match backslash quoted characters. | ||
| 1698 | (and "\\" not-newline) | ||
| 1699 | ;; Match character class. | ||
| 1700 | (and | ||
| 1701 | "[" | ||
| 1702 | (0+ (or | ||
| 1703 | (not (any ?\] ?\\)) | ||
| 1704 | (and "\\" not-newline))) | ||
| 1705 | "]"))) | ||
| 1706 | (group "/")) | ||
| 1707 | "Regular expression matching a JavaScript regexp literal.") | ||
| 1696 | 1708 | ||
| 1697 | (defun js-syntax-propertize-regexp (end) | 1709 | (defun js-syntax-propertize-regexp (end) |
| 1698 | (let ((ppss (syntax-ppss))) | 1710 | (let ((ppss (syntax-ppss))) |
| 1699 | (when (eq (nth 3 ppss) ?/) | 1711 | (when (eq (nth 3 ppss) ?/) |
| 1700 | ;; A /.../ regexp. | 1712 | ;; A /.../ regexp. |
| 1701 | (while | 1713 | (goto-char (nth 8 ppss)) |
| 1702 | (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/" | 1714 | (when (and (looking-at js--syntax-propertize-regexp-regexp) |
| 1703 | end 'move) | 1715 | ;; Don't touch text after END. |
| 1704 | (if (nth 1 (with-syntax-table | 1716 | (<= (match-end 1) end)) |
| 1705 | js--syntax-propertize-regexp-syntax-table | 1717 | (put-text-property (match-beginning 1) (match-end 1) |
| 1706 | (let ((parse-sexp-lookup-properties nil)) | 1718 | 'syntax-table (string-to-syntax "\"/")) |
| 1707 | (parse-partial-sexp (nth 8 ppss) (point))))) | 1719 | (goto-char (match-end 0)))))) |
| 1708 | ;; A / within a character class is not the end of a regexp. | ||
| 1709 | t | ||
| 1710 | (put-text-property (1- (point)) (point) | ||
| 1711 | 'syntax-table (string-to-syntax "\"/")) | ||
| 1712 | nil)))))) | ||
| 1713 | 1720 | ||
| 1714 | (defun js-syntax-propertize (start end) | 1721 | (defun js-syntax-propertize (start end) |
| 1715 | ;; JavaScript allows immediate regular expression objects, written /.../. | 1722 | ;; JavaScript allows immediate regular expression objects, written /.../. |