8000 Clarify: no dotted keys or subtables into inline tables by eksortso · Pull Request #647 · toml-lang/toml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Clarify: no dotted keys or subtables into inline tables #647

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

Closed
wants to merge 2 commits into from
Closed

Clarify: no dotted keys or subtables into inline tables #647

wants to merge 2 commits into from

Conversation

eksortso
Copy link
Contributor

This intends to resolve #630, i.e. it clarifies that inline tables are immutable once defined.

@ChristianSi
Copy link
Contributor
ChristianSi commented Aug 16, 2019

A problem I see here is that the text doesn't address the reverse case. It the following allowed?

a.b = 1  # INVALID
a = {c = 2}

Obviously, it isn't, but the text doesn't make this clear. Indeed, the wording "Once inline tables..." might suggest that dotted keys can "inject" values into inline tables as long as the inline table itself is defined later in the document.

@eksortso
Copy link
Contributor Author

That's easy to resolve. How about if we add this?


If a table is defined with dotted-key expressions, it cannot be redefined with
an inline table.

a.b = 1       # The table `a` is defined here.
#a = {c = 2}  # INVALID: This table is defined with dotted keys.
a.c = 2       # This is okay

@ChristianSi
Copy link
Contributor

@eksortso That reads better, however, the other case should be mentioned too:

#[a.b]  # INVALID, since a is an immutable inline table (see below)
a = {}

@workingjubilee
Copy link
Contributor

Perhaps something like "inline tables by definition must contain all their key/value pairs inline, including sub-tables, or else they would not be inline tables, and so, are invalid" would be to-the-point.

Copy link
Contributor
@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mmakaay
Copy link
mmakaay commented Aug 19, 2019

That's easy to resolve. How about if we add this?

If a table is defined with dotted-key expressions, it cannot be redefined with
an inline table.

a.b = 1       # The table `a` is defined here.
#a = {c = 2}  # INVALID: This table is defined with dotted keys.
a.c = 2       # This is okay

That's not really a good distinction IMO, since the a.b = 1 could also be defined without dotted keys, while still the a = {c = 2} case is invalid.

a = {b = 1}
a = {c = 2}  # INVALID

The point is that you cannot create a table more than once, regardless how you define it in the TOML document. In the modified example that I provide above, by rewriting a.b = 1 this is especially clear, since now you see two assignment for a = ....

I have struggled with this a bit too, when implementing my TOML parser, and what I ended up with was that internally I keep track of implicit and explicit tables. An implicit table is a table which is only used as a "path" in a dotted key syntax. For example:

a.b.c = 1234

Here, I have to create a table "a" and a table "b". Table "a" is flagged implicit, table "b" is explicit.
The rule that I follow, is that I can create an explicit table when there's not yet an explicit table at a given path. For example:

a.x = { very = "good" }  # a.x did not exist at all, creating it is OK
a = { good = "as well" } # a was implicit up to now, creating it is OK and makes it explicit
a.b.field = "another key value pair" # standard table, so adding a key/value pair is OK
a.b = { hmmm = "do not do that" } # a.b already exists as an explicit table, INVALID 

I'm not saying that "implicit" versus "explicit" should be wording to be used in the spec. I'm just trying to help getting clear what constructions are allowed and what are not allowed.

@pradyunsg
Copy link
Member

Thanks for getting the ball rolling on this @eksortso, and for your inputs here @ChristianSi and @workingjubilee!

I've posted what I had locally at #652 from a few weeks back. If no one has any concerns with that, let's merge that. If there are concerns, please voice them here and I'll close the other PR -- let's avoid splitting the discussion. :)

@eksortso
Copy link
Contributor Author

Perhaps something like "inline tables by definition must contain all their key/value pairs inline, including sub-tables, or else they would not be inline tables, and so, are invalid" would be to-the-point.

Sorry, but I honestly don't know how to react to that.

@eksortso
Copy link
Contributor Author

You got it down pat with #652, @pradyunsg, thank you. I'm closing this PR.

@eksortso eksortso closed this Aug 19, 2019
@eksortso eksortso deleted the i630_immutable_inline branch August 19, 2019 12:06
@workingjubilee
Copy link
Contributor

😅 Sorry, was an unfortunately half-baked thought.

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

Successfully merging this pull request may close these issues.

Clarify inline tables are immutable (and dotted keys can't "inject" into them)
5 participants
0