-
Notifications
You must be signed in to change notification settings - Fork 862
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
Allow "[]" to return to global scope (for adding sibling array after a table) #456
Comments
|
Isn't empty quotes correspond to an empty key, and empty brackets disallowed? |
@guai, empty quotes correspond to an empty quoted key. Quoted things are allowed inside brackets. So i believe that this is valid today:
|
I see [] # INVALID in readme. So empty brackets already a special case, but it just disallowed and have no special meaning. I think @TedDriggs right, it is a good candidate for marking return to toplevel [a.b]
c = 1
[a]
d = 2 If we widen this rule on toplevel we'll get something like this: [b]
c = 1
[]
d = 2 |
I think this is quite intuitive and will allow to remove this special case handling in implementation code. Which is always a good thing |
Not special, this case is exactly the same:
|
If you allow
than what is your intuition for
and for
? |
Empty strings maybe? I don't insist this to be allowed cause it much less usefull. |
Consider Tom`s comment in #419:
In general:
In particular, for empty brackets:
To get "key" instead of ".key", you have to introduce a special logic.
Because there is no natural way to return to a global scope. |
Top level in toml is special in many ways. For instance, top level itself is doomed to be a table, while any value below is allowed to be an array, a table, or an immediate string/number/etc. In contrast, top-level "JSON value can be an object, array, number, string, true, false, or null". So we have a complexity trade-off here. Introduce special treatment of empty brackets for sake of making top-level less special in one particular aspect: "I can write child tables before parent's key-value pairs but not on top level". |
|
And its not |
@guai You should care about the parser's implementation because, from the spec: "TOML should be easy to parse into data structures in a wide variety of languages" But in that case, making I'm not for changing the meaning of things like |
@TheElectronWill, it also states, that it is obvious. For me, its obvious, that applying the same rule everywhere is simpler and better. |
100% agree; the original proposal deliberately was limited to the "return-to-global" behavior for that reason. |
I'm all for improving the representation for top-level arrays... the repeating I don't think that |
@fspm, the proposition is not "return to the top level namespace and treat the next key as an array instead" but "return to toplevel and treat the next key-value as immediate primitive in toplevel map". We can do it for maps at levels > 0. For levels > 0 we can first describe child maps/arrays and then immediate primitives, but not on top level, where we must declare primitives first right now. |
I'm not a fan of the "return to global" idea at all. A nice property of TOML is that it's very obvious which table a key belongs to based on where it's defined. If you want global keys, then you know to always look at the top of the file. Things like |
@BurntSushi, but that prevent expressing some domain-specific ordering. Like important things on top, less important - lower. And most important things not required to be toplevel |
@guai Then don't use the global namespace for non-table keys. |
@BurntSushi, its acceptable when I design the data structure from scratch, but not when I need to express somethins existing in toml |
Yes, there are the trade offs. The downside of not being able to arbitrarily inject things into the global scope is that you can't order the non-table keys in the global scope in an arbitrary order. I think we can live with that downside. I think the cost of not being able to specify an arbitrary order is quite a bit smaller than the cost of making removing a very simple property of TOML: it's always obvious where a key is defined. |
@BurntSushi, it makes toml less usefull for me. I'm trying to migrate xml configuration files of an existing |
@BurntSushi, what trade-off are you talking about? I see no gains here, only losses: |
I don't understand. Please use examples. |
As In the example given by @TedDriggs, a "parameters" table makes sense for me: [appliance]
# ...
[parameters]
rules = ... Even if it's less straightforward to map this to the data structure you mentioned, it shouldn't be impossible with a good library. |
@TheElectronWill but in that case we'll have to prefix every path all over the toml document |
BTW, why "[] isn't obvious"? |
@BurntSushi, when I was talking about less symmetry and more exceptions I meant this examples [a.b]
c = 1
[a]
d = 2 [b]
c = 1
[]
d = 2 I can add prefix to nest some section into another one, and I can remove this prefix. Except when its on top level. In this case I need to reorder/reorganize/refactor, change code etc. |
And if you guys afraid that users won't get it, then we can use comments [a.b]
c=1
[] # toplevel primitive start here
foo = "bar" I think in most cases users don't write toml, they change existing one or copy-paste it and then just change values they know the meaning of |
Toml is less expressive than json in many more ways. Toml imposes restrictions on type of items in array. Toml has no null. Things like nested arrays of tables are hard to read. |
TOML isn't a replacement for JSON or YAML. It's a configuration file format. |
And I could not just convert my existing xml configuration files into toml without extra efford |
I think the biggest problem here is that this proposal would violate the "write once" aspect of tables. The root level is a table. It can be written to at the beginning of each TOML document. If we also allow writing to it via |
@mojombo, I propose to use the same rules on any level. |
So, if a It also contradicts the original proposal:
But the original proposal won't fly either, for the reason stated by @mojombo: It would make the top-level the only one whose entries could be spread over two places instead of being all grouped together. This issue has been discussed long enough and it's clearly going nowhere, I think. Time to close it? |
@ChristianSi, then why is it ok to get "table re-opened" error on levels > 0? |
As @guai pointed out, you already get errors when you reopen a table, which could be defined far away from the user edit. The meaning of Allowing |
Well, if you add So defining a |
@ChristianSi, this have nothing in common with principle of least surprise. Principle of least surprise means that if user can be already familiar with something with this syntax, we should not change its meaning. |
The experience of reading most documents ever written: you don't get to "re-open" a section after a new section has started. No one expects to read something like this: An article about configuration filesIntroductionblah blah blah... Methods and Datablah blah blah .. Introductioneh? |
@sgarciac, I never suggested to make sections reopenable, I suggested to make toplevel movable. |
You don't have to add a prefix to every path. Just put your "uncategorized crap" into a table called "General", "Unsorted", "Crap", or whatever, and leave everything else unchanged. You don't even have to change any of your data structures to do so, it's just a tiny change in the way they are mapped to and from TOML. And should you answer "I cannot do that", I will reply with: "Of course you can!" |
@ChristianSi, good idea, but it is still a workaround |
To summarize I would say the different standpoints are that:
I understand that people would like to do as little changes as possible to their codebase to support sth. So why is this still open? |
Indeed. This can be closed. |
Just another task about this to appear. This is fourth one already, I believe. |
@guai Sorry but I can't understand what you have typed. |
@pradyunsg, I mean once this task will be closed another one will apper about that same thing. Because that is what some people (me included) see as most obvious. |
If we had a wiki here, we could add a FAQ section. But actually that is a general problem with suggestions, they tend to be redundant. |
@guai Oh, okay. That makes sense. I guess it would be a good idea to link to the existing ones from here? |
@TedDriggs @guai Thanks for your impassioned thoughts on this matter, these discussions are always helpful in thinking through these edge cases. For closure on this, I think the proposal is too non-obvious to be included. In TOML, root keys come first, and thus carry some significance because of that. In addition, TOML need not be a perfect replacement for existing config formats. I know it's inconvenient to have to rework some code to incorporate a switch to TOML, but maybe it could be a good opportunity to rethink the config layout. Is it the best idea to have a bunch of "crap" settings uncategorized? Could they fit elsewhere? At the very least, you can communicate their non-importance by bundling them into a Regarding questions that keep coming up, I'm 100% ok with that. If people constantly bring things up, it means there is an opportunity to clarify the spec or reconsider past decisions based on new evidence. |
I'm trying to model this Rust struct in TOML:
When writing it out in TOML, I believe the natural way to read/write it would be:
That would look something like...
One approach I thought of that could address this would be allowing
[]
to appear once to return to global scope after entering a table. It would be invalid to use[]
if the document started with key-value pairs, avoiding the splitting of a table definition.This might be too narrow a case, but I think the pattern of 'metadata + a list' seems likely to occur somewhat frequently. This may also dovetail with #309; shorter syntax for arrays-of-tables would make me less concerned about teaching users the
[[rules]]
construct.The text was updated successfully, but these errors were encountered: