Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98613 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54894 invoked from network); 23 Mar 2017 23:33:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Mar 2017 23:33:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:38080] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BB/A1-40046-E4B54D85 for ; Thu, 23 Mar 2017 18:33:35 -0500 Received: by mail-wm0-f49.google.com with SMTP id t189so1004196wmt.1 for ; Thu, 23 Mar 2017 16:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=/RaQh6aNoN6qz01v9AZTpIqhJncJiKIaGlV96wuvets=; b=mLQyGWKeEGkCxxP21ncxf4w/5TJmhk76RpeFGywG9dBxLw3ncUB4dZdq8K4qoH3Py/ 322pSj/hUVn6JXUvUszknffdXgYwXZD4mwb4VfFjfZkMv3EAmHvATaP/NqNOZ5ngGr2f oO368UdiCuG2Gj2AekJXVb853MTDRE2p2Rpc6qQMCFxrDJYLlOBZJ1F4hMDPRmkpK7Ty R/eNXRZVCPVt4wPh/kshwwsHUgauwHr9kiWVV8OJsAx38KweJLgzKs84Ghn+TrfzvI0N cQGJQf2OQzfxaXcl/UVSPKWDdSXEbEArs78iEAFHzuUtjCMRiUi+jb7xg4Ln1ohC31RF cVkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=/RaQh6aNoN6qz01v9AZTpIqhJncJiKIaGlV96wuvets=; b=YiaGsXMdrLh9deV/osf3E7jbgjhS+Mtwn1hcjs6xtHGEDOaz9IQDmq9a3OSxOyUlaD Izw2PTzK6of32WIZmZTS4YEsBlpOT81gYXQDe/ByOmdROko4MkqLhpNM+iAXN+fGh9Bt nupSMtMzIELtYVc8kbKNdumAWgaKo4OwKmOkhRT9nRIfRTUHyXd6d8NgqObhPvieqtqc ctEqkXg0E+JNaCDWVXhntrDneJf3cvzMOhdGlP8LQ7aP+mht7yTG4G5N2ocD8LDYm2Rc pz6pZFc/MUmsW37+Lcy3tin+gf1NqUK+kpaGqkKz/ulOXCi8UX5ifYhg8tJnjXHISBXg AqPQ== X-Gm-Message-State: AFeK/H1v/+UbEnwDb0M2ZBmfgsUWszfaiy3BZO+5m9UWhkDRyVIGNnmaiAjxpyBq/6qkDFF2yeOtx7CPmY/P6w== X-Received: by 10.28.131.65 with SMTP id f62mr205619wmd.4.1490312012277; Thu, 23 Mar 2017 16:33:32 -0700 (PDT) MIME-Version: 1.0 Sender: php@golemon.com Received: by 10.223.152.213 with HTTP; Thu, 23 Mar 2017 16:33:31 -0700 (PDT) X-Originating-IP: [73.9.224.155] In-Reply-To: References: Date: Thu, 23 Mar 2017 18:33:31 -0500 X-Google-Sender-Auth: AhDyTMV2KhnQnGhFKrPeNfOtPtk Message-ID: To: =?UTF-8?Q?Jan_Tvrd=C3=ADk?= Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: TOKEN_AS_OBJECT for token_get_all() From: pollita@php.net (Sara Golemon) On Thu, 23 Mar 2017 18:16:31 +0100, Nikita Popov > I'd like to add a new TOKEN_AS_OBJECT flag to token_get_all(), which > returns an array of PhpToken objects, rather than the mix of plain string= s > and arrays we currently have. The PhpToken class is defined as: > > class PhpToken { > public $type; > public $text; > public $line; > } > > This has been previously suggested and implemented by Rouven We=C3=9Fling= [1], > I've just ported this feature to master and optimized the implementation > [2]. > > Yeah, IIRC the more recent discussion ended at "Oh, and this! And this! And this!" which eventually went nowhere (largely my ADD). IMO there's no harm in adding this, and the class format seems entirely reasonable. If I may bikeshed a TINY bit, I'd ask that all tokens return as objects, rather than char|PhpToken similar to the current char|array format we have. (Maybe that's in the PR, I haven't looked at either) On Thu, Mar 23, 2017 at 5:25 PM, Jan Tvrd=C3=ADk wrote: > Regarding memory - would it be possible to return iterator instead of arr= ay? > That has some hairy edges to it since the lexer isn't actually reentrant within a given thread. Image the following: foreach (token_get_all($code, TOKEN_AS_ITERATOR) as $token) { $moretokens =3D token_get_all($morecode, $whateverflags); // <--- Here be broken dreams and crying unicorns } Worse still if you have parallel iterators. That's probably fixable, but it's a much heavier refactor and one that should probably have an RFC. -Sara