3 ms·
> Syntax highlighting is a complex problem, because it needs to be fast enough, and the more token types you have, the longer it takes. Yes, it scales with the
by awalton 12y ago
> Syntax highlighting is a complex problem, because it needs to be fast enough, and the more token types you have, the longer it takes.
Yes, it scales with the number of tokens. Why wouldn't it? This isn't a problem. It's 2015, we have ~4GHz umptheenth core computers, we can do this in real-time.
> Each time you type a character, you have to parse the code (clang is used here), select the according color, and draw the text
You seem to have no idea what is actually happening here. You don't need to rerun the whole parsing step at each character if your tool understands the language, only when you hit a token that changes the parser's state (so when you enter a paren, you're no longer typing an identifier, so now we need to reparse.) There are a huge number of ways to optimize this step from there, but I don't think anyone is actually employing any of them yet, either because they're too complicated or computers are just so fast we don't care (like maintaining a document AST and simply updating the nodes as they change around so you can get away with vastly simpler "reparses").
The actual layout and rendering of text is then done - each OS has their own text layout engine, and there's several open source ones (e.g. Mozilla and Blink/Webkit have their own text layout kits, Pango does it on GNOME, etc). Color highlighting is a part of text rendering, which happens next, which also every platform has it's own solution for (like, e.g. Cairo, an image compositing library, which uses FreeType, the Windows or Mac font rendering systems for rendering glyphs).
What should be colorized/bolded/treated as different is usually tracked by a set of span data structures (e.g. line number X, character Y to character Z should have this set of attributes applied).
> My guess is that sublime text completely shortcuts this problem by using webkit to draw its own text surface.
Sublime Text implements its own editor widget. Here is the author noting some bits about it: https://news.ycombinator.com/item?id=2822114 https://news.ycombinator.com/item?id=2822114 . Shipping Webkit is not an easy task, nor is it a small one in disk footprint. I'm not sure how you randomly came to the conclusion Webkit had to be involved.
The rest of your post seems as if it was generated by some kind of buzzword Markov Chain, so I'm ignoring it.
- jokoon 12y agookay