Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[ExpressionLanguage] Added a way to dump the AST #19013

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
Jun 13, 2016
Merged

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Jun 9, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

Because it's convenient and it makes easier to inline results of sub/smaller part of the main expression.

$str .= sprintf('%s, ', $pair['value']->dump());
}

$str = rtrim($str, ', ');
Copy link
Member

Choose a reason for hiding this comment

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

you can return here directly (same everywhere)

@stof
Copy link
Member

stof commented Jun 9, 2016

Cannot be accepted without tests

@lyrixx
Copy link
Member Author

lyrixx commented Jun 10, 2016

I addressed your comments, and I added some tests.

@lyrixx lyrixx changed the title [ExpressionLanguage] Added a way to dump AST [ExpressionLanguage] Added a way to dump the AST Jun 10, 2016

foreach ($this->getKeyValuePairs() as $pair) {
$key = $pair['key']->attributes['value'];
if (!is_int($key)) {
Copy link
Member

Choose a reason for hiding this comment

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

when int keys are used but not in numerical order, this won"t work, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see why it would not work. but if it's the case, how could I fix it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@lyrixx lyrixx force-pushed the el-dump branch 2 times, most recently from 2dbc349 to 23a5c66 Compare June 10, 2016 15:24

protected function dumpEscape($value)
{
return str_replace(['\\', '"'], ['\\\\', '\"'], $value);
Copy link
Member

Choose a reason for hiding this comment

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

array(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed another one too, and added more tests. RFR ;)

@nicolas-grekas
Copy link
Member

👍

public function dump(ParsedExpression $expression)
{
return $expression->getNodes()->dump();
}
Copy link
Member

Choose a reason for hiding this comment

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

I would remove this method and add a dump() method on ParsedExpression instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

@fabpot I addressed your comments.


public function dump()
{
return sprintf('<Dumping a "%s" instance is not supported yet>', get_class($this));
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to just throw an exception here? As the dumped expression is not usable anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know. It was easier to be able to see a "preview" while developing than an exception.
But indeed, as the expression is not valid, let throw an expression. (done)

@@ -75,4 +75,27 @@ public function evaluate($functions, $values)

return $results;
}

public function dump()
Copy link
Member

Choose a reason for hiding this comment

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

You should add a phpdoc here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Other public method don't have PHPDoc... So it tried to be consistent here ;)

@fabpot
Copy link
Member

fabpot commented Jun 13, 2016

Thank you @lyrixx.

@fabpot fabpot merged commit 87af6e5 into symfony:master Jun 13, 2016
fabpot added a commit that referenced this pull request Jun 13, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

[ExpressionLanguage] Added a way to dump the AST

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Because it's convenient and it makes easier to inline results of sub/smaller part of the main expression.

Commits
-------

87af6e5 [ExpressionLanguage] Added a way to dump AST
@lyrixx lyrixx deleted the el-dump branch June 13, 2016 12:21
fabpot added a commit that referenced this pull request Jun 15, 2016
…en dumping the AST (nicolas-grekas)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[ExpressionLanguage] Add a way to hook on each node when dumping the AST

| Q             | A
| ------------- | ---
| Branch?       | "master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19013
| License       | MIT
| Doc PR        | -

This is an iteration over #19013 to allow writing dumpers that can decorate dumps (e.g. add HTML tags based on each node type to do syntax highlighting).

Commits
-------

66d23db [ExpressionLanguage] Add a way to hook on each node when dumping the AST
@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.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.