Skip to content

feat: nodes didn't know where in the source they came from - #102

Merged
jamesconwaydev merged 1 commit into
mainfrom
sync-spans
Nov 19, 2026
Merged

jamesconwaydev merged 1 commit into
mainfrom
sync-spans

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Problem

Lexbor's nodes don't know where they came from (lexbor#374, lexbor#388), and neither did Parsec's (#8). Editors, linters and anything that reports back to a person need it.

Change

  • Syncs Netweir 04cc3bc (feat(html): nodes didn't know where in the source they came from netweir/netweir#329). Spans are opt-in, Options { spans: true, .. }:
    • Document::span gives an element's start tag, or the whole of a text, comment, doctype or PI.
    • end_span gives the end tag, and attr_span an attribute's name through its value.
    • Offsets are into the original input, with CRLFs and a byte order mark mapped back. line_col turns one into a 1-based line and column.
    • Nodes the parser invents have none.
  • .gitattributes: keeps crates/parsec/tests/tree-construction/*.dat byte for byte on Windows. A Windows checkout had turned their LFs into CRLFs, which the new span test caught.
  • parsec-capi, bindings/python, bindings/wasm: build Options with ..Options::default(), since it gained a field.
  • README and ROADMAP mark Source positions on every node and attribute #8 done.

Closes #8

Tests

  • cargo test --workspace: 231 test groups, 0 failed. The new tests/spans.rs checks 13,626 spans over every tree-construction case, plus hand-written ones with CRLF, entities, foster parenting and unquoted attributes.
  • Tokenizer 7,045 and tree construction 3,898 passed, 0 failed.
  • clippy -D warnings is clean on the workspace, bindings/python and bindings/wasm (wasm32).

Syncs Netweir 04cc3bc (netweir/netweir#329). With Options { spans:
true, .. }, the parser records each node's and attribute's byte range in
the input as passed (CRLFs and a byte order mark mapped back):
Document::span, end_span, attr_span, and line_col for a line and column.
Off by default, so a plain parse costs what it did.

Options gained a field, so the C API and both bindings fill the rest
with Options::default(). .gitattributes keeps the tree-construction .dat
files' LFs on a Windows checkout, where they had been turned into CRLFs.
@jamesconwaydev
jamesconwaydev enabled auto-merge (squash) November 19, 2026 09:58
@jamesconwaydev
jamesconwaydev merged commit 255e9a5 into main Nov 19, 2026
39 checks passed
@jamesconwaydev
jamesconwaydev deleted the sync-spans branch November 19, 2026 10:03
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.

Source positions on every node and attribute

1 participant