Skip to content

Conversation

natecook1000
Copy link
Member

This change adds three ParserSpan.extracting APIs that yield new ParserSpan instances that have their internal span boundaries shrunk to fit, instead of just insetting the boundaries at the ParserSpan level. An extracted span can be passed off to a parsing function without worry that an absolute seek will go beyond the visible boundaries of the span.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've run Scripts/format.sh to correctly format my change
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

This change adds three `ParserSpan.extracting` APIs that yield new
`ParserSpan` instances that have their internal span boundaries shrunk
to fit, instead of just insetting the boundaries at the `ParserSpan`
level. An extracted span can be passed off to a parsing function
without worry that an absolute seek will go beyond the visible
boundaries of the span.
@natecook1000 natecook1000 marked this pull request as ready for review September 10, 2025 18:54
@natecook1000
Copy link
Member Author

natecook1000 commented Sep 10, 2025

Re: naming, I went with extract(...) here (instead of the extracting name that the span types use) because these new methods mutate the underlying ParserSpan. The extract methods are intended as counterparts to sliceSpan and sliceRange, so they use the same part of speech.

Copy link
Member

@numist numist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  /// An _extracted_ parser span doesn't retain information about the bounds of
  /// the original span…

Love it. This interface is going to be a big improvement for container formats (or formats that use framing), where child parsers should be restricted to their own range.

@natecook1000 natecook1000 merged commit 9a61d04 into main Sep 17, 2025
16 checks passed
@natecook1000 natecook1000 deleted the extracting branch September 17, 2025 00:16
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.

2 participants