Re: [STANDARDS] Questions re keywords
[email protected] (Nikita Popov)
| Newsgroups | php.standards |
|---|---|
| Message-ID | <CAF+90c9A9NU8-Db=jhD8jnuc4VGdi+MDi6t_pkDoNzs+xF=XYg@mail.gmail.com> |
On Fri, Dec 18, 2015 at 9:36 PM, Rex Jaeschke <[email protected]> wrote: > As part of my work at Facebook in updating the formal spec for V7, I was > working on the new intrinsic, assert, which led me to the following > questions: > > > 1. Should `assert` be added to the list of keywords? > Nope, assert is an ordinary function with some extra handling. > 2. If so, which other intrinsic names should be listed as keywords? > (Right now, only `echo`, `list`, and `print` are listed.) > > Stas pointed me to > https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L100 > where I see > > %token T_ARRAY "array (T_ARRAY)" > %token T_ECHO "echo (T_ECHO)" > %token T_EMPTY "empty (T_EMPTY)" > %token T_EVAL "eval (T_EVAL)" > %token T_EXIT "exit (T_EXIT)" > %token T_ISSET "isset (T_ISSET)" > %token T_LIST "list (T_LIST)" > %token T_PRINT "print (T_PRINT)" > %token T_UNSET "unset (T_UNSET)" > > From that it seems to me they should all be listed as keywords. > Yes, all of these are keywords. This list might be helpful to compare against, though I didn't check if it's up to date: http://php.net/manual/de/reserved.keywords.php > 3. If `exit` is a keyword, shouldn't `die` also be one? > Yes, "die" is also a keyword. The list in the parser doesn't include it because "exit" and "die" are merged into the T_EXIT token. > 4. Based on the following extract from the Zend parser grammar > file, %token T_YIELD_FROM "yield from (T_YIELD_FROM)", it seems to me > that `yield from` is treated as a keyword containing whitespace, correct? > While unusual, this not new to me. (When I produced the Ecma spec for "C++ > with extensions for .NET", we added a number of such names in order to > avoid reserving new keywords.) The reason is the same here. We didn't want to add "from" as a separate reserved keyword. > In that spec we wrote such keywords as xxxx$xxxx, where $ was actually > some odd Unicode character that in Word rendered as ░. Then we said, "The > symbol ░ is used in the grammar to signify that white-space appears within > the keyword. Any white space that appears in the program text after > translation phase 1 is permitted in the position signified by the ░ > symbol. It is unspecified whether white space generated by comments, > documentation comments, and macro invocations is permitted in the position > signified by the ░ symbol. Following translation phase 4, a keyword with ░ > will be a single token." It seems to me that we need to say just what kind > of whitespace can separate the two parts, and whether /*...*/ is allowed as > a separator. > In PHP the allowed whitespace matches the white-space-character production and comments are not allowed. Nikita