-
Notifications
You must be signed in to change notification settings - Fork 856
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
Possible positional restrictions on table definitions #446
Comments
I think probably the biggest concern I'd have with this is that it's a breaking change. It could make an otherwise valid TOML file invalid. :-( |
Ah yes good point, I forgot to mention that! I wasn't quite sure whether the 0.4 -> 1.0 transition (assuming that happens) is just a clarification as opposed to a breaking release. If no breaking changes are being made then I think the ship has sailed! |
Suggested change would make TOML more obvious and friendly to a human reader, and more consistent as well.
|
If TOML 1.0 shouldn't be breaking stuff that's already there in the wild, I suggest making this a post-1.0 item. Personally, I like this idea and getting it in 1.0 might be a good idea too. |
@pradyunsg yeah I'd be totally fine making this post-1.0, I wouldn't consider this critical at all! |
@mojombo Your thoughts on this? |
I'd very much like to keep 1.0 backwards compatible with 0.4. In the likely event that dotted keys go in, allowing for this type of looseness might actually be desirable in some cases. I think we need more experience with it before we should lock it down, so let's roll with the status quo for now and re-evaluate for later versions. |
(noting this here so that I don't fail to mention it; this issue can be reopened as a post-1.0 issue) I can imagine that TOML changing table tracking logic to be something like:
The exact same rules apply regardless of the use of dotted keys. A demo: # 'root' table is opened
key = "value"
assignment.first.key = "value" # opens assignment, assignment.first
assignment.second.key = "value" # closes assignment.first; opens assignment.second
# INVALID here: assignment.first.another = "value"
mytable.key = "value" # closes assignment.second, assignment; opens mytable
# INVALID here: assignment.second.another = "value"
# closes mytable and 'root' table |
@pradyunsg How would "unexplored" table status be used? The only application that I could imagine it being used for are undefined supertables. That is to say, if I do see the value in doing this sort of thing. Since tables can (currently) be specified in almost any order, an unexplored table status acknowledges those tables' existence without applying restrictions on their future application that an open status would suggest. |
Refers to all tables that hasn't been mentioned in the file yet.
That'll make |
@pradyunsg I don't see how. When I don't know if I've mentioned this before, but I like to think that a table's keys are always defined across a continuous range of lines (not counting parent or child tables). This logic provides for that. If it doesn't become an adopted scoping standard, then I would continue using it as a style preference. Though I think you're proposing something that is more restrictive. You want it so that you "can open a new table only if its super-table is open." This would only allow subtables to be defined within the scope of their ancestors. I would only apply that rule to inline tables. |
This is what I get for responding late at night. I meant, "this would allow for an That said, I guess we can hold off this discussion until after 1.0 is done with. :) |
I think it would be a VERY BAD idea to treat this is a "post-1.0" issue. It's a breaking change and hence it should happen as soon as possible – preferably before a new 0.x version is released, and CERTAINLY before 1.0. After 1.0 is released, more and more files might rely no such such restrictions being present, and there will be a great of deal of hesitation (and for good reasons!) about making any non-essential breaking changes. If we want to insert such restrictions (and I DO think it's a good idea), we should do so SOON. Currently dotted keys are quite new and no tagged TOML version has them, so breakage will be low. But the longer we wait, the harder it becomes. |
I think there are legitimate reasons to want to order tables in such way: you might want to prioritize access to some keys that belong to different tables by keeping them on top of the TOML file. For example, think of the following configuration file for an hypothetical application that tests a web app: [api_server]
hostname = 'api.dev.whatever.com'
[frontend_server]
hostname = 'www.dev.whatever.com'
[api_server.details]
auth_path = '.....'
ping_path = '.....'
# potentially very long list of details
[frontend_server.details]
homepage_path = '.....'
login_path = '.....'
# etc... If I want to reuse the same file to test different deployment environments by changing only the hostname of the servers, it makes sense to keep that information on top of the file, separated from the rest of the server's configurations. |
I'd already create an issue about I could not rewrite an existing config into toml without reordering |
@ChristianSi These restrictions would be backwards incompatible. The intention of TOML 1.0 being backwards compatible with 0.4 is noted in the README. This is why I labelled this as a post 1.0. Personally, it's the sort of thing where if we make this change, it'd mandate a 0.5 release (because this is the sort of change you want feedback on) and then a 1.0. I do think that if we don't do a 0.5 (which is what I'd prefer), 1.0 should mention that "hey there'll be restrictions on these in the future", possibly with some guarantee about what would stay valid. |
@pradyunsg You're right, the proposed restrictions, when applied to What we could introduce now without introducing breakage are restrictions on the order of dotted keys, if we want to have those. And my intuition again tells me that we should introduce those now if we want to have them, for the same reason as given above. So what we should decide now is whether to enforce such restrictions, say (informally): "All dotted keys that define a subtable must be placed together" – that would amount to what you have proposed above, but only for dotted keys, not for []-tables. Personally, I'm pretty undecided on whether we need such a restriction or whether we should just consider it a best practice – but I think anyone who wants it should speak out in favor of it now, since after the next tagged version is out, this too would become a breaking change and hence becomes considerably more unlikely to happen at all. |
All of the keys defining a table should be kept in one range of lines, in principle. That's the case with tables defined with header rows. That's the case with inline tables, which in nearly all cases take a single line. And that ought to be the case with dotted keys as well. This principle doesn't apply to subtables and non-root supertables, which can be defined in any order (and dotted key paths allow subtables to be defined in the middle of their parent tables' definitions). But for scalar values, arrays, and inline tables, all of their keys should be kept in one continuous range. |
Will restrictions be placed on defining subtables of tables defined using inline table values? |
My intuition is quite the opposite -- this would mean there's an inconsistency in the ability to declare using dotted keys vs tables and simple keys. |
Good point. And yet, consider this case:
That's legal with dotted keys and it will remain legal even with the restrictions you've proposed above. Indeed, it has to remain legal, since otherwise sorting all the keys in a table e.g. alphabetically would become impossible. But It's not possible using tables with simple keys. Hence I'd say we don't have to worry about consistency all that much, since true consistency is impossible anyway. |
That's indeed an interesting case and a compelling argument. In that case, let's move the discussion for dotted-keys restrictions back to #499. |
[[a]]
[b]
[[a]] |
I am not even sure what a sensible API could be implemented to allow for a TOML parser which does not keep all tables in memory. Returning a dict, object, or whatever it is called in your language of choice as most implementations do it would not work in this case as then all data would have to be kept in memory regardless. So I can think of two possible APIs:
If someone can come up with a reasonable API which show that non-negligible memory or performance gains can be achieved with such a restriction I would be happy to hear about it. Until then this is mostly a subjective discussion about what feels more "human" and "obvious". For this aspect there is already a great argument in #446 (comment) of where out-of-order table definitions are desired and advantageous. So restricting this - at the additional cost of breaking compatibility - seems like a no-go to me. |
Hello! I'm currently in the process of rewriting a TOML parser and have come
across a curious aspect of TOML. I believe that a document such as this is
valid:
That is, you can define a table across many portions of a document. There's
certainly nothing wrong with this per-se, but it means that a parser decoding
this document is forced to keep all intermediate tables in-memory or in some
side data structure. For example if you'd like to decode the table
a
fromthis document you're forced to parse
unrelated-table
and store it in memoryelsewhere to come back to later (if requested).
This is definitely a super niche concern, of course! TOML is intended for
configuration, which should never be something like gigabytes large. On the
other hand though this does make writing a parser a little bit more difficult
in some situations, and to me at least I'd subjectively find such a definition
relatively wonky.
I wonder, what would others think about adding a clause such as this to the
spec?
This does make the otherwise very simple spec somewhat more complicated, and also somewhat more arbitrarily. If this were only about parser performance I don't think I'd bother with the suggestion, but subjectively interpreting this as odd prompted me to file this report!
The text was updated successfully, but these errors were encountered: