-
Hi, Thank you for making this awesome crate. I am very much enjoying making parser as the combinators are very easy to follow and to work with :) I am just curious whether it is possible to get the line and column number with any of the builtin combinators? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is up to the implementer of 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 lines of the source file. This is, for the record, what Ariadne does. |
Beta Was this translation helpful? Give feedback.
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…