Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108763 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50831 invoked from network); 25 Feb 2020 22:56:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Feb 2020 22:56:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E43121804A7 for ; Tue, 25 Feb 2020 13:14:15 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 25 Feb 2020 13:14:15 -0800 (PST) Received: by mail-lj1-f173.google.com with SMTP id n18so482081ljo.7 for ; Tue, 25 Feb 2020 13:14:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aRHCVY/cymtTC5MS1ysJILaeWoiIaVA/U+/GLbiNjCA=; b=hG32a5eFTrq/qlBNDJ3YwPg4axUn9rnTSD4eVEx3AKGfH6j8PscgoOPgwXenfiLnve culm84iK/LlMXtD+H3A/IwMnjyu5o7OCISd5oXrEZj/S6mLmFiiBVi7x7uVv71Fbtnc/ yPL604KGhEF0JrYV/rdIw10RNQyWt+F+IgIGhGr1ei2NgqauCRMaG0lgBGvw3LCQ9Kfq RnSN5gR6Px8n6VJga+yrKPYaTdOjr297gwalZcGbAO9PDqrEa/1mZXyOI/IO3A57aO0w 7l5IBUDRWf9JCELpyl4l8n1fcW5MxnCrz9V1aeumWlJvS9aBCCmkOb5xx8S63vTISfj+ VP5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aRHCVY/cymtTC5MS1ysJILaeWoiIaVA/U+/GLbiNjCA=; b=btSY8kyZNevrpQy6I2no8nHLLpdxoMWIh0oHeMOSkoGwypUiEdGOuVLhzAE3N/v3Q/ FebCIGpQJW3qEF5XzyLww5YqUq8EiqUB1CYizhuLG0C0ujtsL+aVqB1izXIALxK0ZqAn VRi+eo8TK3B5981C5mMbXnjs+Bi5Ly1Jz1rtwQwyTYKKjXjel/udIPWcn7I/qKErJaNb kstX8ksYMKKahTtRrHr2rUW8WaE5t5yU7Zczp7mVJPw9BLo4U0S2Cw5XeG7BcUmQM70i Z+U+2KH9FsawKBS5bk322fiychBKHa+axFI7JeH2dxyWGCKKVw262ixFB2w3W+VehH4s tBzw== X-Gm-Message-State: APjAAAUxciviM9Hi9+fB5w+7y5DLk/dN/wItffTRsOd1AZbOzOTSKoGX lAkZcDNaAD+3loirCGSV4/B7A5VytxMQJYFYqP4= X-Google-Smtp-Source: APXvYqwOy+fLE4H2pV1gUgvrYTV8VBDMpN1usXtC/OYioSm5tg1gf3W5ZXnyhfKY4PI4ylo8JbslbTj3Chl597t+rBc= X-Received: by 2002:a2e:93c5:: with SMTP id p5mr575061ljh.192.1582665251269; Tue, 25 Feb 2020 13:14:11 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 25 Feb 2020 22:13:54 +0100 Message-ID: To: Theodore Brown Cc: php internals Content-Type: multipart/alternative; boundary="00000000000019af6e059f6cf840" Subject: Re: [PHP-DEV] Re: [RFC] token_get_all() TOKEN_AS_OBJECT mode From: nikita.ppv@gmail.com (Nikita Popov) --00000000000019af6e059f6cf840 Content-Type: text/plain; charset="UTF-8" On Tue, Feb 25, 2020 at 7:16 PM Theodore Brown wrote: > On Tue, Feb 25, 2020 at 9:59 AM Nikita Popov wrote: > > > On Thu, Feb 13, 2020 at 10:47 AM Nikita Popov > wrote: > > > > > This has been discussed a while ago already, now as a proper proposal: > > > https://wiki.php.net/rfc/token_as_object > > > > > > An open question is whether (at least to start with) PhpToken should be > > > just a data container, or whether we want to add some helper methods > to it. > > > If this generates too much bikeshed, I'll drop methods from the > proposal. > > > > I think this proposal is in a pretty decent shape now, and I'd like to > move > > it to voting soon. The only remaining open question is whether we want to > > add any additional predefined methods. As the class can now be extended, > > every library can add their own methods, but there might still be value > in > > providing some things by default, primarily for performance reason. For > > example, the proposed is() method can be a good bit more efficient when > > implemented directly in extension code. > > > > Any feedback on this point? > > Hi Nikita, > > Thanks for this RFC. The proposed `PhpToken` class will definitely make it > easier to work with parsed tokens (I struggled with this when working on > the migration script for deprecated alternate array/string offset syntax). > > In regards to the open question of additional methods, the `getTokenName()` > method would be very welcome. `isIgnorable()` would also be helpful > sometimes, though I don't care much one way or another if it's added. > > But I'm really skeptical about the value of the `is($kind)` method. Code > working with tokens should know the type of value being checked (ID int, > text content, or array of one or the other), and a method that accepts > any of three types can make it harder to understand what's going on. > > For example, the proposed `isIgnorable()` method doesn't need to use > `is()`, it could just check whether the `id` property is in the array > of token constants. > To provide some context, a method like is() is primarily useful in the implementation of other methods accepting a token-descriptor to search for. Token stream implementation commonly have many helper methods along the lines of public function findRight($pos, $findTokenType) { $tokens = $this->tokens; for ($count = \count($tokens); $pos < $count; $pos++) { if ($tokens[$pos]->is($findTokenType)) { return $pos; } } return -1; } which search for tokens in different directions, skip tokens, check that tokens exist while skipping whitespace etc. Having a fast primitive to perform the token type check would be quite useful for that, I think. Regards, Nikita --00000000000019af6e059f6cf840--