Comparison with Lexbor
Parsec’s aim is to be the parser Lexbor’s users would pick instead. That only works if we’re straight about where things stand, so this page goes through Lexbor module by module: what Lexbor has, what Parsec has today, and what’s planned, with the issue for each.
- The short version
- Module by module: html, dom, selectors, css and style, encoding, url, punycode, unicode, ns and tag, core, ports, engine, utils, Builds, bindings and tooling, What Lexbor doesn’t have: XPath
- Safety
- Speed
- Sources
The short version
Section titled “The short version”Lexbor is a mature C library: released since 2018, with HTML, DOM, CSS, selectors, encodings, URL and Unicode modules, used inside PHP 8.4’s Dom\HTMLDocument, selectolax, nokolexbor and more, and tested against 200 million pages under AddressSanitizer by its own account (README). Parsec’s first release was 0.1.0 in November 2026, and 0.3.0 covers HTML parsing, the tree, selectors and serialization, XPath, the encodings, URLs, CSS through the cascade, and JavaScript and XML parsers of its own. Within that it already does some things Lexbor doesn’t.
| Lexbor | Parsec today | Parsec planned | Parsec | |
|---|---|---|---|---|
| Released, packaged | Yes: 3.0.0, in vcpkg, Homebrew, Debian and others | Yes: 0.3.1 on crates.io, PyPI and npm as parsec-web, and C packages on each GitHub release (#32) |
✅ | |
| HTML parsing, fragments | Yes | Yes | ✅ | |
| Bytes in, encoding sniffed | Yes | Yes, parse_bytes, with the late-<meta> reparse |
✅ | |
| Bytes streamed, encoding sniffed as they arrive | No: lxb_engine_parse takes the whole page |
Yes, ByteParser, the same result as parse_bytes for any split (Encoding) |
✅ | |
| Chunked input | Yes | Yes, the same tree from any split (Parsing) | ✅ | |
| Parse errors | With spec ids, as pointers | With the spec’s names, byte offset, line and column (Parsing) | ✅ | |
| Source positions on nodes | No | Yes, every node and attribute, with line and column (Parsing) | ✅ | |
| Limits on hostile input | None (lexbor#340) | Time budget, size cap, depth limit | ✅ | |
| Thread-safe documents | No (lexbor#105) | Send and Sync, checked at compile time (#11) |
✅ | |
| Node lifetime | Raw pointers (lexbor#132) | Indexes that can’t dangle, and read as nothing once their node is removed; detach to move a subtree (Editing, #12) |
✅ | |
| CSS selectors | Level 4; many pseudo-classes parse and never match | Level 4, including :scope, :lang(), :dir() and the form validity pseudo-classes, and :target and :local-link given a URL; lazy queries and specificity |
The rest a static page can decide (M3) | ✅ 📋 |
| XPath | No | Yes, XPath 1.0 (XPath) | ✅ | |
| Encodings | 40, Shift_JIS wrong for lead bytes 0xE1 to 0xFB in 3.0.1 | 40, through encoding_rs, passing the WPT encoding data | ✅ | |
| URL | Yes; no WPT count published | Yes, parsec-url, a parser of its own: all 4,565 WPT cases pass, and Unicode normalization passes all of NormalizationTest |
✅ | |
| CSS Syntax parser | Yes; its own tests, no outside suite | Yes, parsec-web-css: the current draft with nesting, spans on every rule and declaration, css-parsing-tests in cargo test |
✅ | |
| Typed property values | Yes, 105 properties | Yes, all 822 in the specs, generated from w3c/webref; calc() and the other math functions, CSS Color 4 and 5, shorthands, custom properties and var(); WPT’s parsing cases in cargo test, 99% passing |
✅ | |
| Cascade, media queries, computed values | Partly: its style module attaches styles; no media queries or computed values | Yes, parsec_css::cascade: origins, layers, !important, style="", inheritance, revert, var(); media queries against an environment you give; WPT’s counts in cargo test |
✅ | |
| C API | Yes, it’s C; structs exposed, packages x86-64 only | Opaque handles and error codes; shared and static libraries, pkg-config and CMake; packages for Linux, macOS and Windows on x86-64 and ARM; XPath, source positions and parse errors | ✅ | |
| Python | Through selectolax, maintained by others; no XPath or positions | Yes: bindings/python, selectolax’s API, free-threaded too, with XPath as lxml answers it, positions and parse errors (Python); wheels on PyPI |
✅ | |
| WebAssembly | WASM build | Yes: bindings/wasm, the npm package with TypeScript types, XPath, spans and parse errors, on npm (WASM) |
✅ |
The last column uses the marks from Home: ✅ shipped and checked by cargo test, 🚧 in progress, 📋 planned. A row with both has a part of each. Thread-safe documents and node lifetime get no ✅ yet: what Parsec does today there is true of the code, but no test checks it.
Module by module
Section titled “Module by module”Lexbor’s html module has the WHATWG tokenizer and tree builder; whole-document, fragment and chunked parsing1,2; a scripting flag; the tokenizer on its own with a per-token callback; encoding sniffing with the <meta> prescan3; two serializers, one with pretty-printing and the html5lib test format4,5; parse errors with spec ids, located by pointers into the input rather than line and column6; and per-element interfaces, with <select> selectedness and <selectedcontent> added in 3.0.07.
Parsec today:
- The tokenizer and tree builder, passing the html5lib tokenizer suite and every WPT tree-construction case that doesn’t need JavaScript (Conformance).
- Whole-document and fragment parsing, with a scripting flag (Parsing).
- The tokenizer on its own, through a
Sinktrait (Tokenizer). innerHTML,outerHTML, a start tag alone, and text (Serialization).<select>selectedness and<selectedcontent>.- A time budget, a size cap, and a depth limit that flattens the tree as Chromium does (Limits and hostile input).
Chunked input that builds exactly the tree whole input does shipped in #114. Parse errors with spec names, line and column shipped in #106. Source positions on every node and attribute, which Lexbor users have asked for (lexbor#374, lexbor#388), shipped in #102. Pretty-printing, the html5lib tree format and html5lib’s serializer options shipped in #93 (Serialization).
On hostile input: Lexbor’s own issue #340 shows inputs of a few hundred kilobytes taking seconds, minutes, or all of a machine’s memory, and Lexbor offers no limit. Parsec is linear on the eight inputs in its hostile suite, deeply nested <div>s among them, has a time budget for whatever else turns up, and has a depth limit that keeps the tree as shallow as you choose.
Lexbor’s dom module has the WHATWG DOM node types, including ShadowRoot; insertion and removal both unchecked and spec-checked; cloning and importing; lookups by id, tag, class and attribute; textContent get and set; attribute get, set, remove and iterate; and mutation callbacks8,9,10. Lexbor’s roadmap marks DOM interfaces as in progress and DOM events as not started11. Nodes are raw pointers with no reference counting, an open issue since 202112.
Parsec today: an arena of nodes addressed by NodeId; parent, child and sibling links; create, insert, move, detach and remove, with removed nodes reading as nothing; set, add, rename and remove attributes; rename elements; template contents as the spec has them, or moved into the tree on request (The document tree, Editing). There’s no textContent setter, no cloning or importing between documents, no lookups other than selectors, no shadow roots, no mutation callbacks, and no events. Insertion checks for cycles but not every rule the DOM has.
Also done: documents that are Send and Sync, checked at compile time (#11); ids that know when their node was removed (#12).
selectors
Section titled “selectors”Lexbor’s selectors module matches parsed selectors with lxb_selectors_find, lxb_selectors_find_reverse and lxb_selectors_match_node, with options to include the root and stop at the first match. It has all four combinators plus the column combinator, and :has(), :is(), :where(), :not() and :nth-child(of S). A set of pseudo-classes, :scope among them, parse and never match (selectors.c); :scope support is an open pull request since December 2024 (lexbor#257), and there’s an open bug where ~ after :is() only checks the next sibling (lexbor#436).
Parsec today: Level 4 selectors, :scope included, matched as a browser would on a static page, with the full list on Selectors. :lang() and :dir() match from the markup, the form pseudo-classes (:default, :indeterminate, :valid, :invalid, :in-range, :out-of-range) from the controls’ attributes, and :target, :target-within and :local-link once you pass the page’s URL to select_with or matches_with. Lexbor parses all of these and never matches them. select_iter and select_first stop at the first match, as Lexbor’s option does, and specificity gives a selector’s specificity.
Milestone M3 is done: declared namespace prefixes, the column combinator and :nth-col() (#17), and every WPT selector case that runs without a browser passing (#19, Conformance).
On speed, Parsec’s matcher runs the 32-selector battery over 13 real pages 3.2 times as fast as Lexbor’s, ahead on every selector; Benchmarks has the table.
css and style
Section titled “css and style”Lexbor’s css module has a CSS Syntax tokenizer and parser, stylesheets and declarations, and 105 typed properties13, with three typed at-rules14. Its style module attaches stylesheets and style="" to elements. Custom properties and var()15, media queries16 and computed, inherited values17 aren’t there.
Lexbor’s syntax tests are its own, 17 files in its own format, and it publishes no pass count. Its rules and declarations carry no source positions (lexbor#374).
Parsec today: a selector parser, and parsec-web-css, CSS Syntax Level 3 as the current editor’s draft has it. Every entry point is there, nesting’s block contents included, with An+B, <urange>, @charset decoding and serialization, and a byte span on every token, rule and declaration, with lines and columns on request. cargo test runs css-parsing-tests and Romain Menke’s tokenizer tests; 293 of the 305 syntax cases pass, and the 12 that don’t are where the suite predates the draft. All 287 tokenizer cases pass, positions included. See CSS.
And parsec_css::values, which types a value for any of the 822 properties in the specs, against the grammar the spec gives it: Values 4’s units and math functions, CSS Color 4 and most of 5, shorthands split into longhands, and custom properties resolved, cycles and all, with var() substituted, which Lexbor doesn’t have. 14,758 of web-platform-tests’ 14,893 static CSS parsing cases pass, each value written in the shortest form CSSOM gives it. See CSS values.
And parsec_css::cascade, which styles a Parsec document the way a browser cascades, origins, layers, specificity, !important and style="", with @media and @supports evaluated against an environment you give, and gives every element’s computed values, inherited and all. Lexbor has none of the media query evaluation or computed values. See Cascade.
encoding
Section titled “encoding”Lexbor’s encoding module decodes and encodes the WHATWG Encoding Standard’s 40 encodings plus replacement and x-user-defined (const.h), with BOM sniffing. There’s an open bug where its UTF-8 fast path accepts overlong sequences and surrogates (lexbor#354).
Run over the web-platform-tests Shift_JIS page, Lexbor up to 3.0.1 decodes 5,240 of 7,393 characters as the standard does: it refuses lead bytes 0xE1 to 0xFB. Its single-byte decoders also drop a byte that lands on a full output buffer. Both are fixed on its master (lexbor#424, lexbor#425), not yet released.
Parsec today: parsec-web-encoding, built on encoding_rs, Firefox’s implementation. parse_bytes sniffs as the HTML Standard says (BOM, transport, prescan, fallback) and reparses once when a later <meta> disagrees with a guess; every encoding decodes and encodes, passing the WPT encoding data and the html5lib encoding/ cases. ByteParser does the same for bytes as they arrive, sniffing from the first bytes and decoding each piece into the chunked parser. Lexbor’s lxb_engine_parse sniffs and decodes too, but takes the whole page. See Encoding.
url, punycode, unicode
Section titled “url, punycode, unicode”Lexbor has a WHATWG URL parser with URLSearchParams (url.h), Punycode (punycode.h), and Unicode normalization and IDNA (unicode.h, idna.h). PHP 8.5’s Uri\WhatWg\Url is built on it (RFC). There are open conformance bugs (lexbor#438 to lexbor#442).
Parsec today: parsec-url, with URL’s getters and setters, URLSearchParams, IDNA, Punycode and NFC and NFD normalization, in a parser of its own written from the URL Standard’s current text (#26, #82). It runs WPT’s URL suite in cargo test and publishes the result: all 4,565 cases pass, and all of Unicode’s NormalizationTest. Lexbor runs 287 URL tests of its own and publishes no WPT count. On speed, it parses the links on the 13 benchmark pages 2.28 times as fast as Lexbor and 1.33 times as fast as Ada (#27). URL has the detail.
ns and tag
Section titled “ns and tag”Lexbor keeps namespace URIs and tag names as integer ids in static tables, registering unknown names as it meets them (ns, tag).
Parsec today: namespaces are the Ns and AttrNs enums, and the 124 tags the tree builder treats specially have numbers (known_tag, tag_number); other names are stored as strings (The document tree). Nothing further is planned here.
core, ports, engine, utils
Section titled “core, ports, engine, utils”Lexbor’s core has its own arenas and containers, and lets you replace its allocator, which PHP uses to enforce memory_limit (PHP RFC). ports has POSIX and Windows shims, engine is a convenience layer that decodes, parses and styles in one call, and utils has HTTP header and WARC parsers.
Parsec uses Rust’s standard library and allocator, and runs its CI on Linux, macOS and Windows. A document’s storage is a few vectors sized from the input (Architecture). There’s no allocator hook, no engine layer and no HTTP or WARC parsing, and none is planned.
Builds, bindings and tooling
Section titled “Builds, bindings and tooling”Lexbor builds with CMake, as shared or static libraries per module, with pkg-config files and a single-header amalgamation; it has a WebAssembly build through Emscripten and fuzzers for each module18,19,20. Its CI runs on Ubuntu only21, and its official binary packages are x86-64 only22. The bindings people use, selectolax, nokolexbor, lazy_html and PHP’s, are maintained by others.
Parsec today: a Rust crate; a C API, as shared and static libraries with a header cbindgen generates, pkg-config and CMake files, and a package per platform built for each release, Linux, macOS (universal) and Windows on x86-64 and ARM; a fuzz target run nightly; and CI on three operating systems, with the C test under AddressSanitizer and UndefinedBehaviorSanitizer on Linux. Moving from Lexbor maps Lexbor’s calls to Parsec’s.
The Python package (Python) runs on free-threaded Python, and the WebAssembly package (WASM) in Node and browsers. Both, and the C API, have XPath, source positions and parse errors, which no Lexbor binding has (#23).
All of it shipped with 0.1.0: the crates on crates.io, the Python wheels on PyPI, the package on npm and the C packages on the GitHub release.
What Lexbor doesn’t have: XPath
Section titled “What Lexbor doesn’t have: XPath”Lexbor has no XPath and no XML parser (lexbor#23); nokolexbor ported libxml2’s XPath to get one (nokolexbor). Parsec has one: parsec-xpath, XPath 1.0 over Parsec’s own tree, shared with Netweir. It passes libxml2’s expression tests, and a work limit stops the queries that would be quadratic. See XPath.
Safety
Section titled “Safety”Lexbor is C. Its tracker has a long run of use-after-free and null-pointer reports (search), and two CVEs in 2026 (CVE-2026-29078, CVE-2026-29079). Its maintainers fix them, and Lexbor runs fuzzers and static analysis, but the class of bug comes with the language and with pointer-based node handles (lexbor#132).
Parsec is Rust with one unsafe block, and its nodes are indexes, so a stale handle can’t touch freed memory. Thread safety and memory safety has the details, including what isn’t guaranteed yet.
Measured in one process against Lexbor 3.0.1’s own C, on 13 real pages: Parsec parses 370 MB a second to Lexbor’s 242, is ahead on every page by 1.4 to 2.7 times, and holds less memory on each. Parsec is ahead on all eight hostile inputs too (#68 closed the last two); one, 80,000 unclosed <div>s, takes Lexbor 5.2 seconds and Parsec 3 ms. On ten real stylesheets, Parsec’s CSS tokenizer runs at 389 MB a second to Lexbor’s 210, and its parser at 211 to Lexbor’s 112, ahead on every sheet. Typing every declaration’s value too, all 822 properties to Lexbor’s 105, Parsec runs at 145 to Lexbor’s 114. Benchmarks has the method and every number.
Sources
Section titled “Sources”Each numbered note in the module sections links straight to its source. Here they are in one list. Files are at Lexbor commit 145872a; the rest are issues, discussions and pages as they stood when this was written.
- html: document.h
- html: parser.h
- html: encoding.h
- html: serialize.h
- html: serialize_ext.h
- html: tokenizer/error.h
- html: CHANGELOG
- dom: node.h
- dom: element.h
- dom: document.h
- dom: Lexbor’s roadmap
- dom: lexbor#132
- css and style: property/const.h
- css and style: at_rule/const.h
- css and style: lexbor#232
- css and style: Lexbor’s roadmap
- css and style: discussion #265
- Builds, bindings and tooling: CMakeLists.txt
- Builds, bindings and tooling: wasm
- Builds, bindings and tooling: fuzzers
- Builds, bindings and tooling: cmake.yml
- Builds, bindings and tooling: README
See also
Section titled “See also”- Moving from Lexbor, for the calls side by side.
- Roadmap, for when each planned row arrives.
- Conformance, for the test counts next to Lexbor’s.