yaml for haXe
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.mkd
Test.hx
YamlHX.hx
build.hxml

README.mkd

yaml-hx

Will read a yaml doc and return a haxe.xml.Fast object which you can use to access all the data in it.
The purpose is for a nice fast way to read yaml formatted docs in haXe, for configuration files etc, while staying consistent with the yaml spec. yaml-hx does not implement all features in yaml spec yet.
yaml-hx will read the sample "invoice" yaml doc and create the expected xml document as the source Xml wrapped with Fast.
So yaml-hx can also be used as a yaml2xml converter.

Will put more examples in the Wiki

Using Fast Xml wrapper

Usage

Consider this yaml doc

var yaml_string:String

development:
  adapter: mysql
  hostname: localhost
  username: root
  password: secret
  database: development

For comparison, in ruby

yaml = YAML.load(yaml_string)
>> hostname = yaml["development"]["hostname"]
=> "localhost"
>> username = yaml["development"]["username"]
=> "root"

with yaml-hx

var yamlhx = YamlHX.read(yaml_string);
var hostname = yamlhx.node.development.node.hostname.innerData; // Fast
var username = yamlhx.get("development.username"); // dots

this is the xml that's created by YamlHX
StringTools.htmlEscape( yamlhx.x.toString() )

<YamlHX xmlns="tag:yaml.org,2002" xmlns:yaml="tag:yaml.org,2002">
  <development>
    <adapter>mysql</adapter>
    <hostname>localhost</hostname>
    <username>root</username>
    <password>secret</password>
    <database>development</database>
  </development>
</YamlHX>

the spell called YamlHX.get()

using the sample "invoice" yaml doc

var invoice = YamlHX.read(invoice_yaml);

trace( invoice.get("total") )
// '4443.52'

yaml-hx will resolve the ship-to alias to the bill-to anchor

trace( invoice.get("bill-to.address.city") )
// 'Royal Oak'

trace( invoice.get("ship-to.address.city") )
// 'Royal Oak'

yaml-hx will access list items using array[index] notation

trace( invoice.get("product[1].description") )
// 'Super Hoop'

Implemented on

  • flash8
  • flash9
  • flash10
  • js
  • neko
  • php

build errors on cpp

Features

  • allows empty keys -> empty xml node
  • haXe xml doesn't like attributes with colon ** yaml:anchor attribute is "yaml-anchor" ** yaml:alias attribute is "yaml-alias"
  • get() method that uses faster dot notation
  • get() method allows using array[index] to access lists

todo

  • looks like the single quotes from the yaml file should be stripped from the node contents
  • # comments
  • !!types
  • benchmarks
  • > Newlines folded
  • >>: alias
  • data merging, overriding