unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: "Štěpán Němec" <stepnem@gmail.com>
Cc: 9183-done@debbugs.gnu.org
Subject: bug#9183: js-mode highlights quotes inside regexp character sets as string
Date: Fri, 05 Aug 2011 12:54:45 -0400	[thread overview]
Message-ID: <jwvaabnst43.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87d3gv34nt.fsf@gmail.com> ("Štěpán Němec"'s message of "Wed, 27 Jul 2011 21:27:34 +0200")

> 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






  reply	other threads:[~2011-08-05 16:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-27 19:27 bug#9183: js-mode highlights quotes inside regexp character sets as string Štěpán Němec
2011-08-05 16:54 ` Stefan Monnier [this message]
2011-08-06 11:34   ` Štěpán Němec
2011-08-12 15:48     ` Stefan Monnier
2011-08-12 16:47       ` Daniel Colascione
2011-08-12 17:25       ` Štěpán Němec

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvaabnst43.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=9183-done@debbugs.gnu.org \
    --cc=stepnem@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).