Skip to content

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

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

Merged
merged 1 commit into from
May 14, 2016

Conversation

Taluu
Copy link
Contributor

@Taluu Taluu commented Apr 9, 2016

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)

@fabpot
Copy link
Member

fabpot commented Apr 15, 2016

👍

@@ -564,6 +565,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
return;
case 0 === strpos($scalar, '!!float '):
return (float) substr($scalar, 8);
case preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar):
$scalar = str_replace('_', '', (string) $scalar);
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment saying that the fallthrough is intentional, to avoid mistakes in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do as soon as i get my hands on my dev env

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@stof
Copy link
Member

stof commented Apr 15, 2016

👍
Status: reviewed

@nicolas-grekas could you check why a test is failing when removing a folder ?

@nicolas-grekas
Copy link
Member

@stof this issue has already been fixed a few days ago hopefully

@Taluu Taluu force-pushed the yaml-integer-groups branch from 4597c12 to 0f12481 Compare April 18, 2016 08:42
@dunglas
Copy link
Member

dunglas commented Apr 19, 2016

👍

@fabpot
Copy link
Member

fabpot commented Apr 20, 2016

Should be merged when master becomes 3.2.

@@ -584,8 +590,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
return log(0);
case 0 === strpos($scalar, '!!binary '):
return self::evaluateBinaryScalar(substr($scalar, 9));
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
return (float) str_replace(',', '', $scalar);
case preg_match('/^(-|\+)?[0-9][0-9,_]*(\.[0-9_]+)?$/', $scalar):
Copy link
Member

Choose a reason for hiding this comment

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

This will support numbers mixing , and _. I am not convinced we should support that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, removing , (which is not in the yaml spec AFAIK) would be a bc break, so that's why I kept it. Adding a deprecation is also not within the scope of this PR IMO

Copy link
Member

Choose a reason for hiding this comment

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

I agree that the deprecation should be added in a separate PR. But imo we should only support numbers here that contain either commas or underscores:

case preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9]+)?$/', $scalar):
case preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
    // ...

In a new PR we can then add the deprecation trigger after the first case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I can indeed split this case into two cases

Copy link
Member

Choose a reason for hiding this comment

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

Why? Isn't 1_200,2_200 valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you're referring to float, isn't it 1_200.2_200 ? Looking at http://yaml.org/type/float.html, in the regexp there is no , in fact (while there is a _)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I meant 1_200.2_200

Copy link
Contributor Author

@Taluu Taluu Apr 22, 2016

Choose a reason for hiding this comment

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

So yes, we are keeping that, it is just the , that should be deprecated as it's nowhere in the yaml specs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This case was split as suggested

@Taluu Taluu force-pushed the yaml-integer-groups branch from 0f12481 to e6da11c Compare April 22, 2016 09:25
@xabbuh
Copy link
Member

xabbuh commented Apr 22, 2016

👍

@xabbuh
Copy link
Member

xabbuh commented May 14, 2016

Thank you @Taluu.

@xabbuh xabbuh merged commit e6da11c into symfony:master May 14, 2016
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
@Taluu Taluu deleted the yaml-integer-groups branch October 19, 2016 15:53
@fabpot fabpot mentioned this pull request Oct 27, 2016
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.

8 participants