Multiple use of ast node in parser
| From: | Christian Schneider | Date: | Wed, 17 Oct 2018 11:59:28 +0000 |
| Subject: | Multiple use of ast node in parser | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-103325@lists.php.net to get a copy of this message | ||
I'm playing around with some syntactic sugar for PHP and when trying to implement
:$foo
as equivalent for
'foo' => $foo
I ran into the problem of having only having one ast node but trying to use it twice.
My first attempt was
| ':' T_VARIABLE
{ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, zend_ast_create(ZEND_AST_VAR, $2), $2); }
but that results in corrupted memory because of the double usage.
Trying something like
| ':' T_VARIABLE
{ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, zend_ast_create(ZEND_AST_VAR,
GC_AST(zend_ast_copy($2))), $2); }
works but leaks memory because the copied ast is not freed.
Is there a proper way to do something like this ast transformation inside the parser?
Regards,
- Chris