Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84229 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96866 invoked from network); 3 Mar 2015 11:56:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Mar 2015 11:56:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=lisachenko.it@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=lisachenko.it@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.169 as permitted sender) X-PHP-List-Original-Sender: lisachenko.it@gmail.com X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:45167] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 62/94-03783-C71A5F45 for ; Tue, 03 Mar 2015 06:56:44 -0500 Received: by wivz2 with SMTP id z2so2708943wiv.4 for ; Tue, 03 Mar 2015 03:56:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=qmwcKWUSfqxMiefzpIgvL14MmCam6s3ROtgWVwHdb3A=; b=L6tEGCrcTxZB4VzBrpf/eRGN0dr8FfutlSFs1Hs/WBtfIgBak9FWRXi2sB8B22sL2x s9tHlvCoZjnU4bDztebKlQGaNxmprjZWZbg34WrQaXZu3XtUKZ1cjcWzqQVv0v5KxD3V ZB45eMeHstN7G9clPFzbs/tneM4BUrzX+teUkJbvOyRk+lxtp5v1IIgZ/Mc8YieY73xP vhwM/XEDzwKEPKaNjb6VJjvyx2/PlrBDkhEZdxJPgx/9834JTDXqfshEqPiCONwQDh8/ fJYR+PRJnjsuOkLtaSKYy6nn/wzHABipOaJYpXmUr9dZmsxbE9oEPn/Kkz9XkQEk/WEC HLXw== MIME-Version: 1.0 X-Received: by 10.180.149.205 with SMTP id uc13mr2311041wib.0.1425383800953; Tue, 03 Mar 2015 03:56:40 -0800 (PST) Received: by 10.194.154.229 with HTTP; Tue, 3 Mar 2015 03:56:40 -0800 (PST) In-Reply-To: References: Date: Tue, 3 Mar 2015 14:56:40 +0300 Message-ID: To: Dmitry Stogov Cc: Sara Golemon , Nikita Popov , Nikita Popov , PHP internals list Content-Type: multipart/alternative; boundary=001a11c38d881fe17705106107ee Subject: Re: [PHP-DEV] [RFC][Discussion] Parser extension API From: lisachenko.it@gmail.com (Alexander Lisachenko) --001a11c38d881fe17705106107ee Content-Type: text/plain; charset=UTF-8 Good morning! I have cleaned https://wiki.php.net/rfc/parser-extension-api and restricted it's scope only to the parsing API. Extension API can be implemented later on top of https://github.com/php/php-src/commit/1010b0ea4f4b9f96ae744f04c1191ac228580e48 and current implementation, because it requires a lot of discussion and can not be implemented right now. I want to move this RFC to the vote phase soon to decide if it will be included into PHP7.0 or not. So let's discuss open questions before moving it to the vote phase (from SO chat) 1. Should each node type be represented as personal class? There are two possible ways: single node class for everything (current proposal) and separate class for every node kind. I have made a quick research of AST API in several languages and noticed, that most of them generates AST class nodes automatically. E.g. UnaryOperationNode, StatementNode... This way is cool, but it requires a lot of classes to be loaded and available as API. Pros: SRP of each node class, AST validators (can be described with XML and DTD), more clear code analysis (checks with $node instaceof StatementNode), typehints for concrete nodes for visitors. However, PHP is dynamic language and we can use only one class for everything, adjusting `kind` property for each node. Pros: single class, easier to maintain and to use. Cons: bad UX (how to validate nodes, how to determine number of available children, how to check is node using flags or not, etc) 2. Where metadata should be stored (flags, names of kind nodes, relation between node types)? This information will be needed later for validation of AST Nikita have some thoughts for the future :) So he asked about the storage of metadata to validate an AST and to perform some analysis on it. Metadata should include the following: name of each node kind (this can be just a class name of node or constants in the class), node restrictions (which kind of node types can be used as children for concrete node; number of children nodes), node flag names (it's PUBLIC, PROTECTED, PRIVATE, etc) 2015-02-19 10:22 GMT+03:00 Dmitry Stogov : > > > On Thu, Feb 19, 2015 at 8:42 AM, Sara Golemon wrote: > >> On Wed, Feb 18, 2015 at 11:22 AM, Dmitry Stogov wrote: >> > 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. >> > >> I'm not sure if you've seen my astkit extension, but it does this. >> >> https://github.com/sgolemon/astkit >> > > I didn't see it before, and took just a quick look, but I like it. > Any special reason, why you didn't implement ArrayAccess interface for > children access? > For me it would look natural. > > Thanks. Dmitry. > > >> >> -Sara >> > > --001a11c38d881fe17705106107ee--