summaryrefslogtreecommitdiff
path: root/docs/yaml.rst
blob: 5d70e82a5d3bb8057075a9e7445a8e5131b9a35c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
***********
YAML Primer
***********

This page provides a basic overview of the YAML syntax as used by QFace in the embedded annotations and the external annotations document.

According to the official YAML website, YAML is "a human friendly data serialization standard for all programming languages".

YAML Foundation
===============

For QFace every YAML file is a dictionary of values.

.. code-block:: python

    @singleton: true
    @base: QObject
    interface Heater {
    }

A dictionary in YAML is expressed like this


In an external YAML file the key on the root level is the fully qualified name of the symbol

.. code-block:: YAML

    org.example.Heater:
        singleton: true
        base: QObject

Dictionary
==========

A dictionary is a simple ``key: value`` pair with a colon followed by a space (the space is mandatory).

.. code-block:: yaml

    key: value
    key2: value
    key3:
        key31: value
        key32: value

A nested dictionary can be achieved by a new level of indentation.

An alternate form for a dictionary is this

.. code-block:: yaml

    key3: { key31: value, key32: value }

.. rubric Template

In a template the dictionay can be used as attributes of an object

.. code-block:: jinja

    {% if interface.tags.key == 'value' %}YES{% endif %}

To test is a key exists you can use the key in dictionary form

.. code-block:: jinja

    {% if 'key' in interface.tags %}YES{% endif %}

List
====

A list is an array of values

.. code-block:: yaml

    - item1
    - item2
    - item3:
        - item31
        - item32

A nested list can be created by indenting the list and postfixing the parent entry with a colon.

An alternate form is

.. .. code-block:: yaml

    [ item1, item2, item3: [item31, item32] ]

Comments
--------

YAML only knows line comments. A comment starts with a ``#`` and ends with line.

.. code-block:: yaml

    # this is the key for the value
    key: value

Primitive Types
---------------

YAML understands different primitive types.

.. rubric:: string

YAML understands strings either as an identifier or quoted using ``"`` or ``'``.

You can use code blocks using the ``|`` sign. The block continues until the indentation ends. Or the ``>`` folding block, where each new line is replaced with a space.

.. rubric:: number

YAML understands different number formats, here is a short list of the most important ones

.. code-block:: yaml

    # an integer
    value: 10

    # an hex value
    value: 0xFF

    # a float
    value: 1.01

.. rubric:: boolean

YAML understand different values as true/false.

.. code-block:: yaml

    positive: yes
    positive: true
    negative: no
    negative: false

Besides these words it understand different writing forms (e.g. YES, Yes, Y). Same applies for the negative version.