Yaml, configuration file and comments

I am using YAML for configuration files, which can be hand edited or
modified by software. I would like the comments to survive across a
load/store. Something along these lines:

Conf file:

Set to your liking

personal_salary: “too small”

Default should be OK

others_salary: “too much”

Change only if you know what you are doing™

boss_salary: “insane”

Code example:
$conf, $com = YAML::load(File.open("/path/to/conf"))
-> $conf = { “personal_salary” => “too small”, … }
$com = { “personal_salary” => “Set to your liking”, … }
$conf[“personal_salary”] = “much better"
File.open(”/path/to/conf", “w”).puts($conf.to_yaml(“comments” => $com))

Gives:

Set to your liking

personal_salary: “much better”

Default should be OK

others_salary: “too much”

Change only if you know what you are doing™

boss_salary: “insane”

Is that a doable/interesting feature? Can it be done with the existing
parser or should the syck C code be modified to?

Guillaume.

In YAML, comments are thrown away, so they are not officially supported for a
roundtrip. (See YAML™ Specification Index 3.2.2 for more.) But someone could
definitely write a preprocessor to strip YAML comments and match them up with
the keys when you emit the document again.

This could be a useful feature. I’ll think about it.

_why

···

On Wednesday 18 June 2003 04:15 pm, Guillaume Marcais wrote:

I would like the comments to survive across a load/store.