On 10/06/2020 22:38, Rowan Tommins wrote:
rather than renaming T_PAAMAYIM_NEKUDOTAYIM, we should simply ensure the user never needs to see it.


I'd like to clarify this slightly: I should have said "beyond renaming ... we should ensure" - I have no particular objection to changing the handful of places outside of parse errors that T_PAAMAYIM_NEKUDOTAYIM might appear.


If I understand correctly, the current proposal will instead give us this:

> Parse error: syntax error, unexpected '::' (T_DOUBLE_COLON)

But why not simply this:

> Parse error: syntax error, unexpected '::'


To ensure I'm not making unreasonable demands of others, I had a go at implementing this change, resulting in this straight-forward patch: https://github.com/php/php-src/compare/master...IMSoP:parse-error-poc?diff=split

I believe there's code in zend_yytnamerr that could be tidied up if we never want these token names, but also scope for other improvements in the output - for instance, we might want to say "unexpected quoted string 'foo'" instead of just "unexpected 'foo'".

There's also at least dozens of tests that will need to be changed to account for the new messages.


However, it's enough to demonstrate the difference such a change would make:


Input
::::::::::::::::
Before
Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting end of file
After
Parse error: syntax error, unexpected '::', expecting end of file

Input
$$$$$$$$$
Before
Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or '{' or '$'
After
Parse error: syntax error, unexpected end of file, expecting variable or '{' or '$'

Input
"foo" "bar"
Before
Parse error: syntax error, unexpected '"bar"' (T_CONSTANT_ENCAPSED_STRING)
After
Parse error: syntax error, unexpected '"bar"'


I think all of the above examples are easier to understand after than before.

I would be interested to hear reasons not to pursue this idea further.


Regards,

--
Rowan Tommins (né Collins)
[IMSoP]

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

Reply via email to