Replies: 2 comments
-
To convert multiple |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, there are two problems
Glad you found that crate and it works well for you. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! I've read the
winnow
introduction post, which talks about the design ofLocated
inwinnow
compared tonom-locate
. However, I'm not sure how exactly to get line/column numbers from spans.The
line_numbers
crate can convert fromusize
offsets to line numbers (although it doesn't help with column numbers, even byte-based ones).I would assume this is a fairly common use-case, so I'm not sure if there's a suggested workflow here.
For my specific use-case, I'm parsing through a file and extracting some spans (commands to evaluate like doctests). Then, my program will evaluate those commands and report the results to the user along with where the span was defined (file, line number, ideally column number).
Using
Parser::with_span
I can extractusize
offsets and later convert them to line numbers, but this strikes me as potentially inefficient: eachusize
-to-line-number conversion requires an O(n) iteration through the codepoints in the file contents, so it would be nice to be able to at least convert them all at once, and perhaps ideally to have them tracked as parsing happens. However, I recall that the overhead from some of that tracking hurt performance substantially.In the meantime, I can implement a naïve approach with
line_numbers
, but I'm curious if there's a better way to do this.Beta Was this translation helpful? Give feedback.
All reactions