Overview
Artifact ID: | 3b011aa942271c583c059fac5b13b15e13c85a7798755cf8cf44b6ca5fce4d18 |
---|---|
Ticket: | 8659a16544549c77b75eb624d109985576af7cb3
Support for !!float tag |
User & Date: | peterlewerin 2017-10-20 08:29:57 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- 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 <
- foundin changed to: "0.3.10"
- is_private changed to: "0"
- login: "peterlewerin"
- priority changed to: "5 Medium"
- private_contact changed to: "ed370a9a39466fe318de149a10eda29075002199"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "peterlewerin"
- subsystem changed to: "yaml"
- title changed to: "Support for !!float tag"
- type changed to: "Patch"