Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

javiereguiluz
Copy link
Member

@javiereguiluz javiereguiluz commented Apr 24, 2017

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.

use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

$language = new ExpressionLanguage();
$ast = $language->dump('1 + 2');
Copy link
Member

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());

Copy link
Member Author

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

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

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

Choose a reason for hiding this comment

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

same here

@xabbuh
Copy link
Member

xabbuh commented May 12, 2017

Thank you Javier.

xabbuh added a commit that referenced this pull request May 12, 2017
…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
@xabbuh xabbuh closed this May 12, 2017
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.

3 participants