Record node end position (EndLine/EndColumn)#9
Merged
Conversation
e6bf064 to
102a24c
Compare
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>
102a24c to
0ea83a6
Compare
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Nodetracked only its start (Line/Column). This addsEndLine/EndColumn, the position just past the end of the node.For scalars and aliases the position comes from the event's
end_markat node construction. For mappings and sequences it's overwritten from the matchingMAPPING-END/SEQUENCE-ENDevent, 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
Originand oasdiffchangelog.Tests
TestNodeEndPositioncovers 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.TestNodeRoundtripclears the new fields before its deep-equality check (its expectedNodeliterals 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.