-
Notifications
You must be signed in to change notification settings - Fork 858
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
Notation for Relative Tables #229
Comments
Tables are not using balanced delimiters now, so I am not quite in favor of this proposed notation. I would propose utilizing the [servers.alpha]
ip = "192.168.0.1"
[servers.beta.ports]
blocked = [80, 8080] can be written as: [servers]
-[alpha]
ip = "192.168.0.1"
-[beta]
--[ports]
blocked = [80, 8080] |
I'm not sure why this is an obvious thing to have. I think we discussed this a long time ago and rejected it. Let's just keep things simple and have |
Or maybe the [servers]
|[beta]
||[ports]
blocked = [80, 8080] |
@BurntSushi, that's a fine decision. FWIW, I am quite fond of Python's ConfigObj's approach. It has "relative tables", using extra pairs of [servers]
[[beta]]
[[[ports]]]
blocked = [80, 8080] But this syntax cannot be adopted by TOML even if relative tables are to be implemented, as |
Another option, which I don't feel all that strongly about, is to allow @BurntSushi it's not really just a little more typing; it makes nesting under things like |
@wycats, [profiles.test]
[.dependencies]
[..rustcheck]
git = "..."
[..spec-rs]
git= "..." Nice. |
[foo]
[.bar]
[.baz] The |
Hmm, do you mean But I do like @wycats idea to expand names starting with a dot relative to whatever the last fully written table name was (if I got it right). So:
That could come handy in some cases. |
That said, when looking at it, it doesn't look as ridiculous as I feared. |
I think he's saying that this: [profiles.test]
[.dependencies]
[..rustcheck]
git = "..."
[..spec-rs]
git= "..." Would expand to: [profiles.test]
[profiles.test.dependencies]
[profiles.test.dependencies.rustcheck]
git = "..."
[profiles.test.dependencies.spec-rs]
git= "..." |
It kind of looks like a little ASCII tree. You add FWIW: The verbosity is definitely blocking us from using nesting in Cargo for this kind of thing, but as I said above, that may be a good thing. |
No, dots represents nesting levels. So it expends to Sorry I failed to clearly express my idea. |
@wycats, yes that's the idea. Thanks. I am on my phone and type slowly. |
Ah, so we could say:
Yeah, that doesn't look bad... |
Doesn't seem like a huge win to me. Is it worth it? Besides, it isn't truly relative either. It doesn't allow copy-pasting one chunk of toml into another, like one can do in json or xml. E.g. [servers]
[.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[..ports]
in = 215
[.beta]
ip = "10.0.0.2"
dc = "eqdc10"
[..ports]
in = 215
out = 216 vs [servers]
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.alpha.ports]
in = 215
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
[servers.beta.ports]
in = 215
out = 216 |
I think the biggest usefulness of it would be copying structure from XML files, where you have something like:
which if converted without changing structure would become:
Of course that being said, this specification shouldn't cater to converting XML documents to this format, as the above should obviously just be:
I agree with the earlier sentiment that this would make nesting easier, but that isn't necessarily a good thing. |
If we really want to go down this path, I suggest we expand #235 to allow multi-line inline tables instead. This would allow code somewhat similar to JSON: [logConfig]
file = {
value="log.txt"
}
level = {
value="5"
} Or even deeper nested: [configs]
logConfig = {
file = {
value="log.txt"
},
level = {
value="5"
}
} |
@johanfange Okay and now that TOML supports JSON, what should the M stand for? |
@mirhagk You tell me. TOML does seem to suffer from some feature creep. Either way, with #235, we already support this almost-JSON. Well, as long as you keep it to one line. One option is to add more syntax to support this feature as in the initial post. However, if we get #235, it would clearly be simpler to just relax the one-line restriction for inline tables. |
Yes that is true. By allowing #235 we've already made it so regular expressions can't be used. Its not much harder to allow them to be multi line after that. |
But as it stands it simply discourages nice formatting with json. I'd prefer to see it instead disallow nesting. That'd prevent json from working within it, and also make it easier to parse as well. |
True, but it is relevant here as an alternative. I am personally okay with the |
I personally really dislike this entire idea. I don't think TOML should have relative paths. A config is simpler and easier to understand without them because every table name can be resolved completely just by looking at it. With relative paths, you need to examine the tree of tables to resolve the full key. I understand that there is some value to reducing the length of long key names, but I also think there is even greater value in 1) mitigating against deep levels of nesting and 2) knowing the full table name just by looking at it. |
I agree with you, @BurntSushi. TOML will most often be "write once, read many" and as such should be optimized for clarity in reading, which is aided by fully qualified table names. |
Besides which with the aforementioned feature creep that TOML has, I feel like a feature like this can wait until we get a lot more real world usage before its added. Its easier to add it later than remove it. |
I agree with @BurntSushi and @mojombo, for the record. |
@BurntSushi, @wycats Thanks for your thoughts. Closing this for now, as nothing here aligns with the Obviousness mantra of TOML. |
Seems like one of those obvious things. Exact notation to be determined, but I'll throw out the one that comes to my mind first:
The text was updated successfully, but these errors were encountered: