Given these lines of YAML:
version: 1.00
y: 1
What does this represent?
According to the YAML spec (I'm not a delicate enough to read the spec like a lawyer), does this necessarily represent that a key str("version")
maps to a value float(1.0)
, and a key bool(true)
maps to a value int(1)
? Or is it up to the parser to decide whether 1.0
should be a float or a str?
As these two lines obviously suggest, version: 1.0
should really be parsed as a string not as a number. And y: 1
might actually mean a Y-coordinate rather than a boolean true. This is a common pitfall in YAML config files.
So a co-worker suggested to write a parser that parses a YAML file based on a user-given data structure (like the Go unmarshal libraries) rather than based on the type inferred from the YAML code. I opposed because I think this kind of parsing would violate the YAML specification, making the YAML file no longer "real YAML".
An immediate consequence (if I interpret the YAML spec correctly) is that, suppose someone made an interactive GUI editor for YAML files (maybe it's something like Windows regedit
), the editor would parse the above YAML code as version: 1.00
a float, then emit it back as 1.0
, leading to inconsistent data. If my understanding on YAML spec is correct, the editor does not make incorrect assumptions on the information carried by the YAML code, so the editor isn't doing anything wrong; and the user is just following our so-called YAML standard (and hence believe that it is standard YAML, and the editor is also following standard YAML), so the responsibility would be in us (not the user, not the editor). Therefore I oppose to this custom parser.
Am I correct? If I am correct, how should I convince that he is wrong? If I am incorrect, how to explain this scenario? (Please convince me, because we're getting a bit heated)
(DO NOT TURN THIS INTO AN XY QUESTION. We all know that YAML has problems, but let's assume we can't change to another format to prevent off-topic)
(Context: we are working on an open-source project which has users from different levels of the education spectrum)