Home Download Buy Blog Forum Support

Syntax highlight bug when regex contains /*

Syntax highlight bug when regex contains /*

Postby bronson on Mon Dec 03, 2012 9:39 pm

This code is given improper syntax highlighting... Everything from the /* through the end of the file is shown commented out.

Code: Select all
                var matches = trailing.match(/^\/([^/]*)\/*([^/]*)/)
                if(matches) {
                        ...


Any idea how to fix this? Putting /* */ after the regex restricts the buggy commenting to just the last half of the regex but that's poor workaround... other developers would be perfectly correct to delete nonsense like that.

Thanks for any ideas!
bronson
 
Posts: 38
Joined: Wed Nov 28, 2012 8:52 pm

Re: Syntax highlight bug when regex contains /*

Postby bronson on Mon Dec 03, 2012 10:24 pm

Aha, the problem is that the regex highlighter doesn't realize that / inside [] doesn't need to be escaped.

These regexes are equivalent:

Code: Select all
    /[ab/]/
    /[ab\/]/


But Sublime only correctly highlights the second one.
bronson
 
Posts: 38
Joined: Wed Nov 28, 2012 8:52 pm

Re: Syntax highlight bug when regex contains /*

Postby facelessuser on Mon Dec 03, 2012 11:08 pm

bronson wrote:Aha, the problem is that the regex highlighter doesn't realize that / inside [] doesn't need to be escaped.

These regexes are equivalent:

Code: Select all
    /[ab/]/
    /[ab\/]/


But Sublime only correctly highlights the second one.


This is a language file problem, and also one of those situations I consider "just because you can, doesn't mean you should". I am always explicitly escaping things like that for consistency in my code (I think it makes it very clear that way). I realize though that it is valid if the slash is not escaped in the [] block, but escaping it will always mean that less intelligent parsers and less experienced coders don't get confused. It doesn't mean I won't come across someone else's code were they don't escape stuff like I do, and it would be nice if the highlighter was able to catch this stuff, but In order to do this proper, it takes quite a bit more complexity in the language file to recognize valid un-escaped slashes. And I am sure this issue exists in multiple languages all implementing stuff like this slightly different.

I realize opinion may differ on this...
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Yahoo [Bot] and 22 guests