php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72559 Function to returns the PHP AST
Submitted: 2016-07-07 21:30 UTC Modified: 2016-07-13 01:44 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: david dot proweb at gmail dot com Assigned:
Status: Verified Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: david dot proweb at gmail dot com
New email:
PHP Version: OS:

 

 [2016-07-07 21:30 UTC] 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;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-07 21:37 UTC] stas@php.net
-Package: PHP Language Specification +Package: *General Issues
 [2016-07-08 06:15 UTC] 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-13 01:42 UTC] 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-13 01:44 UTC] kalle@php.net
-Status: Open +Status: Verified
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC