Yaml Examples

YAML examples. (These will be used to help provide material for YamlOscon.)

[[TableOfContents()]]

Release Changes

overview: >
  This is a nit-pick release of the specification
  with mostly cosmetic changes (nothing in substance)

changes:
 - a few productions were fixed up per Oren's observations
 - see terminology changes below
 - css page breaks were added and the outline reformatted
 - preview restructuring...

terminology:  # changes in terminology
  flow: >
     Where in-line was used before, at first to mean a 
     single-line construct and now a multi-line construct.
     Flow seems to better encapsulate the concept since 
     the content flows from one line to the next.
  literal: >
     The block scalar has been renamed literal scalar.  Another
     word was needed since block also meant "block indenting".
  block: >
     This now refers primarly to the indenting technique, in
     constrast to "flow".  Thus, we have a block mapping and
     a flow mapping.  Block scalars include literal and folded,
     flow scalars are plain, single and double quoted.

Escape of the Unicorn Animation Data

title: Escape of the Unicorn
animations:
  - title: background sky
    author: Justyna
    frames:
      - file: bg_sky_1.png
        ms:   500
      - file: bg_sky_2.png
        ms:   500
  - title: background water
    author: Jacek
    frames:
      - file: bg_water.png
ms: 300
- file: bg_water1.png
ms: 200
- file: bg_water2.png
ms: 200
- file: bg_water3.png
ms: 300
- file: bg_water2.png
ms: 200
- file: bg_water1.png
ms: 200

If you use in-lined lists for the file/ms pairs, you can make it even tighter.

For comparison, the original XML:

<title>Escape of the Unicorn</title>
<animations>
  <animation>
    <title>0 background sky</title>
    <author>Justyna</author>
    <frames>
      <frame><file>bg_sky_1.png</file><ms>500</ms></frame>
      <frame><file>bg_sky_2.png</file><ms>500</ms></frame>
    </frames>
  </animation>
  <animation>
    <title>1 background water</title>
    <author>Jacek</author>
    <frames>
      <frame><file>bg_water.png</file><ms>300</ms></frame>
      <frame><file>bg_water1.png</file><ms>200</ms></frame>
      <frame><file>bg_water2.png</file><ms>200</ms></frame>
      <frame><file>bg_water3.png</file><ms>300</ms></frame>
      <frame><file>bg_water2.png</file><ms>200</ms></frame>
      <frame><file>bg_water1.png</file><ms>200</ms></frame>
    </frames>
  </animation>
</animations>

YAML's Built in Lists

Note the difference made by YAML's support for lists:

frames:
  - file: bg_sky_1.png
    ms:   500
  - file: bg_sky_2.png
    ms:   500

vs.

<frames>
  <frame><file>bg_sky_1.png</file><ms>500</ms></frame>
  <frame><file>bg_sky_2.png</file><ms>500</ms></frame>
</frames>

You don't have to make singular identifiers (frame); You only need the plural identifier (frames).

Escape of the Unicorn Game Object Data

Here's what a specification of the game object data would look like in YAML:

objects:
  - category:  monster
    title:     dragon green
    alignment: monsters side
    health:    5
    deathobj:   dragon green dying
    deathscore: 100
    gravityaffected: +

    touchaward:
      health: -5
      score:  -50

    behavior:
      type:  horizontal traverser
      speed: 100.0
      actions:
left: dragon green moves left right: dragon green moves right
    missiles:
      title:     missile fireball
      rate:      2000
      variance:  500
      direction: forward

Here's the present XML:

<objects>
  <object>
    <category>monster</category>
    <title>dragon green</title>
    <alignment>monsters side</alignment>
    <deathobj>dragon green dying</deathobj>
    <deathscore>100</deathscore>
    <gravityaffected/>

    <touchaward>
      <health>-5</health>
      <score>-50</score>
    </touchaward>

    <behavior>
      <type>horizontal traverser</type>
      <speed>100</speed>
      <actions>
<action><name>left</name><anim>dragon green moves left</anim></action> <action><name>right</name><anim>dragon green moves right</anim></action>
      </actions>
    </behavior>

    <missiles>
      <title>missile fireball</title>
      <rate>2000</rate>
      <variance>500</variance>
      <direction>forward</direction>
    </missiles>
  </object>
</objects>

YAML's Built in Key-Value Dictionaries

Note the difference made by YAML's support for Key-Value dictionaries:

actions:
left: dragon green moves left right: dragon green moves right

vs.

<actions>
<action><name>left</name><anim>dragon green moves left</anim></action> <action><name>right</name><anim>dragon green moves right</anim></action>
</actions>