Re: [RFC] Normalize token_get_all() output (with flag)

From: Date: Sun, 10 Jan 2016 21:13:53 +0000
Subject: Re: [RFC] Normalize token_get_all() output (with flag)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-90462@lists.php.net to get a copy of this message
On Tue, Jan 5, 2016 at 11:51 AM, Sara Golemon <pollita@php.net> wrote: > On Mon, Jan 4, 2016 at 2:56 PM, Sara Golemon <pollita@php.net> wrote: >> https://wiki.php.net/rfc/token-get-always-tokens >> > A suggestion from a co-worker who's worried about seeing patterns like: > > case ($t['token']) { > case T_PAAMAYIM_NEKUDOTAYIM: > // do something > break; > case ord(';'): > // do something else > break; > } > > I see three options to remediate this: > 1) We could offer constants like: T_SEMICOLON (or T_ASCII_SEMICOLON) > defined to that character's ordinal value. (using unicode names) > 2) Make the token field be the character value (for single-character > tokens) instead of the ordinal. > 3) Add an additional field such that you have Array ( ['id'] => 59, > ['token'] => ';', ['text'] => ';', > ['line'] => 1 ) 'id' would always > be integer, while 'token' would be int or single-char. > > I don't like 3 as it's wasteful and needlessly duplicative. 1 feels a > bit over-engineered and actually hurts readability. 2 feels like a > nice compromise and matches how our rules end up looking in the parser > anyway (since C treats single characters as ordinals already). > Never really got a response on this one, and I'm personally leaning further towards Option 2; So unless someone has a better idea, I'll update the RFC in a few days. -Sara

« previous php.internals (#90462) next »