2011/6/20 Derick Rethans <der...@php.net>
>
> On Mon, 20 Jun 2011, Felipe Pena wrote:
>
> > 2011/6/20 Etienne Kneuss <col...@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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to