JuliaLang / TOML.jl

A fast TOML parser for TOML 1.0 written in Julia
MIT License
34 stars 15 forks source link

Output style request: use inline dicts when brevity is improved #42

Open tecosaur opened 2 years ago

tecosaur commented 2 years ago
( rewording of a comment in #40 )

Despite best efforts, in some cases the structure being represented can become somewhat nested. In such situations, the fact that TOML.print always writes dicts out as [key.subkey...] thing=val can actually make the readability worse.

Here's a practical example from a file I have, processed we have:

[["GTEx v8 transcript tpm"]]
stuff="..."
    [["GTEx v8 transcript tpm".loader]]
    stuff="..."
        [["GTEx v8 transcript tpm".loader.loaders]]
        driver = "csv"
        args = { header = 3 }

this becomes (via a parsing round-trip)

[["GTEx v8 transcript tpm"]]
stuff="..."
    [["GTEx v8 transcript tpm".loader]]
    stuff="..."
        [["GTEx v8 transcript tpm".loader.loaders]]
        driver = "csv"

            ["GTEx v8 transcript tpm".loader.loaders.args]
            header = 3

which I think is quite simply harder to read.

I'd think a heuristic along the lines of "if number of key-value pairs less than (some N) and inline dict representation is <72 characters long, use an inline dict" could be quite helpful here.