Tcl Library Source Code

Documentation
Login


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

NAME

yaml - YAML Format Encoder/Decoder

Table Of Contents

SYNOPSIS

package require Tcl 8.5 9
package require yaml ?0.4.2?

::yaml::yaml2dict ?options? txt
::yaml::yaml2huddle ?options? txt
::yaml::setOption ?options?
::yaml::dict2yaml dict ?indent? ?wordwrap?
::yaml::list2yaml list ?indent? ?wordwrap?
::yaml::huddle2yaml huddle ?indent? ?wordwrap?

DESCRIPTION

The yaml package provides a simple Tcl-only library for parsing the YAML http://www.yaml.org/ data exchange format as specified in http://www.yaml.org/spec/1.1/.

The yaml package returns data as a Tcl dict. Either the dict package or Tcl 8.5 is required for use.

COMMANDS

EXAMPLES

An example of a yaml stream converted to Tcl. A yaml stream is returned as a single item with multiple elements.

{
--- !<tag:clarkevans.com,2002:invoice>
invoice: 34843
date   : 2001-01-23
bill-to: &id001
    given  : Chris
    family : Dumars
    address:
        lines: |
            458 Walkman Dr.
            Suite #292
        city    : Royal Oak
        state   : MI
        postal  : 48046
ship-to: *id001
product:
    - sku         : BL394D
      quantity    : 4
      description : Basketball
      price       : 450.00
    - sku         : BL4438H
      quantity    : 1
      description : Super Hoop
      price       : 2392.00
tax  : 251.42
total: 4443.52
comments:
    Late afternoon is best.
    Backup contact is Nancy
    Billsmer @ 338-4338.
}
=>
invoice 34843 date 2001-01-23 bill-to {given Chris family Dumars address {lines {458 Walkman Dr.
Suite #292
} city {Royal Oak} state MI postal 48046}} ship-to {given Chris family Dumars address {lines {458 Walkman Dr.
Suite #292
} city {Royal Oak} state MI postal 48046}} product {{sku BL394D quantity 4 description Basketball price 450.00} {sku BL4438H quantity 1 description {Super Hoop} price 2392.00}} tax 251.42 total 4443.52 comments {Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.}

An example of a yaml object converted to Tcl. A yaml object is returned as a multi-element list (a dict).

{
---
- [name        , hr, avg  ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa  , 63, 0.288]
-
  Mark McGwire: {hr: 65, avg: 0.278}
  Sammy Sosa: { hr: 63, avg: 0.288}
}
=>
{name hr avg} {{Mark McGwire} 65 0.278} {{Sammy Sosa} 63 0.288} {{Mark McGwire} {hr 65 avg 0.278} {Sammy Sosa} {hr 63 avg 0.288}}

LIMITATIONS

tag parser not implemented. currentry, tags are merely ignored.

Only Anchor => Aliases ordering. back alias-referring is not supported.

Too many braces, or too few braces.

Not enough character set of line feeds. Please use only "\n" as line breaks.

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category yaml of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.

SEE ALSO

base64, huddle, json

KEYWORDS

data exchange, huddle, parsing, text processing, yaml

COPYRIGHT

Copyright © 2008 KATO Kanryu