Open kootenpv opened 2 years ago
Could you point out where this is described in the official spec?
The spec is https://yaml.org/spec/1.2.2. Your link is an old draft proposal which has been abandoned since 17 years ago and has never made it into a spec. I don't think I would want to implement such drafts.
As far as I can tell, § 10.3.2 "Tag Resolution" is what defines what is a valid integer. It says:
[-+]? [0-9]+
(base 10)0o [0-7]+
(base 8)0x [0-9a-fA-F]+
(base 16)where none of those mentions _
.
Oh my bad, I indeed thought I had read it somewhere but had not realized it was a draft.
All Python versions have implemented it which added extra confidence to it being official.
I just checked, also js-yaml
in nodejs reads integer numbers with underscore.
Underscores are not part of yaml 1.2 !!int
tag resolution.
My suggestion would be to not match them by default (if you are claiming to be a YAML 1.2 framework).
But also to support an option allowing them for compatibility (if you want to, your call).
Would love to see this feature added. We tend to have large numbers in our config for configuring various limits, and visually parsing through a chain of 8 zeros without separators is rather error prone unless one is being careful. Although this isn't in the yaml spec, the feature is found in many yaml libraries.
If you're concerned about strict adherence to the spec, perhaps this could be implemented behind a feature flag?
The official yaml spec allows underscores in integers (for readability), would there be a way to achieve this in
serde_yaml
too?