Skip to content

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.

CrateForMay reachWith default features off
parsec-basespans, line indexes, diagnostics and limitsnothing at all, not even a crate from crates.ionothing
parsec-urlURLsno other Parsec crateno other Parsec crate
parsec-web-corethe HTML parser and its treeno other Parsec crateno other Parsec crate
parsec-jsJavaScriptparsec-baseparsec-base
parsec-xpathXPath 1.0parsec-web-coreno other Parsec crate
parsec-xmlXMLparsec-base and parsec-xpathparsec-base and parsec-xpath
parsec-web-cssCSSparsec-web-coreno other Parsec crate
parsec-web-encodingencodingsparsec-web-coreno other Parsec crate
parsec-webthe one most people installparsec-web-core, parsec-web-css, parsec-web-encoding, parsec-url and parsec-xpathparsec-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-js gives you a syntax tree without an engine. Nothing in Parsec runs code.
  • parsec-xml follows 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-url stands 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.