Skip to content

[ExpressionLanguage] Add support for <<, >>, and ~ bitwise operators #58052

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
Aug 22, 2024

Conversation

alexandre-daubois
Copy link
Member

@alexandre-daubois alexandre-daubois commented Aug 21, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

In order to fully support this idea, I suggest adding to ExpressionLanguage the 3 currently missing bitwise operators, namely left shift, right shift and binary not.

use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

require 'vendor/autoload.php';

$el = new ExpressionLanguage();

$el->evaluate('1 << 4'); // 16
$el->evaluate('32 >> 4'); // 2
$el->evaluate('~5'); // -6

@fabpot
Copy link
Member

fabpot commented Aug 21, 2024

What's the use case?

@alexandre-daubois
Copy link
Member Author

alexandre-daubois commented Aug 21, 2024

The idea it to have all necessary tools to deal with bitfields in expression language. That would allow for example to use bitfields in YAML files thanks to expressions. This is based on an idea from Nicolas, especially for the "binary not".

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Given that we already support other binary operators like & and |, I'm fine with adding those operators, even if it's only for the sake of completeness.

@nicolas-grekas
Copy link
Member

Thank you @alexandre-daubois.

@nicolas-grekas nicolas-grekas merged commit b3d9138 into symfony:7.2 Aug 22, 2024
7 of 10 checks passed
nicolas-grekas added a commit that referenced this pull request Sep 28, 2024
This PR was merged into the 7.2 branch.

Discussion
----------

[ExpressionLanguage] Use script to generate regex

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | maybe?
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Fixes/uses the `generate_operator_regex.php` script for the regex added in #58052

Commits
-------

3fc2f3b [ExpressionLanguage] Use script to generate regex
@fabpot fabpot mentioned this pull request Oct 27, 2024
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