CUBY logo

YAML

Difference between revisions from 2011/10/17 14:04 and 2011/10/17 13:51.
Some cuby input files in YAML format can bee seen on [Examples] page.
!YAML structures
The basic '''keyword'''->value record in cuby input looks like
{html}<pre><code>keyword: value</code></pre>{/html}
In some cases, cuby uses '''subsections''' in input files to contain keywords specific to some part of the calculation. It is created as a list one level deeper, indented by two spaces:
{html}<pre><code>subsection_name:
&nbsp;&nbsp;key1: value
&nbsp;&nbsp;key2: value
another_subsection:
&nbsp;&nbsp;key1: different_value
&nbsp;&nbsp;key2: value</code></pre>{/html}
Third feature of YAML used in cuby input files are '''array'''s - ordered lists values. Array is written in YAML using - characters:
{html}<pre><code>keyword_requiring_array:
&nbsp;&nbsp;- value1
&nbsp;&nbsp;- value2
&nbsp;&nbsp;- value3
</code></pre>{/html}

Some keywords are read as '''comma-separated lists''', but these are not recognized by YAML parser, but processed by cuby itself:
{html}<pre><code>keyword: this, that, something else</code></pre>{/html}

Empty lines are ignored, # character starts comments.

!!Warning!
YAML language specification does not allow the use of duplicate keys, but the ruby parser does not complain when it encounters this problems and just overwrites the value. Therefore, input
{html}<pre><code>keyword: 1, 2, 3
keyword: 6, 7
</code></pre>{/html}
sets the value of the key to "6, 7".
sets the value of the key to "6, 7". Unfortunately, this is the behavior of the YAML parser itself, so it is not possible to warn the user when such duplicity is encountered.

!Syntax highlighting
And advantage of standardized file format is that there are syntax highligters for it. If one is not a part of your favorite editor and the editor is vim, you can get the highilgter [here|http://github.com/trans/yaml_vim/tree/master]