toml icon indicating copy to clipboard operation
toml copied to clipboard

Improve dotted table parsing

Open HarveyHunt opened this issue 2 years ago • 0 comments

Context

https://github.com/toml-rs/toml-rs/issues/225 was filed to request externally tagged enum support, which was mostly implemented in https://github.com/toml-rs/toml-rs/pull/264. However, https://github.com/toml-rs/toml-rs/pull/264 didn't have complete support for enums in dotted tables. The PR did add some disabled tests to verify the functionality in the future.

Examples

As shown in the test file, before this change the following TOML would fail to parse:

[val]
NewType = "value"

Here's an excerpt of the error message: "unknown variant `val`, expected one of `Plain`, `Tuple`, `NewType`, `Struct`", key: ["val"]

The code was also unable to parse an array of tables into enum values, such as:

[[enums]]
Plain = {}

[[enums]]
Tuple = { 0 = -123, 1 = true }

[[enums]]
NewType = "value"

[[enums]]
Struct = { value = -123 }

Here's an excerpt of the error message: "enum table must contain exactly one table", key: ["enums"]

Implement the missing functionality and enable the test cases that were previously added.


Note: This PR is functionally identical to https://github.com/toml-rs/toml-rs/pull/362, but is rebased and has an extra commit that removes the FIXMEs and a lint. @johansglock and I have chatted offline about this and agreed that I'll submit this new PR in order to get this change upstream, as he has limited time at the moment.

As discussed on https://github.com/toml-rs/toml-rs/issues/225, I am resubmitting this PR to the new repo.

HarveyHunt avatar Oct 11 '22 10:10 HarveyHunt