Skip to content

Record node end position (EndLine/EndColumn)#9

Merged
reuvenharrison merged 2 commits into
v3from
feat/node-end-position
Jun 25, 2026
Merged

Record node end position (EndLine/EndColumn)#9
reuvenharrison merged 2 commits into
v3from
feat/node-end-position

Conversation

@reuvenharrison

Copy link
Copy Markdown
Collaborator

What

Node tracked only its start (Line/Column). This adds EndLine/EndColumn, the position just past the end of the node.

For scalars and aliases the position comes from the event's end_mark at node construction. For mappings and sequences it's overwritten from the matching MAPPING-END/SEQUENCE-END event, so the span covers the whole block, not just its first line.

Why

A consumer can now extract an entire collection from its node, e.g. the whole OpenAPI operation block for an endpoint. This is the foundation for surfacing an endpoint's location (start and end) up the stack in kin-openapi Origin and oasdiff changelog.

Tests

  • TestNodeEndPosition covers a single-line scalar span and a nested operation block, asserting the block ends at its last content line and does not bleed into the next sibling.
  • TestNodeRoundtrip clears the new fields before its deep-equality check (its expected Node literals predate them; the end positions are verified by the new test instead). All existing tests pass unchanged otherwise.

Compatibility

Purely additive: two new fields, ignored on encode (like Line/Column). No change to the __origin__ wire format in this PR; that follows alongside the kin-openapi consumer.

@reuvenharrison reuvenharrison force-pushed the feat/node-end-position branch 5 times, most recently from e6bf064 to 102a24c Compare June 24, 2026 15:28
Node tracked only its start (Line/Column). Add EndLine/EndColumn,
populated from the parser event's end_mark: for scalars/aliases at
node construction, and for mappings/sequences from the matching
MAPPING-END/SEQUENCE-END event so the span covers the whole block,
not just its first line.

This lets a consumer extract an entire collection (e.g. a whole
OpenAPI operation block) from its node, which the change-origin work
upstream builds on.

TestNodeEndPosition covers scalar and nested-block spans, including
that a block does not bleed into its sibling. TestNodeRoundtrip clears
the new fields before its deep-equality check, since its expected
literals predate them (end positions are covered by the new test).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@reuvenharrison reuvenharrison force-pushed the feat/node-end-position branch from 102a24c to 0ea83a6 Compare June 24, 2026 15:31
…ion tests

Two end-position bugs surfaced while widening test coverage for Node
EndLine/EndColumn:

- Block (literal/folded) scalars overshot their end to the start of the
  following line, because the scanner's end_mark advances past the trailing
  line break. The block-scalar scanner now captures the position just past the
  last content character (before the break) and uses it as the token end, so a
  multi-line value (e.g. description: |) no longer bleeds its span, and the
  overshoot no longer propagates up to the enclosing mapping. Fixed at the
  scanner so it holds for both string and reader input.

- Non-empty flow collections ended just past their last child, excluding the
  closing }/], while empty flow collections (no child) ended just past the
  delimiter. mapping()/sequence() now use the END-event mark for flow style so
  the span covers the whole {...}/[...] consistently; block style still borrows
  the last child's end (its END token sits at the dedent and would overshoot).

Adds targeted end-position tests for block scalars (incl. strip chomping and
block-scalar-at-EOF), trailing/standalone comments, multi-document streams,
merge keys, flow collections, quoted scalars, block sequences of mappings, and
deep-nesting propagation. Full suite and go vet pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@reuvenharrison reuvenharrison merged commit 67665f7 into v3 Jun 25, 2026
2 of 15 checks passed
@reuvenharrison reuvenharrison deleted the feat/node-end-position branch June 25, 2026 16:22
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.

1 participant