What steps will reproduce the problem? 1. insert the following yaml document into http://instantyaml.appspot.com/
a: 8e-06 b: 8.e-06
What is the expected output? What do you see instead?
8e-06 is parsed as a string, contrary to yaml 1.2 (it was somewhat unclear for yaml 1.1) Please see Jesse Beder's response in: http://stackoverflow.com/questions/6769292/yaml-scientific-notation-syntax
yaml 1.2 uses the regexp: [-+]? ( . [0-9]+ | [0-9]+ ( . [0-9]* )? ) ( [eE] [-+]? [0-9]+ )?
while it's possible 1.1 may be: [-+]?([0-9][0-9_])?.[0-9.]([eE][-+][0-9]+)?
which requires the decimal.
I was able to work around this in my project, but the base of the problem was that I was trying to use a yaml output which used yaml-cpp which does 1.2 and then trying to use snakeyaml to input it, and it was failing to parse the string with certain numbers that happened very infrequently.
Comment #1
Posted on Jul 25, 2011 by Massive RhinoIndeed, it looks like a bug in the YAML 1.1 specification. Jesse Beder gave a very helpful answer. It is really useful. I see now problem areas in the YAML 1.2 specification. For instance if a value starts with '+' then a JSON parser will create a string while the YAML 1.2 parser should create a float. Since YAML 1.2 is a superset of JSON it does not lead to inconsistency but it will cause some misunderstanding. I do not see a problem to fix this in the coming 1.9 release.
Comment #2
Posted on Jul 25, 2011 by Massive Rhinoa few questions on the way to implement the fix: 1) what should be the class of the result '8e+08' ? Double ? Integer (or BigInteger if Integer or Long do not fit). I think 'e' must always require a Double. 2) normal integers match the regular expression for floats in the YAML 1.2 specification. It means that integers must be matched always first. I think they shall fix the regular expression for floats in YAML 1.2
Comment #3
Posted on Jul 26, 2011 by Massive RhinoFixed. The fix will be delivered in version 1.9
Wiki updated: http://code.google.com/p/snakeyaml/wiki/Documentation#Deviation_from_PyYAML
Status: Fixed
Labels:
Type-Enhancement
Priority-Medium