Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43487 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82210 invoked from network); 26 Mar 2009 13:52:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Mar 2009 13:52:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 209.85.146.177 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 209.85.146.177 wa-out-1112.google.com Received: from [209.85.146.177] ([209.85.146.177:32421] helo=wa-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3D/E1-30978-DA88BC94 for ; Thu, 26 Mar 2009 08:52:46 -0500 Received: by wa-out-1112.google.com with SMTP id j40so353242wah.7 for ; Thu, 26 Mar 2009 06:52:43 -0700 (PDT) Received: by 10.114.161.11 with SMTP id j11mr618325wae.65.1238075563060; Thu, 26 Mar 2009 06:52:43 -0700 (PDT) Received: from monster.local ([76.84.30.125]) by mx.google.com with ESMTPS id k14sm203006waf.58.2009.03.26.06.52.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 26 Mar 2009 06:52:42 -0700 (PDT) Message-ID: <49CB88A3.8080501@chiaraquartet.net> Date: Thu, 26 Mar 2009 08:52:35 -0500 User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070807) MIME-Version: 1.0 To: Jeremy CC: internals@lists.php.net References: <14.C2.30978.F466AC94@pb1.pair.com> In-Reply-To: <14.C2.30978.F466AC94@pb1.pair.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: Access to syntax tree? From: greg@chiaraquartet.net (Greg Beaver) 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