dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
965 stars 164 forks source link

Allow parsing integers containing underscores #242

Open kootenpv opened 2 years ago

kootenpv commented 2 years ago

The official yaml spec allows underscores in integers (for readability), would there be a way to achieve this in serde_yaml too?

dtolnay commented 2 years ago

Could you point out where this is described in the official spec?

kootenpv commented 2 years ago

https://yaml.org/type/int.html

dtolnay commented 2 years ago

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:

where none of those mentions _.

kootenpv commented 2 years ago

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.

ingydotnet commented 2 years ago

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).

jwilm commented 1 year ago

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?