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: 2021-11-18 18:17 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: Suspended Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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
 [2021-11-18 18:17 UTC] cmb@php.net
-Status: Verified +Status: Suspended
 [2021-11-18 18:17 UTC] cmb@php.net
Bundling nikic/php-ast (or any other external extension for that
matter) requires an RFC.  Anybody is welcome to pursue the RFC
process[1].  For the time being, I suspend this ticket.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 17:01:30 2024 UTC