[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:
http://pastie.textmate.org/private/hxkpy8qkahofrxwyvp4coq
Originally this started on the regular mailing list as a question but
with some help we got this done:
http://lists.macromates.com/textmate/2008-June/025973.html
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][-+]?
[0-9]+)?))\b';
// Try a longer version which starts with a required .#?
[FAILED]
match = '\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?([eE][-+]?
[0-9]+)?)|((\.[0-9]+)([eE][-+]?[0-9]+)?))\b';
// Use a backreference for the dot? [FAILED]
match = '\b((0(x|X)[0-9a-fA-F]+)|(([0-9](\.[0-9]+)?|(?<=\.)
[0-9]+)([eE][-+]?[0-9]+)?))\b';
If these look good could you add this?
Thanks in advance,
Joseph Pecoraro
More information about the textmate-dev
mailing list