• Re: Question about yaml/huddle conversion

    From Stephen Prather@21:1/5 to All on Tue Mar 22 01:12:03 2022
    I read the source code a little more. First:

    huddle type $config
    mapping

    There's no provision for a "mapping" in this switch command. Is this a bug?

    proc ::yaml::_imp_huddle2yaml {data {offset ""}} {
    variable _dumpIndent
    set nextoff "$offset[string repeat { } $_dumpIndent]"
    switch -- [huddle type $data] {
    "string" {
    set data [huddle get_stripped $data]
    return [_dumpScalar $data $offset]
    }
    "list" {
    set inner {}
    set len [huddle llength $data]
    for {set i 0} {$i < $len} {incr i} {
    set sub [huddle get $data $i]
    set sep [expr {[huddle type $sub] eq "string" ? " " : "\n"}]
    lappend inner [join [list $offset - $sep [_imp_huddle2yaml $sub $nextoff]] ""]
    }
    return [join $inner "\n"]
    }
    "dict" {
    set inner {}
    foreach {key} [huddle keys $data] {
    set sub [huddle get $data $key]
    set sep [expr {[huddle type $sub] eq "string" ? " " : "\n"}]
    lappend inner [join [list $offset $key: $sep [_imp_huddle2yaml $sub $nextoff]] ""]
    }
    return [join $inner "\n"]
    }
    default {
    return $data
    }
    }
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stephen Prather@21:1/5 to All on Tue Mar 22 01:09:30 2022
    Hi forum--

    I'm trying to read a yaml file to huddle, and then convert the huddle back into yaml. But huddle2yaml does not seem to be treating my huddle as such.

    package require yaml
    0.4.1
    set config [::yaml::yaml2huddle "foo: 10"]
    HUDDLE {!!map {foo {!!int 10}}}
    puts [::yaml::huddle2yaml $config]
    ---
    HUDDLE {!!map {foo {!!int 10}}}

    I checked the source code, but couldn't get anything from that. And there are no relevant tests in the tcllib/yaml dir that I could find, not any other examples I can find via Google.

    Surely this is user-error, not a bug. Any ideas?

    Thanks!
    --Myles

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)