hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

YAML 1.1 Working Draft #

by why in inspect

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.

said on 31 Dec 2004 at 16:50
I wonder if there's plans for making this possible:
  [1, 2]: [3, 4]
I tried to use that syntax before and it did not work which I found quite odd.
said on 31 Dec 2004 at 21:10
This is a horrible syntax. Awful. Why not use XML if you need to be that explicit about data types? Bad, bad idea.
said on 31 Dec 2004 at 22:11
flgr: That syntax was allowed in the final 1.0, but hasn't been fully tested. Bad man: Your negativity is awe-inspiring!!
said on 01 Jan 2005 at 07:02
Boy, this spec gets more and more complex. Although I guess you can do pretty cool stuff with it, YAML still means "YAML Ain't Markup Language", doesn't it? Anyone pondered about a "YAML lite", that is a compatible subset of YAML and can be implemented more easily?
said on 01 Jan 2005 at 11:18
There's been lots of YAML offshoots. OGDL. Michael Schwern had one a while ago. Having implemented a YAML parser, though, I think it's safe to say that YAML isn't nearly as complicated as the specification makes it out to be. Oren and Clark are just pedantic. In reality, the hardest thing about writing a YAML parser is handling the indentation.
said on 01 Jan 2005 at 18:18
Boy, this spec gets more and more complex. Although I guess you can do pretty cool stuff with it, YAML still means "YAML Ain't Markup Language", doesn't it?
But it does bring back echos of the original meaning of YAML: Yet another markup language. Is YAML veering into over-complification, where the original vision is lost as more features are bolted on?
said on 01 Jan 2005 at 22:56
Well, yeah. But if someone laid out Ruby into an elaborate syntax specification, it could look pretty convoluted. The spec productions are all written to be machine-readable. It's like reading my YACC syntax. I really don't like the way all the whitespace in the YAML documents has its own color and outline. It's heiroglyphic.
said on 03 Jan 2005 at 14:31

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

said on 03 Feb 2005 at 02:26

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.