emancu / toml-rb

A parser for TOML using Citrus library.
MIT License
104 stars 39 forks source link

Cannot parse dotted keys which specify inline table #151

Open Jefffrey opened 2 months ago

Jefffrey commented 2 months ago

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 commented 2 months ago

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

emancu commented 1 month ago

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