yaml(3tcl)
β¨ yaml β YAML Format Encoder/Decoder β¨
okay bestie, welcome to the yaml page from tcllib π this is the YAML processing manual, and yes we're about to make data exchange cute.
πΈ 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 is a simple, Tcl-only library for parsing the YAML data exchange format, exactly as specified at http://www.yaml.org/ and http://www.yaml.org/spec/1.1/. no cap, it's giving pure Tcl.
it hands your data back as a Tcl dict. so you're gonna need either the dict package or Tcl 8.5 to use it, fr fr. π¦
π COMMANDS π
::yaml::yaml2dict ?options? txt
::yaml::yaml2huddle ?options? txt
these two parse yaml-formatted text txt into a Tcl dict/huddle and return that value. main character energy, honestly. π
-fileβ txt is actually a filename of a YAML-stream. (yes, the argument name is stilltxt, we don't make the rules)-streamβ txt is just a YAML-stream, as-is. periodt.-typeslist β the list is a type list for the yaml-scalar types. like, e.g.!!str!!timestamp!!integer!!true...
-types {timestamp integer null true false}
so in this case, if a string matched "timestamp", it gets converted to the TCL internal timestamp. e.g. "2001-12-15T02:59:43.1Z" => 1008385183. iconic behaviour ngl.
-m:trueparam β param is two elements of a list: the value for true, and the strings that count as it. highkey clever.
-m:true {1 {true on + yes y}}
so in this case, the string "yes" found in the YAML Stream gets automatically converted to 1. slay.
-m:falseparam β param is two elements of a list: the value for false, and the strings that count as it.
-m:false {0 {false off - no n}}
-m:nullparam β param is two elements of a list: the value for null, and the strings that count as it.
-m:null {"" {null nil "" ~}}
-validateβ Experiment, old: the output stream contains YAML's-tag on each node. it's giving experimental, so be aware.
% puts [::yaml::load -validate {[aaa, bbb]}]
=>
!!seq {{!!str aaa} {!!str bbb}}
::yaml::setOption ?options?
changes the implicit options for the library. right now the params are the same as ::yaml::yaml2dict. and heads up bestie β arguments passed to ::yaml::yaml2dict have more priority than this setting. π
::yaml::dict2yaml dict ?indent? ?wordwrap?
::yaml::list2yaml list ?indent? ?wordwrap?
::yaml::huddle2yaml huddle ?indent? ?wordwrap?
these convert a dict/list/huddle object into a YAML stream. the glow-up goes the other direction. π§
- indent β the spaces of indent for each block node. currently the default is
2. - wordwrap β word wrap for the YAML stream. currently the default is
40.
π¦ EXAMPLES π¦
a yaml stream converted to Tcl π
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.}
a yaml object converted to Tcl π
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 π
okay so, the tea: π
- the tag parser is not implemented. currently, tags are merely ignored. π
- only Anchor => Aliases ordering works. back alias-referring is not supported.
- too many braces, or too few braces. (yes, that's the whole vibe)
- 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. no cap. please report such in the category yaml of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. please also report any ideas for enhancements you may have for either the package and/or the documentation. we want the feedback, fr fr. π«Ά
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 (c) 2008 KATO Kanryu <kanryu6@users.sourceforge.net>
and that's the whole page, bestie π this one came from tcllib, version 0.4.2, filed under yaml(3tcl) β go forth and parse, you ate. πβ¨π
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2008 KATO Kanryu <kanryu6@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms