Godot-proposals: YAML support (parser)

Created on 28 May 2020  路  8Comments  路  Source: godotengine/godot-proposals

Describe the project you are working on:
2d space game

Describe the problem or limitation you are having in your project:
I have to use csv files for data, which have their own limitations/problems (https://github.com/godotengine/godot/issues/38957, https://github.com/godotengine/godot/issues/31749)

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
YAML is a popular data format that has one significant advantage over CSV/JSON - comments! Many of my data points are derived from others and comments would make it much more clear for any prospective contributors.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
I imagine similar to how built in JSON parsing works.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Writing a YAML parser, especially one supporting comments (which are the main draw of YAML), is definitely not 'a few lines'

Is there a reason why this should be core and not an add-on in the asset library?:
New developers will not be aware of asset library.

core

Most helpful comment

It doesn't have to be a resource, but the parser class is enough to achieve this. JSON is quite popular so it has a dedicated parser already. Perhaps there could be a general-purpose parser implementing quite a bunch of those formats.

Not particularly related to the proposal, but the guys at SCons told that it would be possible to extend the serialization formats used by env.Dump() (including YAML). I'm personally trying to merge this to support JSON: SCons/scons#3672. If you wonder why, this would be mainly useful for #119 (GDNative plugins can be compiled with SCons, and it would be nice to inspect various build-time information for Godot editor etc).

For markdown, there's #139 proposal.

All 8 comments

https://github.com/commonmark/cmark is the standard library for this, it should be possible to include it and read the [YAML] as a resource to a dictionary.

Edited:
Typo.

New developers will not be aware of asset library.

That doesn't sound like a valid reason. A complete beginner won't need YAML either.

@KoBeWi But s/he will need JSON? If we have one, we should have the other, too.

Well Godot has a BBCode parser too, which is the closest thing to this.

Sorry, I got confused.

There's several things that can be added.

  • markdown as a resource
  • json as a resource
  • yaml as a resource

Personally, I want to add all of them, but this particular one is yaml.

It doesn't have to be a resource, but the parser class is enough to achieve this. JSON is quite popular so it has a dedicated parser already. Perhaps there could be a general-purpose parser implementing quite a bunch of those formats.

Not particularly related to the proposal, but the guys at SCons told that it would be possible to extend the serialization formats used by env.Dump() (including YAML). I'm personally trying to merge this to support JSON: SCons/scons#3672. If you wonder why, this would be mainly useful for #119 (GDNative plugins can be compiled with SCons, and it would be nice to inspect various build-time information for Godot editor etc).

For markdown, there's #139 proposal.

Would hand-written ConfigFiles be a suitable replacement? The syntax is similar to TOML, but you can serialize any Godot datatype to them. Complex datatypes can be written over several lines, so something like this can be parsed successfully:

[ship]
name = "Some Spaceship"
; This is a comment. It must be placed at the beginning of a line.
properties = {
    "speed": 20,
    "position": Vector2(40, 60),
    "active": true,
    "colors": ["red", "green", "blue"],
}

Comments and formatting will be preserved as long as you don't save the ConfigFile using Godot.

New developers will not be aware of asset library.

I don't think this reason is sufficient in itself. We could aim to improve the asset library's discoverability instead.

New developers will not be aware of asset library.

Not to jump on the statement, but new developers often don't know about the documentation either, and use Google / Youtube to find engine-related information. I'm quite sure that if an asset library solution for parsing YAML existed, searching for "Godot YAML" would quickly bring it up.

Was this page helpful?
0 / 5 - 0 ratings