Description
Description
Current parse
function requires full context to complete successfully. It needs to know about declared function
s and name
s.
I would like to be able to parse the nodes without those details. I have 2 use case for this:
- Execute the expression in another engine such a JavaScript directly in the browser
- Validate certain properties for a given expression, for instance that
is_granted()
receives 2 arguments
From my understanding, the parser need to be updated to avoid throwing on the following lines:
Alternatively it could be possible to code my own parser based on the existing one, but it cannot be overridden:
Implementation
About the implementation, I guess that a parseWithoutContext(TokenStream $stream)
function could be the easier, it would just update an internal flag such as the current lint
flag and will use this flag during function
/ name
resolution.
Example
The following code would then be valid and its results could be used to construct what I want to achieve.
$parsed = (new ExpressionLanguage())->parseWithoutContext('is_granted("ROLE_EDIT", subject)');
//^ Symfony\Component\ExpressionLanguage\ParsedExpression {#1213 ▼
// #expression: "is_granted("ROLE_EDIT", subject)"
// -nodes: Symfony\Component\ExpressionLanguage\Node\FunctionNode {#1214 ▼
// +nodes: array:1 [▼
// "arguments" => Symfony\Component\ExpressionLanguage\Node\Node {#1217 ▼
// +nodes: array:2 [▼
// 0 => Symfony\Component\ExpressionLanguage\Node\ConstantNode {#1215 ▼
// +nodes: []
// +attributes: array:1 [▼
// "value" => "ROLE_EDIT"
// ]
// -isIdentifier: false
// }
// 1 => Symfony\Component\ExpressionLanguage\Node\NameNode {#1216 ▼
// +nodes: []
// +attributes: array:1 [▼
// "name" => "subject"
// ]
// }
// ]
// +attributes: []
// }
// ]
// +attributes: array:1 [▼
// "name" => "is_granted"
// ]
// }
//}
// Analyze the above output as an AST
// Dump the above output to evaluate it somewhere else