I am currently working on some syntax highlighting in Javascript.
To match strings, I would use something like this:code = code.replace(/("([^"\\]*(\\.[^"\\]*)*)")/gm, "<span class=\"string\">$1</span>"); // string
This would match an integer:code = code.replace(/(\d+)/gm, "<span class=\"number\">$1</span>");
Now my problem is that an integer within a string would get matched too. It's not a problem of highlighting but of performance, since I could usecode > span.number instead of code span.number.
Any suggestions for preventing this kind of behavior?
I also read through TextMate's Language Grammars which seem really powerful to me. However, I have no idea how I could implement that in Javascript.
Some help would really be appreciated.
I know that there are many good syntax highlighting things around, but none of them provides really good support for Objective-C.