status-im / nim-toml-serialization

Flexible TOML serialization [not] relying on run-time type information.
Apache License 2.0
37 stars 7 forks source link

OrderedTable support #44

Closed Patitotective closed 2 years ago

Patitotective commented 2 years ago

I'm using this library to parse a TOML file where I describe some tables that will later become graphical elements, it will be cool if there were some TomlKind.OrderedTable or TomlFlag.TomlOrderedTable so the elements look in the order you defined them.

Patitotective commented 2 years ago

Or simply turn TomlTable into OrderedTable[string, TomlValueRef]

jangko commented 2 years ago

fixed by #45.

You can use -d:tomlOrderedTable to switch TomlTable into OrderedTable when parsing. But because elements ordering is not mandated and even not not guaranteed by the spec, ordered table only supported by reader/parser/decoder. The writer/encoder cannot support full toml spec if using ordered table. there are cases related to dotted key where it's simply too hard or almost impossible to implement an ordered top level elements because dotted keys original form is destroyed during parsing, and when the generalized form of table is serialized, it will create different structure than the original document.

Patitotective commented 2 years ago

Thank you for the quick implementation. :upside_down_face: