Jason
Jason

Reputation: 2373

Using YAML tags to denote types

I don't quite understand how to use application specific YAML tags, and maybe its because my desired use of them is purely wrong. I am using YAML for a configuration file and was hoping to use tags to provide my configuration loader with a hint as to what datatype it should parse the data into - application specific datatypes.

I'm also using libyaml with C.

So I'm trying to do something like...

shapes:  
  square: "0,4,8,16"  
  circle: "5,10"  

In my app I'd like to use tags as hints so I can load the values of square into my square data structure, and the values of circle into my circle data structure (these values mean nothing in this example).

So I'm currently doing:

shapes:  
  square: !square "0,4,8,16"  
  circle: !circle "5,10"  

Libyaml will provide a tag of "!square" when I'm passed the scalar "0,4,8,16". Is it valid to use this tag to provide my loader with a hint of how to process the scalar?

Since it does work for me, I'm more curious to know if its proper. And if not, how would I go about making this more proper.

Thanks.

Upvotes: 11

Views: 6607

Answers (1)

Pharaun
Pharaun

Reputation: 1232

I know that this is an ancient question, but anyway I've seen !int, etc being used in yaml files before so I went to look up the specs at Yaml 1.2 Spec # Tags

application specific tag: !something |
 The semantics of the tag
 above may be different for
 different documents.

As per the document, it does look like your intended usage of tags is correct for application specific tag.

Upvotes: 5

Related Questions