2 ms·
Right exactly, in fact I call the library "lazylex" because it only does the minimum to find the <> structure. If you want to recognize more, then you invoke a
by chubot 6y ago
Right exactly, in fact I call the library "lazylex" because it only does the minimum to find the <> structure.
If you want to recognize more, then you invoke a attribute "name=value" lexer on the tag, but usually you don't. This makes it quite fast (and speed is useful because most doc toolchains are slow).
The lexing is the "generic" part and parsing is specific to the task at hand.
In the case of making an HTML table of contents, you literally just find <h1>, <h2> with regexes, and don't do all this DOM nonsense. It's easier to write than the SAX style with an explicit stack.
So yes the point is that parsing HTML is trivial for most purposes: use the call stack. It helps if your language has exceptions to indicate errors.