Skip to content

[Yaml] Allow using _ in some numeric notations #18096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Taluu
Copy link
Contributor

@Taluu Taluu commented Mar 10, 2016

Q A
Branch 2.3
Bug fix? no ?
New feature? yes ?
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #18094
License MIT
Doc PR ~

Allows to use the _ to group "big" ints, as suggested in the yaml integer type specification. As discussed in #18094, we should check if it is still part of the 1.2 specification, but I don't really see why not ? I can't see anywhere anything saying it is not valid anymore... as there are links to these types in some other specs.

@Taluu
Copy link
Contributor Author

Taluu commented Mar 10, 2016

It seems that binaries too should accept this, but as on 2.3 it is not handled (maybe on master though ? as the binary notation was introduced on php 5.4

@nicolas-grekas
Copy link
Member

Leading _ shouldn't parsed as numbers but this PR does, isn't it?

@Taluu
Copy link
Contributor Author

Taluu commented Mar 15, 2016

Indeed. I'll fix that then.

return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar;
case '.inf' === $scalarLower:
case '.nan' === $scalarLower:
return -log(0);
case '-.inf' === $scalarLower:
return log(0);
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I saw anywhere that the , was authorized though ? I kept it, but nothing in the specs says it should be used as a separator (And as @nicolas-grekas noticed, _123_456_ should not be a valid number, so shouldn't ,123,456, be also considered invalid or a string ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check with a reference parser, e.g. http://yaml-online-parser.appspot.com/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That tool is awesome, and yes, the , is not allowed as a separator (it renders as string when one is used in a number). I'd rather not touch it, as it would introduce a bc break.

But 123_ seems to be a valid integer too, so I need to keep that (it will simplify some regex)

@xabbuh
Copy link
Member

xabbuh commented Apr 5, 2016

@fabpot @stof What is your opinion on this? I tend to treat it as a bug fix. Though what confuses me is that this only part of the 1.1 spec but is not included in 1.2 (see #18094). On the other hand it looks that mostly all widespread YAML parsers support the underscore as a separation character.

@fabpot
Copy link
Member

fabpot commented Apr 5, 2016

Some thoughts:

  • We explicitly don't support all YAML features, only the ones that makes sense when using YAML as a configuration file format.
  • If this is not supported in 1.2, we don't want to add support for this feature.
  • It looks like a new feature to me.

@stof
Copy link
Member

stof commented Apr 6, 2016

Given that this will change the way we treat the value, I'm against putting this in a patch release, as it might break existing project. This should go in master

@stof
Copy link
Member

stof commented Apr 6, 2016

and the dumper needs to be changed, to detect that a string 123_456 requires to be quoted when being dumped (to avoid being parsed as an integer after that)

@Taluu
Copy link
Contributor Author

Taluu commented Apr 6, 2016

I will rebase this on master then, and fix the dumper

@Taluu
Copy link
Contributor Author

Taluu commented Apr 9, 2016

Closing in favor of #18486

@Taluu Taluu closed this Apr 9, 2016
@Taluu Taluu deleted the fix-yaml-integer-groups branch April 9, 2016 11:05
xabbuh added a commit that referenced this pull request May 14, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

[Yaml] Allow using _ in some numeric notations

| Q             | A
| ------------- | ---
| Branch        | master
| Bug fix?      | no ?
| New feature?  | yes ?
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18094
| License       | MIT
| Doc PR        | ~

Allows to use the `_` to group "big" ints, as suggested in the yaml integer type specification. As discussed in #18094, we should check if it is still part of the 1.2 specification, but I don't really see why not ? I can't see anywhere anything saying it is not valid anymore... as there are links to these types in some other specs.

This is #18096, but targetted on master as this is considered as a new feature. I also support the dump of such values as only strings. I think I should change how it is dumped thoug, and use the escape filter instead though (as I was misusing the data provider and it provided strange results at the time)

Commits
-------

e6da11c [Yaml] Allow using _ in some numeric notations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants