Re: Access to syntax tree?
| From: | Greg Beaver | Date: | Thu, 26 Mar 2009 13:52:35 +0000 |
| Subject: | Re: Access to syntax tree? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-43487@lists.php.net to get a copy of this message | ||
Jeremy wrote:
> Is there any way to access the parse tree of a PHP file from within PHP?
>
> I'm trying to write a code-checking utility to find namespace-related
> problems in code and alert me to them. Specifically:
>
> namespace foo\bar;
>
> function foobar()
> {
> try
> {
> ...
> }
> catch(Exception $e)
> {
> //nothing will be caught
> //I forgot to qualify
> //code silently fails
> }
> }
>
> I didn't want to put a whole lot of work into this, so I'm trying to
> avoid having to write in C/flex/ANTLR/etc. There's a bit of
> grease-monkey internals stuff in PHP so I thought I would check.
Hi Jeremy,
The parser file needs to be updated to reflect additions in PHP 5.3, but
http://pear.php.net/PHP_Parser provides an example of a
parser in which
you could actually check for every class reference at parse-time,
ignoring everything else.
It's built using the tokenizer extension as a lexer, and a port of lemon
to PHP for the parser (zend_language_parser.y is also ported into lemon
format)
Greg