-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ExpressionLanguage] Lexer should provide expression information #19449
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] Lexer should provide expression information #19449
Conversation
k0pernikus
commented
Jul 27, 2016
•
edited
Loading
edited
Q | A |
---|---|
Branch? | 2.7. |
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | symfony suite did not fully pass locally out of the box, ./phpunit src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php passes |
Fixed tickets | #19445 |
License | MIT |
Doc PR | does not apply |
@@ -1,3 +1,4 @@ | |||
auth.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be in the project gitignore. It is not projct-specific (btw, composer will never write in this file by default as it writes auth in the global file).
If you really want to use a local credential file, use a gitignore rule specific to your computer: https://help.github.com/articles/ignoring-files/
This is not the only place where we throw a SyntaxError. Instead of adding sprintf everywhere, I suggest making the expression an optional argument of the SyntaxError constructor so that it handles it internally (as done for the cursor) |
@stof I have updated the pull request accordingly to your findings :) |
@@ -87,15 +87,16 @@ public function tokenize($expression) | |||
$cursor += strlen($match[0]); | |||
} else { | |||
// unlexable | |||
throw new SyntaxError(sprintf('Unexpected character "%s"', $expression[$cursor]), $cursor); | |||
$message = sprintf('Unexpected character "%s"', $expression[$cursor]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the $message
variable, as done before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be fixed
@k0pernikus we have more places throwing a SyntaxError in the component. Please add the expression in them too whenever possible |
@stof Will do. I keep you updated. |
Status: needs work |
@k0pernikus Any news? Do you have time to finish this PR? |
@fabpot Sorry for late reply. I try to look into this during this weekend and provide feedback. |
@fabpot I took a look and I know again why I stopped my progress: I have a hard time understanding what's going on in the nested if-statements of the Parser and why at a certain point the exception is thrown. This is related to @stof wish to have the expression "whenever possible", yet that's not clear for me to see. Currently, I also have a time issue and won't be able to invest too much in here right now. Maybe at the end of December or in the beginning of January. As my pull request fixes the issue I was having in the first place, may I kindly ask to merge my pull request and open a follow-up ticket pertaining the other cases where the exception is thrown without providing clear feedback? |
parent::__construct(sprintf('%s around position %d.', $message, $cursor)); | ||
$message = sprintf('%s around position %d', $message, $cursor); | ||
if ($expression) { | ||
$message = sprintf('%s for expression "%s"', $message, $expression); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using backticks rather than quotes to encore the expression, because quotes can appear inside the expression itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Closing in favor of #22229 where I applied the necessary changes on top of your commit. |
…rs (k0pernikus, stof) This PR was merged into the 2.7 branch. Discussion ---------- [ExpressionLanguage] Provide the expression in syntax errors | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19445 | License | MIT | Doc PR | n/a This finishes the PR #19449. Commits ------- 7cd7441 Complete the injection of the expression in all syntax errors dc55db2 add expression text to SyntaxError