Toml: Suggestion: Table attributes where contained keys are prefixed with @

Created on 2 Oct 2016  路  2Comments  路  Source: toml-lang/toml

Synopsis

Let all Tables implement an attribute collection separate from normal keys, where the attribute is specified as a normal key with a @ symbol. Preferably, this leading @ should be allowed in bare keys. Maybe even only restrict it to bare keys.

Reasoning

To closer mimic behavior of for instance XML, which i'm trying my best to get rid of in my work environment and replace with TOML.
Currently, there are a lot of well-established configuration files that I do not want to change the semantics of, makes slight use of XML attributes, so make an all-in-one swoop transition from XML to TOML, I need to support some sort of attributes on sections (Tables).

In the configuration management tool i'm currently writing, I'm implementing a TOML output format.
To support section attributes, i will need to manually extract all table keys starting with a @ and
treat them as attributes.

I believe having TOML specifically treat (bare) keys with leading @ as table attributes leads to simplified code using the parsed result, as well as making TOML more versatile at little cost.

Example

# This is my config file.
@CONFIG_VERSION = '1.2.3'

[[definition]]
@mission = 'SENTINEL 1A'
international_designator = '2014-016A'

[[definition]]
@mission = 'TERRA'
international_designator = '1999-068A'

The equivalent XML is

<missions>
  <definition mission="SENTINEL 1A">
    <international_designator>2014-016A</international_designator>
  </definition>
  <definition mission="TERRA">
    <international_designator>1999-068A</international_designator>
  </definition>
</missions>

Most helpful comment

Here is why I think it's a bad idea:

  • TOML does not aim to mimic XML in any way.
  • I'm quoting the specs: "TOML is designed to map unambiguously to a hash table." Do you know any programming language where simple hash tables have a separate collection of attributes?
  • Implementing this will make the parsers more complex and consume more memory.
  • You could achieve what you want without modyfing the TOML specs: just use normal key/value pairs, parse your file with a basic TOML lib, then check if the keys' names start with a @ and organize your data accordingly.

All 2 comments

Here is why I think it's a bad idea:

  • TOML does not aim to mimic XML in any way.
  • I'm quoting the specs: "TOML is designed to map unambiguously to a hash table." Do you know any programming language where simple hash tables have a separate collection of attributes?
  • Implementing this will make the parsers more complex and consume more memory.
  • You could achieve what you want without modyfing the TOML specs: just use normal key/value pairs, parse your file with a basic TOML lib, then check if the keys' names start with a @ and organize your data accordingly.

Since this suggestion was not met with great enthusiasm, I'll lay waste to it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LongTengDao picture LongTengDao  路  4Comments

LongTengDao picture LongTengDao  路  3Comments

mqudsi picture mqudsi  路  3Comments

Silentdoer picture Silentdoer  路  4Comments

paiden picture paiden  路  3Comments