Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83106 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16725 invoked from network); 18 Feb 2015 19:22:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 19:22:17 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.160.181 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.160.181 mail-yk0-f181.google.com Received: from [209.85.160.181] ([209.85.160.181:65312] helo=mail-yk0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/F4-25021-866E4E45 for ; Wed, 18 Feb 2015 14:22:17 -0500 Received: by mail-yk0-f181.google.com with SMTP id 200so1820017ykr.12 for ; Wed, 18 Feb 2015 11:22:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=6DoBFXhaDv0DFHcdW8c/c7pELnUq9YFwRng5fXThl9E=; b=gfNfg1TkKNBIfZqtdWQbnLsKnOYQmdfYHh0LnV5d4mSe9Gx/xm3J49AVNiMl3bXO9o lgzag498gMAZ1PGUowZAn4pcgPtJZbXPFhZNRgQejg5eaz2Cib+O8awaFcLxtbVo34Am 9CQnn0+GWNJYN7OJhXBVBRqiR5wKXo+l+BiHUzhkPKQRhRD6J8XElqv48zL7RAm9XgHn QVAJijh4jkhIby/GOMPw0b6YXcS9pZr0a4kEA8do0A1/xs1dm2HxCLjJyL8lzoNvl+2D uJwsfKKjjrqQJRe1CRoAS5j4iNShab5aq2h6n1C31zS+KSZJluIamoTZCbVNHRjOllqC rLhw== X-Gm-Message-State: ALoCoQlxnkhupSL064C9JZyDKGKNOjGLv4pm6lQyeH8MLduLF2fUtjNLdeL0CV0ak0SmAHEbZKXAAPwBqwHE4/GykHRrbfbfhXyJfiepiJbBusp5glHbTr92jRdkpVMFCc4THKQw5fe2QJRbNXatYPCRmpvAWkUyMg== MIME-Version: 1.0 X-Received: by 10.52.25.11 with SMTP id y11mr439720vdf.51.1424287333884; Wed, 18 Feb 2015 11:22:13 -0800 (PST) Received: by 10.52.74.73 with HTTP; Wed, 18 Feb 2015 11:22:13 -0800 (PST) In-Reply-To: References: Date: Wed, 18 Feb 2015 23:22:13 +0400 Message-ID: To: Nikita Popov Cc: Alexander Lisachenko , Nikita Popov , PHP internals list Content-Type: multipart/alternative; boundary=001a1133e5f29868a4050f61bce5 Subject: Re: [PHP-DEV] [RFC][Discussion] Parser extension API From: dmitry@zend.com (Dmitry Stogov) --001a1133e5f29868a4050f61bce5 Content-Type: text/plain; charset=UTF-8 I think the AST API shouldn't use "public" properties. Using it, we will have to construct the whole tree of objects, duplicating information from AST. I would propose SimpleXML approach instead - construct object only for node(s) we currently access. So at first we will construct just single object referring to AST root. Then traversing it we will create and destroy objects for necessary nodes. To access children I would propose to implementing ArrayAccess interface. $ast = \php\ast\parse($string); foreach ($ast as $child) { echo "\t" . $child->getKindName() . "\n"; foreach ($child as $grandchild) { echo "\t" . $child->getKindName() . "\n"; } } Thanks. Dmitry. On Wed, Feb 18, 2015 at 10:06 PM, Nikita Popov wrote: > On Wed, Feb 18, 2015 at 4:22 PM, Alexander Lisachenko < > lisachenko.it@gmail.com> wrote: > >> >> 2015-02-18 17:59 GMT+03:00 Nikita Popov : >> >>> Alexander, I would recommend you to split this into two RFCs, one >>> dealing only with AST export (and maybe pretty printing) and the second one >>> with the compilation hooks. There's probably a few questions about the >>> export API that should be discussed that will be forgotten if everyone >>> focuses on the more complicated, and probably not yet relevant, question of >>> compilation hooks. >> >> >> >> Hello, Nikita! Thanks for you thoughts! >> >> Sounds reasonable for me, because of short timeframe for PHP7. Let's go >> with the first part of RFC, because second part is really cumbersome and >> can be applied later, eg. in 7.1 I will split this RFC into two parts and >> mark first part for 7.0. >> > > Great! > > About first part, do you agree with proposed classes and namespace >> `Php\Parser`? >> > > Yeah, I'm okay with that namespace. I prefer php\ast as being more > distinctive from existing projects, but that's not really important. > > >> I want to propose to use classes for parser API instead of pure functions >> because it can give more usable OO-API for future needs. >> > > I'm okay with having stuff like ->getKindName() on the nodes, however I'd > still keep around the free-standing functions, because they can be used > without a node (i.e. you only need the kind AST_FOO and not an instantiated > node). > > I also don't see why we need ParserEngine::parse() instead of just a > (namespaced) parse() function. Not a fan of unnecessary wrapper classes. > > >> There is one more notice regarding to the zval nodes, they should be also >> exported as objects, not as values. I think we should export coherent nodes >> for everything. >> > > What's the advantage of this? Most leaf nodes will be zval nodes and I > feel it would be rather inconvenient if they'd all have extra wrappers. Is > there some specific problem with including the values directly? > > Nikita > > --001a1133e5f29868a4050f61bce5--