Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON/YAML/etc. configuration files? #326

Open
musjj opened this issue Jan 1, 2023 · 3 comments
Open

JSON/YAML/etc. configuration files? #326

musjj opened this issue Jan 1, 2023 · 3 comments

Comments

@musjj
Copy link

musjj commented Jan 1, 2023

What do you think of adding a JSON/YAML/etc. configuration format?
I think it would make it way easier to introduce to new users.

@o-sdn-o
Copy link
Collaborator

o-sdn-o commented Jan 1, 2023

Hi! I support this idea. We will need to implement the format converter used by vtm to JSON/YAML/etc and vice versa. Perhaps in the future one of these formats will be more convenient than the one used in vtm now. The use of vtm in its own format is due to the need to inline attribute records (for brevity) while not losing the algorithmic simplicity of merging two such configurations

<background>
  <fgc>whitedk</fgc>
  <bgc>blacklt</bgc>
  <tile>"#   \n    "</tile>
</background>

the same but shorter

<background fgc=whitedk bgc=blacklt tile="#   \n    "/>

To convert to other serialization formats, we can translate the vtm format into some canonical form that is compatible with other formats. To do this, we need to introduce a new parameter for each attribute - _value_ - which contains the attribute's own value.

Canonical form

<background>
  <_value_>""<_value_>
  <fgc>
    <_value_>"whitedk"<_value_>
  </fgc>
  <bgc>
    <_value_>"blacklt"<_value_>
  </bgc>
  <tile>
    <_value_>"#   \n    "<_value_>
  </tile>
</background>

JSON

{
    "background": {
        "_value_": "",
        "fgc": {
            "_value_": "whitedk",
        },
        "bgc": {
            "_value_": "blacklt",
        },
        "tile": {
            "_value_": "#   \n    ",
        },
    },
}

YAML

    - background
        - _value_: ""
        - fgc
            - _value_: "whitedk"
        - bgc
            - _value_: "blacklt"
        - tile
            - _value_: "#   \n    "

@o-sdn-o
Copy link
Collaborator

o-sdn-o commented Jan 1, 2023

There is also the question of how to deal with lists when merging configurations. We need a way to determine in which case the list should be overwritten and which should be added.

Adding an asterisk to the end of the name solves this problem for all formats.

@sertonix
Copy link
Contributor

sertonix commented Jan 3, 2023

Since xml supports multiple keys with the same name the childs would need to be stored as arrays.

Something like this would be possible:

<background >
  <fgc>whitedk</fgc>
  <bgc>blacklt</bgc>
  <tile>"#   \n    "</tile>
</background>
{
  "type": "backgroud",
  "values": [
    {
      "type": "fgc",
      "value": "whitedk"
    },
    {
      "type": "bgc",
      "value": "blacklt"
    },
    {
      "type": "tile",
      "value": "#   \n    "
    }
  ]
}

This would also make the special syntax a bit easier.

<item* />
{
  "type": "item",
  "template": true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants