Tcl Library Source Code

Ticket Change Details
Login
Overview

Artifact ID: 39bf8b4f2ee2012bcb8dd63fa94f3d668e138a1ede97272d9f14cf09b6c30247
Ticket: d74e6561a29ca0dca4d6198a46aa9474e20e34ad
YAML->HUDDLE->YAML fails
User & Date: emmanuel 2017-09-28 21:37:24
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    Converting a YAML file to huddle and back again to YAML will not work. This is because the implementation of huddle2yaml does not pay attention to the internal types that are introduced by the YAML parser to support dictionaries and lists. The following piece of code solves it:
    
        proc ::yaml::_imp_huddle2yaml {data {offset ""}} {
            set nextoff "$offset[string repeat { } $yaml::_dumpIndent]"
            switch -glob -- [huddle type $data] {
                "int*" -
                "str*" {
                    set data [huddle get_stripped $data]
                    return [_dumpScalar $data $offset]
                }
                "sequence" -
                "list" {
                    set inner {}
                    set len [huddle llength $data]
                    for {set i 0} {$i < $len} {incr i} {
                        set sub [huddle get $data $i]
                        set tsub [huddle type $sub]
                        set sep [expr {[string match "str*" $tsub] || [string match "int*" $tsub] ? " " : "\n"}]
                        lappend inner [join [list $offset - $sep [_imp_huddle2yaml $sub $nextoff]] ""]
                    }
                    return [join $inner "\n"]
                }
                "mapping" - 
                "dict" {
                    set inner {}
                    foreach {key} [huddle keys $data] {
                        set sub [huddle get $data $key]
                        set tsub [huddle type $sub]
                        set sep [expr {[string match "str*" $tsub] || [string match "int*" $tsub] ? " " : "\n"}]
                        lappend inner [join [list $offset $key: $sep [_imp_huddle2yaml $sub $nextoff]] ""]
                    }
                    return [join $inner "\n"]
                }
                default {
                    return $data
                }
            }
        }
    
  5. foundin changed to: "current"
  6. is_private changed to: "0"
  7. login: "emmanuel"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "411315ec769379ea86b165441afa60d632da17e5"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "emmanuel"
  14. subsystem changed to: "yaml"
  15. title changed to: "YAML->HUDDLE->YAML fails"
  16. type changed to: "Bug"