So I got thorougly roasted on my original idea. Which is actually good, compared to the deafening silence I've seen when I post other ideas. :-) Believe me, I prefer discussion on my ideas. In this case, it's helped me abort a bad approach - which is why I post my ideas.
In short, regexps are impractical in the context I had in mind. I refused to give up on this until Daniel Brooks (aka db48x) showed me "the regular expression that parses email addresses".
So scratch regexp's.
What I (very roughly) need for XML documents, as I understood db48x's explanation, is:
I was very concerned about performance, but apparently that's a non-issue.
The first and third items on the list involves probably some XML parser hacking. Of course, I've never hacked our expat before. :-) The second item is straight mathematics. The fourth I could probably just apply to the editor's contentDocument, or perhaps hack nsPlaintextEditor to support nsIEditorStylesheets.
For other types of source code (such as C++, JS, etc.), I'd need the same types of constraints as for XML, but not the same constraints. Some way to create a common set of XPIDL interfaces would really be cool, but I'm not at that stage yet. I'm still in the brainstorming-and-learning phase. (Maybe working backwards, from end-of-document to start, may mean not recalculating for offsets and new DOM nodes as iteration continues.)
Here's the transcript of our conversation: #developers @ irc.mozilla.org on syntax highlighting
As always, your feedback in helping me clarify and organize these thoughts is welcome - as long as you're informative. (I can take rudeness, but not without references to back it up.)
Posted by WeirdAl at May 6, 2006 9:49 AMI don't really know what you want to do but maybe this helps: http://dean.edwards.name/my/examples/star-light/
(From Alex: Oh, that is sweet.)
Posted by: at May 6, 2006 11:26 AMAs Axel said, you can learn from eclipse's syntax highlighting framework. That'll be much easier than trying to reinvent everything from scratch.
Their framework deals with the rehighlight-on-each-keystroke problem, allows writing custom highlighters, and there are some docs about it.
> (Maybe working backwards, from end-of-document to start, may mean not recalculating for offsets and new DOM nodes as iteration continues.)
If you're going a JS route first off (since you have first class functions), you might want to look at PatRat style parsing - here or google for other examples - you can attach the partial functions for the parse state onto the dom nodes in the presentation (these represent the set of possible forward states that have resulted in the complete parse), which should reduce the work on each update event.
Pete
Doesn't Nvu have syntax highlighting?
(From Alex: I believe they do for at least CSS, via CaScadeS v 2, but I don't think that's open-source.)
Posted by: Anonymous at May 7, 2006 1:34 AMThere is some syntax highlighting in NVU. Maybe you can start there
Posted by: at May 7, 2006 2:47 AM