Re: [RFC] 5.4 features for vote (long)
| From: | Felipe Pena | Date: | Tue, 21 Jun 2011 03:09:37 +0000 |
| Subject: | Re: [RFC] 5.4 features for vote (long) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53456@lists.php.net to get a copy of this message | ||
2011/6/20 Derick Rethans <derick@php.net>
>
> On Mon, 20 Jun 2011, Felipe Pena wrote:
>
> > 2011/6/20 Etienne Kneuss <colder@php.net>
> > >
> > > I'd love to see the proposal from Felipe about the improved parse
> > > errors in that list. I believe that the patch was ready or almost
> > > ready? I can't find the RFC though, but maybe the RFC never existed....
> > >
> >
> > https://wiki.php.net/rfc/improved-parser-error-message
>
> I think this is good and helpful.
> I've two suggestions though:
>
> - Add the token name in parenthesis at the end of the string
> - Add '' around the token strings
>
> Examples:
> Parse error: syntax error, unexpected '<<=' (T_SL_EQUAL) in Command line code
> on line 1
> Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM) in Command line
> code on line 1
> Parse error: syntax error, unexpected 'quoted-string' (T_CONSTANT_ENCAPSED_STRING),
> expecting identifier or '(' in Command line code on line 1
>
To have the quoting message working as desired, we need to implement
the yytnamerr function (based in the default one)
e.g.:
static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr)
{
if (!yyres) {
return yystrlen(yystr);
}
if (*yystr == '"') {
YYSIZE_T yyn = 0;
char const *yyp = yystr;
while (1) {
if (*++yyp != '"') {
yyres[yyn++] = *yyp;
} else {
yyres[yyn] = '\0';
return yyn;
}
}
}
return yystpcpy (yyres, yystr) - yyres;
}
I'm ok with this, I just think it's ugly to repeat the token name in
the definition in the .y file. :P
%token T_LNUMBER "'number' (T_LNUMBER)"
%token T_STRING "'identifier' (T_STRING)"
$ sapi/cli/php -r 'function 1'
Parse error: syntax error, unexpected 'number' (T_LNUMBER), expecting
'identifier' (T_STRING) or '(' in Command line code on line 1
--
Regards,
Felipe Pena