Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose more ways for users to manipulate Span #455

Closed
tangmi opened this issue Apr 25, 2020 · 0 comments · Fixed by #681
Closed

Expose more ways for users to manipulate Span #455

tangmi opened this issue Apr 25, 2020 · 0 comments · Fixed by #681

Comments

@tangmi
Copy link

tangmi commented Apr 25, 2020

I often find myself reaching for pest::span::Span to keep a mapping back to the parsed source file. I sometimes run into issues because Span::input is not pub.

I'd like to propose adding two methods to Span to give it more flexibility for users:

  • pub fn sub_span(&self, range: impl std::ops::RangeBounds<usize>) -> Option<Span>
    • Allows one to sub-slice a Span, returning a smaller span (or "substring") which preserves the original Span's input.
  • pub fn lines_span(&self) -> LinesSpan
    • where LinesSpan is an iterator, much like pest::span::Lines, but returns Span instead of &str.
    • Lines can be implemented as span.lines_span().map(|span| span.start_pos().line_of())

I've created a draft PR with a more concrete example of this proposal: #456.

Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants