Skip to content

How to get the line and column number? #117

Answered by zesterer
numToStr asked this question in Q&A
Discussion options

You must be logged in to vote

It is up to the implementer of Span to provide these things. Chumsky actually doesn't care about what constitutes a span, provided it conforms to the API of the trait. Most people use character or byte offset within each file but, truthfully, chumsky is entirely ambivalent and you could just as well have spans use lines and columns (although I wouldn't recommend it).

The best course of action is probably to keep things as byte offsets where possible (they're easier to work with and don't require you to carry a reference to the source code around to manipulate them), only calculating line/column when you really need to (such as when generating an error diagnostic) by counting through the l…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@numToStr
Comment options

Answer selected by numToStr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants