The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
YAML 1.1 Working Draft

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
YAML 1.1 Working Draft Posted: Dec 31, 2004 6:43 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: YAML 1.1 Working Draft
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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.

Read: YAML 1.1 Working Draft

Topic: Ruby on Rails has its web presence overhauled Previous Topic   Next Topic Topic: Ruby on Rails logo and site unveiled

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use