pombreda / js2-mode

Automatically exported from code.google.com/p/js2-mode
0 stars 0 forks source link

Parser confuses quotes in a regexp with a true string #80

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Parser gets confused by regexp with a quote in it, believing it to be the
start of a string.  This is using the latest release of js2 (20080616a).

<enter the following line and hit enter>

  return str.replace(/'/g, "q");  

<js2 does this>

  return str.replace(/'/g, "q");'
                      + ''

Original issue reported on code.google.com by dshilv...@gmail.com on 18 Jun 2008 at 6:13

GoogleCodeExporter commented 9 years ago
Same here with the following regexp:

var stringRE = /('[^']*')|("[^"]*")/g;

It's important to say that the file becomes basically impossible to edit after 
such a
regex, because the mode always tries to automatically insert '' + '' when you 
hit
enter, even if there are lines between the insertion point and the offending 
line.
The only way to continue working is to put the offending redex in the last 
line. 

Original comment by andrei.f...@gmail.com on 25 Jun 2008 at 4:12

GoogleCodeExporter commented 9 years ago
The best workaround I have for now is to add a comment at the end of the line 
that
closes the string.  This keeps the error from continuing through the rest of 
the file.

  return str.replace(/'/g, "q");  //'

Original comment by dshilv...@gmail.com on 29 Jun 2008 at 7:26

GoogleCodeExporter commented 9 years ago
The reason that this happens is because of the function parse-partial-sexp 
which is
able to return some rather nice things. One of those things is whether or not 
the
cursor is current in a string. The problem arises in the fact that this function
bases it's judgment on the syntax table defined by the mode. Currently ' is 
defined
as a character which can being a string, and the syntax table knows nothing 
about
regular expressions (from what I can tell).

I don't know enough about how the syntax table works to actually fix the 
problem.

Original comment by waw...@gmail.com on 5 Oct 2008 at 1:02

GoogleCodeExporter commented 9 years ago
Also true for double-quotes, e.g. /[^"]/ (reported in another bug that I'm 
marking as
a duplicate of this one).

Original comment by steve.ye...@gmail.com on 23 Jul 2009 at 11:07

GoogleCodeExporter commented 9 years ago
Issue 99 has been merged into this issue.

Original comment by steve.ye...@gmail.com on 23 Jul 2009 at 11:09

GoogleCodeExporter commented 9 years ago

Original comment by steve.ye...@gmail.com on 23 Jul 2009 at 11:13

GoogleCodeExporter commented 9 years ago
This can be fixed by adding a syntax-table text property to the chars inside 
regexps,
and telling parse-partial-sexp to respect text properties.  I'll fix it for an
upcoming release (in a week or so.)

Original comment by steve.ye...@gmail.com on 23 Jul 2009 at 11:26

GoogleCodeExporter commented 9 years ago
Fixed in 20090723b.el

Original comment by steve.ye...@gmail.com on 23 Jul 2009 at 11:38

GoogleCodeExporter commented 9 years ago
This is happening again for me; I have the 20090723b.el release.

The culprit code is attached; it's based off some json library for jquery my 
team is
using. Hideous regexp, but it's valid, according to jslint.

Original comment by chai...@gmail.com on 12 Nov 2009 at 1:29

Attachments: