4 ms·
Does GNU Emacs have standardized (out-of-the-box) parser generating facilities, or every package still has to hack their own?
by drdaeman 15y ago
Does GNU Emacs have standardized (out-of-the-box) parser generating facilities, or every package still has to hack their own?
- hollerith 15y agoThere's a primitive data structure called the syntax table that assists in writing fast parsers, but it is nothing like lex or yacc.
- jrockway 15y agoBut 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.)