forked from symfony/symfony-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 3.2: (39 commits) updating instance Avoid backticks in shell scripts Update optional_dependencies.rst Fix xml blocks pass only strings to loadUserByUsername() Fix Authenticator Class (getCredentials) example Documented addAnnotatedClassesToCompile() and the use of class patterns Added the picture that shows how GuardAuthenticationListener calls Authentication Guard methods. [symfony#7205] minor tweak Simplified the use of transChoice() [symfony#7875] minor tweaks Minor fix Minor changes Properly show all events and describe guard events [symfony#7891] remove not needed sentence [symfony#7773] fix line length Add helpful remarks on custom DataCollector Remove use of deprecated security.exception_listener.class parameter Update resources.rst Fix incoherent ut8mb4 collation in Doctrine setup ...
- Loading branch information
Showing
101 changed files
with
1,250 additions
and
545 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.. index:: | ||
single: AST; ExpressionLanguage | ||
single: AST; Abstract Syntax Tree | ||
|
||
Dumping and Manipulating the AST of Expressions | ||
=============================================== | ||
|
||
Manipulating or inspecting the expressions created with the ExpressionLanguage | ||
component is difficult because they are plain strings. A better approach is to | ||
turn those expressions into an AST. In computer science, `AST`_ (*Abstract | ||
Syntax Tree*) is *"a tree representation of the structure of source code written | ||
in a programming language"*. In Symfony, a ExpressionLanguage AST is a set of | ||
nodes that contain PHP classes representing the given expression. | ||
|
||
Dumping the AST | ||
--------------- | ||
|
||
Call the :method:`Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::getNodes` | ||
method after parsing any expression to get its AST:: | ||
|
||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; | ||
|
||
$ast = (new ExpressionLanguage()) | ||
->parse('1 + 2') | ||
->getNodes() | ||
; | ||
|
||
// dump the AST nodes for inspection | ||
var_dump($ast); | ||
|
||
// dump the AST nodes as a string representation | ||
$astAsString = $ast->dump(); | ||
|
||
Manipulating the AST | ||
-------------------- | ||
|
||
The nodes of the AST can also be dumped into a PHP array of nodes to allow | ||
manipulating them. Call the :method:`Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::toArray` | ||
method to turn the AST into an array:: | ||
|
||
// ... | ||
|
||
$astAsArray = (new ExpressionLanguage()) | ||
->parse('1 + 2') | ||
->getNodes() | ||
->toArray() | ||
; | ||
|
||
.. _`AST`: https://en.wikipedia.org/wiki/Abstract_syntax_tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.