Req #72559 [Opn->Ver]: Function to returns the PHP AST
| From: | kalle@php.net | Date: | Wed, 13 Jul 2016 01:44:07 +0000 |
| Subject: | Req #72559 [Opn->Ver]: Function to returns the PHP AST | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202263@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72559&edit=1
ID: 72559
Updated by: kalle@php.net
Reported by: david dot proweb at gmail dot com
Summary: Function to returns the PHP AST
-Status: Open
+Status: Verified
Type: Feature/Change Request
Package: *General Issues
PHP Version: Irrelevant
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2016-07-13 01:42:08] kalle@php.net
I think this could be a great addition to the already existing tokenizer extension in the core,
since it conceptially operates in a very similar way, perhaps indeed by merging @nikic's
php-ast into it.
------------------------------------------------------------------------
[2016-07-08 06:15:00] requinix@php.net
@nikic has an "experimental" extension for this <https://github.com/nikic/php-ast> and there's a
draft RFC about getting it (or some derivative version of it, or something like it) into PHP <https://wiki.php.net/rfc/parser-extension-api>.
------------------------------------------------------------------------
[2016-07-07 21:30:16] david dot proweb at gmail dot com
Description:
------------
Currently, PHP have a function that returns the TOKENs of language (token_get_all), but if you wants
to read AST, you should use some package like nikic/php-parser, and it have some specific problems:
1. It's slower than PHP AST because it reprocess code and implements it own lexer;
2. It should be updated together of PHP (currently not is a great problem because is very active);
It should be done by own PHP, because it have all process that allows does that (I guess). Basically
need some code to allow read it by code.
But need some considerations:
It should not implements a lot of classes, onde for each AST key. It should send raw parameters data
to a processor that will decides how it will be parsed. Basically, I think that a raw array can
solve that.
Example:
echo "Hello", "World";
Hello\World('Foo', 'Bar' . 'Baz');
Expectative:
Note: simple values can stays as literals, array should specify the object key type (maybe the
biggest problem).
[
[
'key' => 'echo',
'exprs' => [
'Hello',
'World'
]
],
[
'key' => 'functionCall',
'name' => [
'hello',
'world'
],
'args' => [
'Foo',
[
'key' => 'concatenate',
'values' =>
[
'Bar',
'Baz',
]
]
]
]
]
And some limitations:
It'll be PHP version dependent, it is, if I try to parse a 4.x PHP code it'll be
impossible because of the PHP 7.1 code compatibility, in this case, the package can work on a
polyfill. In same circunstancies, could be impossible, on PHP 7.1, parses a code fom PHP 7.2, so,
polyfills too can solve that;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72559&edit=1