Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upLineIndex.OffsetToLineCol translates offsets to line/col for reference. #106
Conversation
byte column, and rune column, providing value locations in the original file.
Can you clarify your use-case a bit, and provide some concrete examples? Right now I can't figure out how it differ from using It probably can be used for visualizing json files, right? But frankly right now looks like a separate project. |
About use case: Sorry. This is such a simple addition, that I assumed it would be self evident from the title. Offsets are rather obscure when troubleshooting, whereas line and column locations are useful to humans who need to locate an item in a file. Background: A friend on mine has a project that uses JSON-based interface definition files. If there is an error when parsing an interface definition, the compiler (the one he's writing, that may call upon jsonparser) needs to be able to point out to the developer the line and column location of that error. Since it seemed like generally useful and reusable functionality, I figured I'd offer it to you upstream as well. |
Ah, I see what you mean now. It is indeed can be useful and can help increase error messages as well. Give me some time to figure out whole idea :) |
jstoiko
commented
Jun 6, 2017
Thanks for this @glycerine! This is useful indeed. We had to adapt this PR a bit to make lines/cols 1-based instead of 0-based since that's what humans are mostly used to. Changes are here. |
glycerine commentedMay 28, 2017
Description: What this PR does
The LineIndex struct provides OffsetToLineCol() which
translates offsets from Get() into line,
byte column, and rune column locations.
When parsing a json file, this provides value
locations in the original file.
This code is a convenience and an
optional additional that does not
interact with the parsing functionality,
but does make the output offset more
useful when processing json files.