-
Notifications
You must be signed in to change notification settings - Fork 861
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
Reduce verbosity of sub tables #413
Comments
I think that's a good idea :) |
Interesting, but that might lead to:
# something before...
[..key]
value = 1 you need to look above (possibly far away) to search for [.a] # invalid without top level table above and [a]
[..c] # invalid without intermediate table name Note that TOML is designed for easy parsing than functionality. I guess the above explains the downvotes. (Note: I myself do not fully agree with the second; I just provide such a point.) |
While I can see the convenience for writing TOML files, I don't believe it's worth the extra parser complexity. And I realize that I say this as the person who opened #409, but there's a difference. Hex and octal have some use cases where they are essential, not just nice-to-have (Unix file permissions, for example), and the added parser complexity is small. This suggestion, though, adds a lot of complexity for (IMHO) very little gain, and I don't believe that the trade-off is worth it in this case. |
I'm currently evaluating using TOML for an ansible-like DSL which defines tasks like so (simplified): [defaults]
user = "admin"
[[tasks]]
[[tasks.clone_repo]]
desc = "Clone repo from github"
type = "git"
[task.clone_repo.args]
source = "https://github.com..."
dest = "$HOME/repo" This is a tough sell due to verbosity and it's the second time I encounter the use case, extremely quickly after picking up TOML which makes me think it's a pretty core issue to the language. Neither JSON nor YAML have this issue due to syntactic scoping. Another issue caused by the verbosity is the human error element. I was going to write a paragraph about this, until I noticed upon remarshalling that the last header is missing an What this could look like: [defaults]
user = "admin"
[[tasks]] # Would that work?
[[.clone_repo]]
desc = "Clone repo from github"
type = "git"
[..args]
source = "https://github.com..."
dest = "$HOME/repo" Much less repetitive and removes most potential human errors. To address @FranklinYu's concerns regarding mental overhead on read: As for parser complexity, erroring properly should not be overly complicated here. What this adds to parsing is tracking the last-defined value at each level. I will expand on your example with another potential error though: [a]
[.aa] # a.aa
[..aaa] # a.aa.aaa
[b]
[..baa] # !!! could become a.aa.baa if not clearly specified Conclusion: I'm strong +1 on inclusion of such syntax. |
I've never seen a repetition-reducing syntax of this sort that I think is obvious enough to be included in TOML, including all the proposals seen here. What might solve some of these problems, though, is dotted keys as seen in #499. It's an obvious solution that would allow a reduction in repetition for certain cases. |
Right now since sub tables require repeating the keys of any of it's parent tables, any situation where you want multiple sub tables, particularly nested, tends to end up being very verbose, looking something like:
This I believe makes TOML uglier than it needs to be for situations where you end up with multiple nested sub tables. The problem primarily comes from the repeated key names of the parent tables, so what if TOML just allowed you to omit that? So essentially the above would become:
The rule would be pretty simple, the
.
make it relative to the previously defined table with one fewer.
.While whitespace is still optional, you can make it more immediately obvious what is going on by applying some whitespace here to turn the above into something like:
The text was updated successfully, but these errors were encountered: