Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

[ExpressionLanguage] Lexer should provide expression information #19449

wants to merge 1 commit into from

Conversation

k0pernikus
Copy link
Contributor

@k0pernikus k0pernikus commented Jul 27, 2016

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
Copy link
Member

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/

@stof
Copy link
Member

stof commented Jul 27, 2016

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)

@k0pernikus
Copy link
Contributor Author

@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]);
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

this should be fixed

@stof
Copy link
Member

stof commented Jul 28, 2016

@k0pernikus we have more places throwing a SyntaxError in the component. Please add the expression in them too whenever possible

@k0pernikus
Copy link
Contributor Author

@stof Will do. I keep you updated.

@nicolas-grekas
Copy link
Member

Status: needs work

@fabpot
Copy link
Member

fabpot commented Nov 10, 2016

@k0pernikus Any news? Do you have time to finish this PR?

@k0pernikus
Copy link
Contributor Author

@fabpot Sorry for late reply. I try to look into this during this weekend and provide feedback.

@k0pernikus
Copy link
Contributor Author

@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);
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@nicolas-grekas nicolas-grekas changed the title Lexer should provide expression information [ExpressionLanguage] Lexer should provide expression information Dec 6, 2016
@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@stof
Copy link
Member

stof commented Mar 31, 2017

Closing in favor of #22229 where I applied the necessary changes on top of your commit.

@stof stof closed this Mar 31, 2017
fabpot added a commit that referenced this pull request Apr 3, 2017
…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
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.

6 participants