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

Get line containing the point of an span. #53

Open
kaj opened this issue Feb 21, 2020 · 1 comment
Open

Get line containing the point of an span. #53

kaj opened this issue Feb 21, 2020 · 1 comment

Comments

@kaj
Copy link

kaj commented Feb 21, 2020

A method to get the textual line containing the (start of) a LocatedSpan would be nice.

I want to present parse errors in a user-friendly way, like this:

  ,
2 |     div.selector { property: } /* No value */
  |                              ^ Parse error: Expected value.
  '

As LocatedSpan has methods get_column, get_utf8_column and location_line to get line-relative information, and fragment to get the source text from the span, I think it would be reasonable to also provide a method line_fragment (or some better name) to get the line text.

I currently do this with the following unsafe and abstraction-level-breaking code, adapted from the private get_columns_and_bytes_before method.

https://github.com/kaj/rsass/blob/580121abdf1367384109afaa0c18b88b99e4c959/src/error.rs#L125-L143

kaj added a commit to kaj/nom_locate that referenced this issue Oct 16, 2020
Add a function to get the full input line containing the (start point
of the) LocatedSpan.

As suggested in fflorent#53.
kaj added a commit to kaj/nom_locate that referenced this issue Oct 16, 2020
Add a function to get the full input line containing the (start point
of the) LocatedSpan.

As suggested in fflorent#53.
progval pushed a commit that referenced this issue Oct 18, 2020
* Implement LocatedSpan::get_line().

Add a function to get the full input line containing the (start point
of the) LocatedSpan.

As suggested in #53.

* Add some tests.

* Remove bogus comment.

* No need for get_line() to return Option.

* The test that uses `format!` requires std.

* Some rustfmt.

* Refactor two similar unsafe blocks to one.

* Add some disclaimer comments / docs.

* Rename get_line to get_line_beginning.

* Add line_begining_may_ot_be_entire_len test.

This test documents how `get_line_beginning()` differs from a
hypotetical `get_line()` method.
@pitaj
Copy link
Contributor

pitaj commented Nov 21, 2020

This is implemented and should be closed, unless we also want to provide some way to get the full line given the original input span.

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

No branches or pull requests

3 participants