Conversation

glycerine

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

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

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

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

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 . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.