YAML 1.1 Working Draft #
Hey, look what you didn’t know was coming: YAML 1.1. Since the specification is pretty thick, I shall act as summarizer. (Please note that none of these changes will make it into Ruby/Syck until the fall, considering that our 1.0 support still needs work.)
The most significant and useful change for YAML 1.1 is the new tag shortcut syntax. This was heavily debated on Yaml-Core in September of this year. Trust me when I say it was beaten and hammered like an orchid folded katana blade. We went back and forth, smoothing the syntax into an appealing middle ground.
Here’s a taste from example 2.24:
%TAG ! tag:clarkevans.com,2002: --- !shape # Use the ! handle for presenting # tag:clarkevans.com,2002:circle - !circle center: &ORIGIN {x: 73, y: 129} radius: 7 - !line start: *ORIGIN finish: { x: 89, y: 102 } - !label start: *ORIGIN color: 0xFFEEBB text: Pretty vector drawing.
Normally, in YAML documents, the type system defaults to yaml.org types. This means that when you use !int
as a tag, the full URI for the tag is actually tag:yaml.org,2002:int
. The !int
is merely a shorthand.
The document above illustrates how the %TAG
directive can be used to redefine the global namespace for a document. If we used !int
in the above document, the URI would now be tag:clarkevans.com,2002:int
. This is terribly handy if you want complete control over resolving the tags in a document.
Here’s some other things you can do with %TAG
, courtesy of example 4.31:
# Explicitly specify default settings: %TAG ! ! %TAG !! tag:yaml.org,2002: # Named handles have no default: %TAG !o! tag:ben-kiki.org,2000: --- - !foo "bar" - !!str "string" - !o!type "baz"
The first two %TAG
directives are redundant. These are merely the default settings. As you can see: private types and builtin types have switched shortcut syntax. The team felt that explicit use of private types was seen more often than explicit use of builtin types. People don’t use an explicit !str
that often.
The third %TAG
directive shows the new prefixing notation. Previously, if you wanted to simplify tags in your YAML document, you might use:
--- !hobix.com,2004/^weblog title: RedHanded link: http://redhanded.hobix.com/ tagline: sneaking Ruby through the system period: 00:60:00 linklist: !^linklist - ruby home: http://ruby-lang.org/ - ruby-doc: http://ruby-doc.org/ - rubyforge: http://rubyforge.org/
The above is the old YAML 1.0 prefixing notation. The carat works like a bookmark. The string !hobix.com,2004/
is saved by the carat in its use on the first line. Later, it’s pasted into the !^linklist
tag, which the loader sees as !hobix.com,2004/linklist
.
Done with the new prefixing:
%TAG !hx! tag:hobix.com,2004: --- !hx!weblog title: RedHanded link: http://redhanded.hobix.com/ tagline: sneaking Ruby through the system period: 00:60:00 linklist: !hx!linklist - ruby home: http://ruby-lang.org/ - ruby-doc: http://ruby-doc.org/ - rubyforge: http://rubyforge.org/
This syntax is much better for interleaved types, in which namespaces cross as they share data.
And, remember, that if you’re please with YAML 1.0 and wish to use it forever, you can do that with the %YAML 1.0
directive.
flgr
Bad man
why
chris2
why
James
why
chris2
I had a OGDL parser in the works, but got annoyed with them because they couldn’t figure out how to interpret their specs. sigh
rolf
Hi, Chris2. I want OGDL to be simple, but the spec is written in a formal language (like YAML ’s spec), and that’s not so simple. But it is not fixed, and if someone says its not simple enough, then we have failed in our goal. Time to work on it. Cheers.
Comments are closed for this entry.