Tcl Library Source Code

Ticket Change Details
Login
Overview

Artifact ID: 3b011aa942271c583c059fac5b13b15e13c85a7798755cf8cf44b6ca5fce4d18
Ticket: 8659a16544549c77b75eb624d109985576af7cb3
Support for !!float tag
User & Date: peterlewerin 2017-10-20 08:29:57
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    If YAML source contains the (standard) !!float tag, yaml fails with the message
     
    The "!!float" handle wasn't declared.
     
    In CHANGES, support for !!float is mentioned (0.2.2), but there is no composer for it. The above problem can easily be kludged away by stripping !!float tags, but it seems more correct to add support for them. Code and test diffs below.
     
    Possible problem with this patch: the decision how to handle values that can't be converted to float using expr {double($value)} is above me. For the purposes of this patch my decision is to let the Tcl exception remain unhandled, so for the value 123_0 the error message is
     
    expected floating-point number but got "123_0"
     
    While this side-steps the error handling in yaml, it is still a clear and useful message and keeps the patch simple. The alternative is of course to catch it and rethrow using the module's error handling, but that is a bigger rewrite.
     
    Code (yaml.tcl):
     
    50d49
    <             !!float ::yaml::_composeFloat
    249,252d247
    < }
    < 
    < proc ::yaml::_composeFloat {value} {
    <     return [list !!float [expr {double($value)}]]
     
    Test (yaml.test):
     
    769,785d768
    < test yaml-21.1 "explicit_tags float" -body {
    <     set y {!!float 123}
    <     yaml::yaml2dict $y
    < } -result {123.0}
    < 
    < 
    < test yaml-21.2 "explicit_tags float" -body {
    <     set y {!!float 123.0}
    <     yaml::yaml2dict $y
    < } -result {123.0}
    < 
    < 
    < test yaml-21.2 "explicit_tags float" -body {
    <     set y {!!float 123_0}
    <     yaml::yaml2dict $y
    < } -result {expected floating-point number but got "123_0"} -returnCodes error
    <
    
  5. foundin changed to: "0.3.10"
  6. is_private changed to: "0"
  7. login: "peterlewerin"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "ed370a9a39466fe318de149a10eda29075002199"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "peterlewerin"
  14. subsystem changed to: "yaml"
  15. title changed to: "Support for !!float tag"
  16. type changed to: "Patch"