Skip to content
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

Cannot parse dotted keys which specify inline table #151

Open
Jefffrey opened this issue Sep 10, 2024 · 2 comments
Open

Cannot parse dotted keys which specify inline table #151

Jefffrey opened this issue Sep 10, 2024 · 2 comments

Comments

@Jefffrey
Copy link

Jefffrey commented Sep 10, 2024

Example TOML:

a.b = 1
a.c = { d = 1 }

Fails to parse. Example test case output based on above:

  1) Failure:
TomlTest#test_valid_cases [test/toml_test.rb:133]:
Error: Key "a" is defined more than once in test/examples/valid/dotted-key-inline-table.toml

This succeeds in being parsed by Python and Rust implementations.

Python:

Python 3.12.5 (main, Aug  9 2024, 08:20:41) [GCC 14.2.1 20240805] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tomllib
>>> toml_str = """
... a.b = 1
... a.c = { d = 1 }
... """
>>> tomllib.loads(toml_str)
{'a': {'b': 1, 'c': {'d': 1}}}

Rust (toml v0.8.19):

fn main() {
    let toml_str = r#"
a.b = 1
a.c = { d = 1 }
"#;
    dbg!(toml_str.parse::<toml::Value>());
}

Outputs:

[src/main.rs:6:5] toml_str.parse::<toml::Value>() = Ok(
    Table(
        {
            "a": Table(
                {
                    "b": Integer(
                        1,
                    ),
                    "c": Table(
                        {
                            "d": Integer(
                                1,
                            ),
                        },
                    ),
                },
            ),
        },
    ),
)

Note that in the reverse order, this library can parse successfully, i.e.

a.c = { d = 1 }
a.b = 1
@emancu
Copy link
Owner

emancu commented Sep 10, 2024

🤔 Interesting, I will take a look over the next week.

@emancu
Copy link
Owner

emancu commented Oct 3, 2024

I did start digging into this, and is taking me more than I expected. I didn't forget, just a bit short of time.

I'm sorry

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

No branches or pull requests

2 participants