2 ms·
But keep in mind that parsers are designed to parse well-formed documents, not to parse non-well-formed documents pretending that they are well-formed. When yo
by jrockway 15y ago
But keep in mind that parsers are designed to parse well-formed documents, not to parse non-well-formed documents pretending that they are well-formed. When you are typing in code, you are often in an invalid state that a formal grammar would reject. Hence, syntax highlighters try to guess what a piece of text is in based on as little state (previous lines of the document) as possible. Yes, you lose absolute accuracy, but the heuristics get a lot right, run extremely quickly, and are tolerant of errors.
As an example, nobody has a formal grammar that will parse Perl 5, but cperl-mode highlights (and indents, etc.) almost everything you throw at it correctly. In fact, I can't think of anything that doesn't highlight correctly!
(Also, CEDET is in core now, and it has a library for writing parsers. Never seems to work for me, though.)