Skip to content
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

[ExpressionLanguage] Document precedence #19803

Closed
homersimpsons opened this issue Apr 18, 2024 · 8 comments · Fixed by #19860
Closed

[ExpressionLanguage] Document precedence #19803

homersimpsons opened this issue Apr 18, 2024 · 8 comments · Fixed by #19860
Labels
ExpressionLanguage hasPR A Pull Request has already been submitted for this issue.

Comments

@homersimpsons
Copy link
Contributor

Current status

The page https://symfony.com/doc/current/reference/formats/expression_language.html#supported-operators does not document operators precedence.

Objective

Add documentation about operators precedence.

Why?

Today I wanted to check the precedence of some operator in order to update a code, I had an expression that could translate to the following ambiguity:

var_dump(! null === false); // => ((!null) === false) => false
var_dump(! (null === false)); // => true

We can find the precedence in https://github.com/symfony/expression-language/blob/b8ec919a6d3d47fc4e7845c256d164413207bf73/Parser.php#L24

I think that this information should be accessible in the doc directly, but I understand that it won't benefit a lot of users so I'm wondering how it should be presented. Maybe just a collapsible array at the end, or when the precedence is mentioned in:

You must use parentheses because the unary operator not has precedence over the binary operator matches.

@94noni
Copy link
Contributor

94noni commented Apr 19, 2024

A note block could be added and document this internal behavior i think yes 👍🏻

homersimpsons added a commit to homersimpsons/symfony-docs that referenced this issue May 3, 2024
homersimpsons added a commit to homersimpsons/symfony-docs that referenced this issue May 3, 2024
@OskarStark
Copy link
Contributor

I really like this note and we should merge it. However, what about a debug command? We have the same for listener priorities

@homersimpsons
Copy link
Contributor Author

However, what about a debug command?

I'm not sure to understand, there is no command for symfony's expression language, right?

@OskarStark
Copy link
Contributor

Yes, I would propose to create one

@homersimpsons
Copy link
Contributor Author

What would be the purpose of such command? How do you see its interface?

@OskarStark
Copy link
Contributor

I would output the list from the docs PR, if we can get the info programmatically

@javiereguiluz javiereguiluz added the hasPR A Pull Request has already been submitted for this issue. label May 9, 2024
@homersimpsons
Copy link
Contributor Author

I would output the list from the docs PR, if we can get the info programmatically

Yes we can definitely get it programatically rather easily (minus some formating / arranging).

The repo does not have a dependency on the console component, I'm not exactly sure how to approach this. Another command I can think of would be an easy "debug" command where someone could provide an expression (and possibly variables) and get the result.

@javiereguiluz
Copy link
Member

Given that the list of operators is very rarely updated, I'd just handle this manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExpressionLanguage hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants