Separate trees, shared plumbing
HTML and XML look alike and parse nothing alike. So each language in Parsec keeps its own grammar, its own tree and its own way of handling mistakes, and they share only the parts that are the same everywhere.
The crates
Each crate may reach only the Parsec crates in its row. That isn't a convention: check-crate-deps.sh runs cargo tree on every crate in CI, once with all its features and once with its defaults off, and fails the build on any edge its row doesn't allow. This table is read from that script when the page is built.
| Crate | For | May reach | With default features off |
|---|---|---|---|
parsec-base | spans, line indexes, diagnostics and limits | nothing at all, not even a crate from crates.io | nothing |
parsec-url | URLs | no other Parsec crate | no other Parsec crate |
parsec-web-core | the HTML parser and its tree | no other Parsec crate | no other Parsec crate |
parsec-js | JavaScript | parsec-base | parsec-base |
parsec-xpath | XPath 1.0 | parsec-web-core | no other Parsec crate |
parsec-xml | XML | parsec-base and parsec-xpath | parsec-base and parsec-xpath |
parsec-web-css | CSS | parsec-web-core | no other Parsec crate |
parsec-web-encoding | encodings | parsec-web-core | no other Parsec crate |
parsec-web | the one most people install | parsec-web-core, parsec-web-css, parsec-web-encoding, parsec-url and parsec-xpath | parsec-web-core, parsec-web-css, parsec-web-encoding, parsec-url and parsec-xpath |
The two columns differ where a dependency sits behind a feature. parsec-web-css reaches the HTML tree only for the cascade, which matches selectors against a document; parsec-web-encoding reaches it only to parse what it decodes; and parsec-xpath only for its HTML implementation. Turn their defaults off and you get CSS syntax and values, sniffing and decoding, or XPath over a tree of your own, without compiling an HTML tokenizer.
What that buys you
- Parse only HTML and you never compile the JavaScript parser.
parsec-jsgives you a syntax tree without an engine. Nothing in Parsec runs code.parsec-xmlfollows XML's rules all the way: a well-formedness error is fatal, a name is its namespace and local part, and entity expansion is capped. None of HTML's error recovery leaks in.parsec-urlstands alone.
Why not one tree for everything
I considered one shared representation for every language and turned it down. A node general enough for HTML elements, CSS rules, JavaScript expressions and XML elements is specific enough for none of them, and every parser would pay for the others' fields. Separate trees let each one be laid out for how it's used: the HTML tree for selector matching, the JavaScript tree for walking.
What's shared is what's identical everywhere and tedious to get right twice: turning a byte offset into a line and column, counting UTF-16 units for the bindings, a diagnostic with a code and a span, and the depth and step limits that keep hostile input linear. That's parsec-base, and it depends on nothing.
Where the code is written
Every crate is written in the Parsec repository. The HTML parser started life inside Netweir and was copied across until November 2026; now Netweir depends on the released crates like anyone else, and a parser fix lands in Parsec first.
The docs' Architecture page follows a parse from the call to the finished tree, file by file, and shows how a document is laid out in memory.