Hi Flavius!

I am working on PHP Parser in user land code
(https://github.com/nikic/PHP-Parser), which currently has
capabilities to parse PHP 5.3 into an AST and compile the nodes back
to PHP source.

>From my experience in building it, some notes:

First, you seem to try to lex the PHP code yourself too. Why don't you
use PHP's internal lexing capabilities? (Like token_get_all does.) PHP
is a hard to lex language (with all it's special encapsed string and
heredoc syntaxes) and PHP's own lexer
(http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_scanner.l) is
something like two and a half thousand lines long.

Second, you seem to try to parse PHP using your own grammar. From my
experience, the PHP grammar
(http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y) is
really messed up and it's already quite hard to strictly adhere to
that grammar (as it has lots of strange quirks) and make it AST-able.
If you write up your own grammar I doubt that it will ever match the
PHP grammar. I think you should stick as much as possible to the PHP
grammar and only introduce changes where required. (The grammar I use
(https://github.com/nikic/PHP-Parser/blob/master/grammar/zend_language_parser.phpy)
is already made AST-able, though some quirks in the language required
me to do brain-transplantation at one point.) For example you already
have at least one error in the little grammar you have: The opening
and closing tags should be filtered away before being passed to the
parser as the may occur anywhere, even in the middle of an expression
(`echo $hi . ?><?php $hi;` is valid).

On Sat, Sep 3, 2011 at 11:21 PM, Flavius Aspra <flavius...@gmail.com> wrote:
> Hi
>
> I'm Flavius Aspra and over the past weeks [1] I've worked on a small
> extension, which I think it has a lot of potential. Thanks to everyone
> for being patient with me on #php.pecl during this time - I've learned a
> lot!
>
> Meta will enable userland scripts to get the AST of a PHP source code,
> to manipulate it, and if desired, to serialize it back to valid PHP code.
>
> The current status is "not really usable", but it has already reached
> around 2k LOCs and I think it's easier for you to review it now, than later.
>
> The code is still hosted on github, please let me know what needs to be
> done to make it PECL-compatible. Advices, bug fixes and improvements are
> welcome. Pending TODOs are listed inline, in the code, as they fit, and
> longer-term TODOs are in TODO.txt.
>
> I've already asked for a first thought on IRC, and people seem to see
> the need for this extension.
>
> The project's page is at [2], it's called "phpmeta" there, so no
> confusion arises. The extension is simply called "meta". Many other
> details can be found in the README. Feel free to ask me anything.
>
> [1] Actually, I wanted to work on this for GSoC, but I was a little bit
> late, so I've worked on it in my spare time
> [2] https://github.com/OriginalCopy/phpmeta
>
> Cheers,
> Flavius

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to