Hello,
I'm trying to alter existing PHP code by transforming its AST. From what
I've read, the Zend Engine does a one-pass compile and thus offers no way to
access the AST. (Whether this is a good or a bad idea doesn't really matter
at this point, so let us stay away from that discussion for now.)
Other possible solutions I've come across are phc [1], rphp [2] and PHP
Depend [3]. Unfortunately, the first does not support PHP 5.3, the second is
still in a very early stage of development and the third does not allow
'unparsing' and is not particularly fast either (which is only a minor
concern, but still).
The last idea I had was approaching this from the Java side and use the
parser that comes with PDT [4] or PHPEclipse [5], but I haven't yet figured
out how to do this yet, and I'm not even entirely sure if this can be done
outside of Eclipse (of course it should, but who knows).
As you can see, I haven't really found a satisfactory solution yet, so any
help is appreciated.
regards
raph
[1] http://phpcompiler.org/
[2] http://code.roadsend.com/rphp/
[3] http://pdepend.org/
[4] http://www.eclipse.org/pdt/
[5] http://www.phpeclipse.com/
Am 02.12.2009 18:35, schrieb Raphael Pigulla:
As you can see, I haven't really found a satisfactory solution yet, so any
help is appreciated.
pecl/parse_tree (if it (still) works) provides access to the parse tree
of PHP code in the form of XML. The XML can be manipulated and then
transformed back into PHP code.
What kind of AST transformations are you thinking about?
--
Sebastian Bergmann Co-Founder and Principal Consultant
http://sebastian-bergmann.de/ http://thePHP.cc/
pecl/parse_tree (if it (still) works) provides access to the parse
tree of PHP code in the form of XML. The XML can be manipulated and
then transformed back into PHP code.
PECL::Parse_Tree is still in alpha state and has not been updated since
January 2007, so I don't have too much confidence in it being 5.3 compliant.
For now I've opted to approach this from the Java side using DLTK and
PDT which is very powerful and fast. Plus, it is my hope that - PDT
being a widely used PHP IDE and all - the parser will always be fairly
up to date.
What kind of AST transformations are you thinking about?
At this point it's only a little side project. Eventually, I hope to
build some sort of PHP precompiler for our CI server that can help us
with QA and such (e.g., checking pre- and postconditions). It is in a
way very similar to AspectPHP, but may very well go beyond what is
possible with AOP (at the cost of being not as flexible, obviously). But
again, this project is still in a very early stage; I'm just writing the
very first prototype to see how far DLTK can take me.
regards
Raphael