Home Download Buy Blog Forum Support

Invalid JS syntax highlighting -- regex inside array

Invalid JS syntax highlighting -- regex inside array

Postby polarix on Wed Aug 01, 2012 7:45 pm

The JavaScript.tmLanguage seems to have inaccurate results for the following string, though it is legal javascript:

Code: Select all
var pl=[/^\'(?:[^\']|\'\')*\'/, /^(?:G+|y+|M+|k+|S+|E+|a+|h+|K+|H+|c+|L+|Q+|d+|m+|s+|v+|z+|Z+)/, /^[^\'GyMkSEahKHcLQdmsvzZ]+/]; function ql(a){return a}


When we break it up onto different lines, it works fine.
Code: Select all
var pl=[
/^\'(?:[^\']|\'\')*\'/,
/^(?:G+|y+|M+|k+|S+|E+|a+|h+|K+|H+|c+|L+|Q+|d+|m+|s+|v+|z+|Z+)/,
/^[^\'GyMkSEahKHcLQdmsvzZ]+/]; function ql(a){return a}


Looks like there's an inaccurate lookbehind I don't fully understand in the JavaScript.tmLanguage...
Code: Select all
<string>(?&lt;=[=(:]|^|return|&amp;&amp;|\|\||!)\s*(/)(?![/*+{}?])</string>
polarix
 
Posts: 1
Joined: Wed Aug 01, 2012 7:39 pm

Re: Invalid JS syntax highlighting -- regex inside array

Postby facelessuser on Wed Aug 01, 2012 8:26 pm

I use this in my JavaScript.tmLanguage. With this regex, your code seems to look fine for me.

            <string>(?&lt;=[\s\[\,=(:]|^|return|&amp;&amp;|\|\||!)\s*(/)(?![/*+{}?]|[^/]*$)</string>


There is a bunch of variations of fixes for JavaScript regex floating around in the forum. I can't even remember how much of this is my fixes and how much is from another person. I am also sure this can be improved further, but hopefully this will help.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 10 guests