From: Tom Tromey <tom@tromey.com>
To: Tom Tromey <tom@tromey.com>
Cc: 25529@debbugs.gnu.org
Subject: bug#25529: diagnosis and one approach to a fix
Date: Sat, 04 Feb 2017 23:01:57 -0700 [thread overview]
Message-ID: <87shnt89be.fsf@tromey.com> (raw)
In-Reply-To: <87wpd58ag6.fsf@tromey.com> (Tom Tromey's message of "Sat, 04 Feb 2017 22:37:29 -0700")
Tom> I don't think there is a way to teach parse-partial-sexp that "^" is a
Tom> quote only in this one specific instance.
This doesn't actually make sense anyway.
The "^" is a distraction, as this is valid:
let x = /[[]/;
Tom> One possible fix here would be to change this function to do a simple
Tom> parse of the regexp literal. I think it would only really have to
Tom> handle parsing bracket syntax and looking for the terminating "/". The
Tom> current code also looks for balanced parens, but I don't think this is
Tom> actually needed.
I've appended a patch implementing this idea.
Tom
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index e42e014..083cef9 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1698,18 +1698,30 @@ js-syntax-propertize-regexp
(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))))))
+ (let ((keep-going t)
+ (backslash nil)
+ (in-bracket nil))
+ (while keep-going
+ (forward-char)
+ (let ((c (char-after)))
+ (cond
+ (backslash
+ (setq backslash nil))
+ ((eq c ?\\)
+ (setq backslash t))
+ ((eq c ?\[)
+ ;; Note that inside a bracket we can see another unescaped open
+ ;; bracket.
+ (setq in-bracket t))
+ ((eq c ?\])
+ (setq in-bracket nil))
+ ((eq c ?/)
+ (unless in-bracket
+ ;; We're done.
+ (setq keep-going nil)
+ (put-text-property
+ (point) (1+ (point))
+ 'syntax-table (string-to-syntax "\"/")))))))))))
(defun js-syntax-propertize (start end)
;; JavaScript allows immediate regular expression objects, written /.../.
next prev parent reply other threads:[~2017-02-05 6:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-25 7:22 bug#25529: 25.1.90; js-mode: Regexp literal with unbalanced brackets breaks font-lock Mikhail Gusarov
2017-02-05 5:37 ` bug#25529: diagnosis and one approach to a fix Tom Tromey
2017-02-05 6:01 ` Tom Tromey [this message]
2017-02-05 18:05 ` Tom Tromey
2017-02-05 18:43 ` Tom Tromey
2017-02-06 1:12 ` Dmitry Gutov
2017-02-06 17:27 ` Tom Tromey
2017-02-07 2:20 ` Dmitry Gutov
2017-02-07 13:07 ` Tom Tromey
2017-02-07 13:11 ` Dmitry Gutov
2017-02-07 14:56 ` Stefan Monnier
2017-02-11 1:52 ` Tom Tromey
2017-02-11 3:45 ` Stefan Monnier
2017-02-11 4:06 ` Tom Tromey
2017-02-11 4:22 ` Stefan Monnier
2017-02-11 15:27 ` Tom Tromey
2017-02-11 15:41 ` Stefan Monnier
2017-02-11 17:13 ` Tom Tromey
2017-02-11 19:11 ` Dmitry Gutov
2017-02-11 19:37 ` bug#25529: done Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87shnt89be.fsf@tromey.com \
--to=tom@tromey.com \
--cc=25529@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.