kowainik / tomland

🏝 Bidirectional TOML serialization
https://kowainik.github.io/posts/2019-01-14-tomland
Mozilla Public License 2.0
120 stars 39 forks source link

[RFC] Store inline-tag along with the tables #330

Open vrom911 opened 4 years ago

vrom911 commented 4 years ago

There are two ways to write tables in TOML. But currently tomland doesn't keep track of such information, though it could be useful during pretty-printing later. This info is not that hard to get, as we already parsing both cases.

The question is, do you think that it worth to support this enhancement? And what the downsides are?

chshersh commented 4 years ago

@vrom911 Excellent idea 👌 It's totally possible because we already know this information during parsing. I think, the solution to this problem will be to implement a type like:

data TomlTable = TomlTable
    { tomlTableInline :: TableInline
    , tomlTableTOML :: TOML
    }

And instead of the current type

https://github.com/kowainik/tomland/blob/316c893a10d1dc652bbcc46f7f8862974941244e/src/Toml/Type/TOML.hs#L96-L100

it will look like this

data TOML = TOML
    { tomlPairs       :: !(HashMap Key AnyValue)
    , tomlTables      :: !(PrefixMap TomlTable)
    , tomlTableArrays :: !(HashMap Key (NonEmpty TomlTable))
    }

I think it's totally worth it, since it will help to produce better output!