2 ms·
"Syntax" highlighting is normally done with lexical analysis, not with a parser, and is far, far faster than regex-based syntax highlighting, because it can use
by barrkel 13y ago
"Syntax" highlighting is normally done with lexical analysis, not with a parser, and is far, far faster than regex-based syntax highlighting, because it can use a simple tuned state machine, and it only needs to redraw text attributes until it gets to text in the same state (from the state machine) it's trying to repaint. Turbo Pascal was doing syntax highlighting in DOS 20 years ago.
Parsers have been used to do semantic highlighting of symbols, e.g. paint identifiers in different colors depending on whether they're interfaces or classes, etc. But the big win for parsing isn't highlighting, it's completion. You can't do super useful completion without a fairly rich parse tree, and not just for the current file, but also for all the libraries.