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

User defined error messages with key regions #124

Open
thisismiller opened this issue Jul 12, 2020 · 1 comment
Open

User defined error messages with key regions #124

thisismiller opened this issue Jul 12, 2020 · 1 comment

Comments

@thisismiller
Copy link

Suppose I have the following example.toml file:

foo = 1
bar = 2

After parsing this, I'd like to be able to print an error message like:

[error] Key `bar` is not allowed
 --> example.toml
 2 | bar = 2
   | ~~~ here

And I... can't seem to figure out how to make this happen. toml::key is an alias to std::string and not toml::string, so it loses (and the parser doesn't seem to track) the region information. I tried to get something close by using toml::get_region( toml::find( data, "bar" ) ) to get the value's region and trying to work backwards in the line from there, but base_region doesn't give me something like location::retrace nor can I construct a new location covering [line_begin(), begin()).

How can I get a source_location describing the location of a key in a table?

@ToruNiina
Copy link
Owner

Sorry, currently, it does not have the feature you said. To do that, as you pointed out, we need to define toml::key as a struct and add region information in parser. So far, I personally did not need to do that and no one craimed it. That is why it does not have the feature.

I'm now refactoring region related stuff to reduce complexity around it and once I've done it, maybe we would have full control on it. But since the region is an internal component, essentially interface might be changed without anouncement even in a minor release.

Since region of a key seems to be useful feature, so I will consider implementing it in the future release.

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

No branches or pull requests

2 participants