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

LineIndex.OffsetToLineCol translates offsets to line/col for reference. #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

glycerine
Copy link

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.

byte column, and rune column, providing value
locations in the original file.
@buger
Copy link
Owner

buger commented Jun 3, 2017

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 offset provided by jsonparser.

It probably can be used for visualizing json files, right?

But frankly right now looks like a separate project.

@glycerine
Copy link
Author

glycerine commented Jun 3, 2017

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.

@buger
Copy link
Owner

buger commented Jun 3, 2017

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
Copy link

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.

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

Successfully merging this pull request may close these issues.

None yet

3 participants