-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added an article about ExpressionLanguage AST #7831
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
Conversation
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; | ||
|
||
$language = new ExpressionLanguage(); | ||
$ast = $language->dump('1 + 2'); |
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.
Hi;
Actually, this method does not exist. You can get the AST like this:
<?php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
$ast = (new ExpressionLanguage())
->parse('var.a.b + 12', ['var'])
->getNodes()
;
dump($ast);
And then you can dump the AST (as a string) dump($ast->dump());
Finally, Instead of getting a string, it's possible to get an array in order to manipulate it: dump($ast->toArray());
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.
Thanks for your help and for the examples! I've updated the article contents.
@@ -0,0 +1,47 @@ | |||
.. index:: | |||
single: AST; ExpressionLanguage |
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 think we should at least add "Abstract Syntax Tree" to the index.
Dumping the AST | ||
--------------- | ||
|
||
Call the ``getNodes()`` method after parsing any expression to get its AST:: |
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.
Use the :method:
role here?
-------------------- | ||
|
||
The nodes of the AST can also be dumped into a PHP array of nodes to allow | ||
manipulating them. Call the ``toArray()`` method to turn the AST into an array:: |
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.
same here
Thank you Javier. |
…uiluz) This PR was squashed before being merged into the 3.2 branch (closes #7831). Discussion ---------- Added an article about ExpressionLanguage AST I need ExpressionLanguage experts to review the first part of the new article and to give me clues about how to write the second part. Thanks! Let's ping some experts in this: @lyrixx and @nicolas-grekas. This fixes #7185. Commits ------- a91a590 Added an article about ExpressionLanguage AST
I need ExpressionLanguage experts to review the first part of the new article and to give me clues about how to write the second part. Thanks!
Let's ping some experts in this: @lyrixx and @nicolas-grekas.
This fixes #7185.