Skip to content

feat(xpath): Parsec had no XPath, and neither does Lexbor - #104

Merged
jamesconwaydev merged 3 commits into
mainfrom
xpath
Nov 19, 2026
Merged

jamesconwaydev merged 3 commits into
mainfrom
xpath

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Problem

Lexbor has no XPath, which is why nokolexbor ported libxml2's (lexbor#23). Parsec had none either (#31).

Change

  • crates/parsec-xpath, synced from Netweir's new crates/netweir-xpath (refactor(xpath): XPath only ran over netweir-dom's own node wrapper netweir/netweir#341), which moved Netweir's XPath 1.0 engine onto the parser's own Document.
    • Every axis, node tests, predicates and the core function library.
    • A step from many context nodes is worked out once for the whole set: //div//div over 8,000 nested divs takes 0.2 ms, where it took 1.7 s.
    • Queries that stay quadratic stop at a work limit.
    • Expression nesting is capped, and tree walks are iterative.
  • Using it: you build an Index once per document and query through Doc::html(&doc, &index). To see inside <template>, call adopt_template_contents() first, as lxml has it. Netweir does the same.
  • scripts/sync-from-netweir.sh: syncs both shared crates with the same header and name rewriting, and --check covers both. The manifest is Parsec's own. The one dependency beyond parsec-html is stacker (MIT/Apache-2.0).
  • NOTICE, README and ROADMAP: NOTICE credits libxml2's test data, and README and ROADMAP mark M8 done.
  • Also syncs Netweir ff397ba.

Closes #31

Tests

  • libxml2's test/XPath/expr suite: 231 passed, 0 failed, 12 skipped (libxml2's own extensions: exponent literals). Plus 13 tests covering every axis, function, the hooks and the work limit.
  • cargo test --workspace: 249 test groups, 0 failed. cargo deny check, check-headers.sh and sync-from-netweir.sh --check pass, and shellcheck is clean.
  • The README example compiles and runs.

Adds crates/parsec-xpath, synced from Netweir's crates/netweir-xpath
(netweir/netweir#341), which moved Netweir's XPath 1.0 engine onto the
parser's own Document. Every axis and the core function library; steps
from many context nodes worked out once for the whole set, and a work
limit for the queries that stay quadratic. libxml2's expression tests
run in cargo test: 231 passed, 12 skipped (libxml2's own extensions).

scripts/sync-from-netweir.sh now syncs both crates, with the same
header and name rewriting, and its --check covers both. The manifest is
Parsec's own; the one dependency beyond parsec-html is stacker, which
the evaluator uses to grow its stack on deep expressions.

Also syncs Netweir ff397ba.
@jamesconwaydev
jamesconwaydev enabled auto-merge (squash) November 19, 2026 10:43
@jamesconwaydev
jamesconwaydev merged commit 1b3537a into main Nov 19, 2026
33 checks passed
@jamesconwaydev
jamesconwaydev deleted the xpath branch November 19, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XPath 1.0 over Parsec's tree

1 participant