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] Add a way to hook on each node when dumping the AST #19060

Merged
merged 1 commit into from Jun 15, 2016

Conversation

nicolas-grekas
Copy link
Member

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).

@@ -330,7 +330,7 @@ public function parsePostfixExpression($node)
throw new SyntaxError('Expected name', $token->cursor);
}

$arg = new Node\ConstantNode($token->value);
$arg = new Node\NameNode($token->value);
Copy link
Member Author

Choose a reason for hiding this comment

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

The AST is more correct when using NameNode instead of ConstantNode for representing GetAttrNode::PROPERTY_CALL and GetAttrNode::METHOD_CALL (but keep ConstantNodefor GetAttrNode::ARRAY_CALL).
This is enlighten by the "unescaping" (this trim) that was required otherwise when dumping a GetAttrNode.

Copy link
Member

Choose a reason for hiding this comment

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

I tend to agree that this semantically more correct. Is it a BC break? I don't think so.

Copy link
Member

Choose a reason for hiding this comment

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

Yes it's a BC break. I created a melody script to reproduce it.

@fabpot it's because of this change your gist your sent me yesterday does not work anymore.

Copy link
Member

Choose a reason for hiding this comment

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

Arf, any change is a BC break after all :)

Copy link
Member

Choose a reason for hiding this comment

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

So, we need to revert this change, that's two issues as of now.

Copy link
Member

Choose a reason for hiding this comment

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

reverted now

}
array_shift($tokens);
Copy link
Member

Choose a reason for hiding this comment

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

isn't it better to add the , token after each pair, and to pop the last one here ? It would avoid having to reindex the 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.

fixed

@@ -27,12 +27,14 @@ public function compile(Compiler $compiler)

public function dump()
{
$str = '';
$tokens = array();
Copy link
Member

Choose a reason for hiding this comment

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

Token has another meaning in the component, so we need to use something else.

@fabpot
Copy link
Member

fabpot commented Jun 15, 2016

You should also add a phpdoc to the dump() method on Node at least for the return value.

@fabpot
Copy link
Member

fabpot commented Jun 15, 2016

And I think that the dump() method on Nodes should be changed to something else as I would expect a dump method to return a string, not an array.

@nicolas-grekas
Copy link
Member Author

Comments addressed, dump() renamed to toArray()

@fabpot
Copy link
Member

fabpot commented Jun 15, 2016

👍

@fabpot
Copy link
Member

fabpot commented Jun 15, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 66d23db into symfony:master Jun 15, 2016
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
@nicolas-grekas nicolas-grekas deleted the es-dump branch June 15, 2016 16:40
fabpot added a commit that referenced this pull request Sep 21, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

[ExpressionLanguage] fixed a BC break

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | fixes a BC break :)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | see #19060 (comment)
| License       | MIT
| Doc PR        | n/a

Commits
-------

b00930f [ExpressionLanguage] fixed a BC break
@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.

None yet

5 participants