Repository · Wiki · Benchmarks · Roadmap · Discussions
Parsec is the parsing foundation for the web, in memory-safe Rust: HTML, CSS, JavaScript and XML, one crate at a time, so you build on exactly the parsers you need. It started as an HTML parser, because Netweir needed one faster than Lexbor, and the HTML parser is still the part that's been in use longest. CSS with the cascade, XPath, and the WHATWG Encoding and URL standards sit beside it. A JavaScript parser of our own comes next, then XML, each with its own tree over shared plumbing.
If you parse HTML for a living, you've probably met Lexbor too, directly or through selectolax, PHP's Dom\HTMLDocument, nokolexbor or lazy_html. It's fast, and it follows the spec. What people keep asking it for is the rest: where a node came from in the source, XPath, selectors like :lang() that it parses and never matches, documents you can share across threads, and a node you still hold after it's removed that doesn't read freed memory. Parsec's HTML parser is that list.
use parsec::css::SelectorList;
let doc = parsec::parse("<ul><li class=hit>one<li>two</ul>", false);
let hits = SelectorList::parse("li.hit").unwrap().select(&doc, doc.root());
assert_eq!(doc.text(hits[0]), "one");And it's quicker at the job. On 13 real pages, 24 MB of Wikipedia, MDN, GitHub, the BBC, the HTML spec and others, Parsec parses 370 MB a second to Lexbor's 242, ahead on every page. Throw a crawl's worst at it, 1,000 pages of broken fragments, re-encoded pages and 10 to 30 MB giants, and it gets through them in 1.02 seconds to Lexbor's 1.94, using just over half its peak memory, and nothing crashed. The Benchmarks page has every number and how to run them yourself.
- parsec: the parser, CSS selectors Level 4, XPath 1.0, declarative shadow DOM, the WHATWG Encoding and URL standards, and CSS stylesheets with the cascade. It passes all 7,042 html5lib tokenizer tests and every web-platform-tests tree-construction case that runs without JavaScript.
- From Python, JavaScript or C: bindings for each live in the same repository, free-threaded Python and WebAssembly included.
- Install it: 0.2.0 is out.
cargo add parsec-html,pip install parsec-htmlornpm install parsec-html, and the C library is on the release. - Road to the parsing platform: JavaScript, XML and the rest, milestone by milestone. Pick any open item.
- What's done and what's next: the line between the two is kept sharp.
Questions and ideas go to Discussions. Issues labelled good first issue and help wanted are a good place to start, and CONTRIBUTING.md covers the rest. Found a security problem? SECURITY.md says how to report it privately.