[SVN] Javascript Syntax Highlighting Tweaks (with Patch)

Joseph Pecoraro joepeck02 at gmail.com
Fri Jun 27 21:53:09 UTC 2008

I made some changes to the Javascript Syntax to take care of some cases:

(1) Scientific notation => Ex, 1e5 and 2.5E5
(2) Regular Expressions in an array or parameter list => Ex. [/test/],  
or new Array(/test/, /test/)
(3) Highlighting params in a nameless function => Ex. (function(a){})()

The patch is available at this pastie:

Originally this started on the regular mailing list as a question but  
with some help we got this done:

I took a look at the jQuery, Prototype, and prettify.js sources using  
the patch above and could only find a few more edge cases that aren't  
handled that were failing before as well, but I don't think they are  
too important:
(1) var $continue... highlights "continue" as a keyword but it  
shouldn't be because of the '$' in front of it.  \b worked a little  
too well here =)
(2) .5 * .5.... In javascript digits before the decimal point are  
optional but the highlighting right now keeps the decimal point  
white.  I tried to get around this with a backreference (?<=\.) but  
failed.  Here is what I tried:

         // Currently is
         match = '\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?([eE][-+]? 
         // Try a longer version which starts with a required .#?  
         match = '\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?([eE][-+]? 
         // Use a backreference for the dot? [FAILED]
         match = '\b((0(x|X)[0-9a-fA-F]+)|(([0-9](\.[0-9]+)?|(?<=\.) 

If these look good could you add this?

Thanks in advance,
Joseph Pecoraro

More information about the textmate-dev mailing list