diff options
author | Rowan Tommins <git@rwec.co.uk> | 2020-06-11 20:56:22 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-07-13 11:07:40 +0200 |
commit | 55a15f32ced0bd2467e6dec0c1287a4f11b1852f (patch) | |
tree | a88ec4ac9a7c7480fa877b8248cfdfb5c178ea00 /ext | |
parent | d4fdf79add800b4c529e6a31f2a0ff665b8b97ce (diff) | |
download | php-git-55a15f32ced0bd2467e6dec0c1287a4f11b1852f.tar.gz |
Improve output of tokens in Parse Errors
Currently, unexpected tokens in the parser are shown as the text
found, plus the internal token name, including the notorious
"unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)".
This commit replaces that with a more user-friendly format, with
two main types of token:
* Tokens which always represent the same text are shown like
'unexpected token "::"' and 'expected "::"'
* Tokens which have variable text are given a user-friendly
name, and show like 'unexpected identifier "foo"', and
'expected identifer'.
A few tokens have special cases:
* unexpected token """ -> unexpected double-quote mark
* unexpected quoted string "'foo'" -> unexpected single-quoted
string "foo"
* unexpected quoted string ""foo"" -> unexpected double-quoted
string "foo"
* unexpected illegal character "_" -> unexpected character 0xNN
(where _ is almost certainly a control character, and NN is the
hexadecimal value of the byte)
The \ token has a special case in the implementation just to stop
bison making a mess of escaping it and it coming out as \\
Diffstat (limited to 'ext')
-rw-r--r-- | ext/reflection/tests/bug74454.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/bug74372.phpt | 2 | ||||
-rw-r--r-- | ext/tokenizer/tests/token_get_all_TOKEN_PARSE_000.phpt | 2 | ||||
-rw-r--r-- | ext/tokenizer/tests/token_get_all_heredoc_nowdoc.phpt | 8 |
4 files changed, 7 insertions, 7 deletions
diff --git a/ext/reflection/tests/bug74454.phpt b/ext/reflection/tests/bug74454.phpt index e311ab3beb..2a61ff7cc0 100644 --- a/ext/reflection/tests/bug74454.phpt +++ b/ext/reflection/tests/bug74454.phpt @@ -14,4 +14,4 @@ function load_file() { } ?> --EXPECT-- -ParseError: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST) +ParseError: syntax error, unexpected token "if", expecting "function" or "const" diff --git a/ext/spl/tests/bug74372.phpt b/ext/spl/tests/bug74372.phpt index 161238af0e..c2506009a5 100644 --- a/ext/spl/tests/bug74372.phpt +++ b/ext/spl/tests/bug74372.phpt @@ -14,4 +14,4 @@ new Foo; ?> --EXPECTF-- -Parse error: syntax error, unexpected 'ha' (T_STRING) in %s on line %d +Parse error: syntax error, unexpected identifier "ha" in %s on line %d diff --git a/ext/tokenizer/tests/token_get_all_TOKEN_PARSE_000.phpt b/ext/tokenizer/tests/token_get_all_TOKEN_PARSE_000.phpt index b9da91502a..2d418a423c 100644 --- a/ext/tokenizer/tests/token_get_all_TOKEN_PARSE_000.phpt +++ b/ext/tokenizer/tests/token_get_all_TOKEN_PARSE_000.phpt @@ -15,5 +15,5 @@ echo "Done"; ?> --EXPECT-- -syntax error, unexpected 'code' (T_STRING) +syntax error, unexpected identifier "code" Done diff --git a/ext/tokenizer/tests/token_get_all_heredoc_nowdoc.phpt b/ext/tokenizer/tests/token_get_all_heredoc_nowdoc.phpt index 5f21c384d7..d073fa5941 100644 --- a/ext/tokenizer/tests/token_get_all_heredoc_nowdoc.phpt +++ b/ext/tokenizer/tests/token_get_all_heredoc_nowdoc.phpt @@ -326,11 +326,11 @@ Line 2: T_END_HEREDOC (' INNER_END') Test case 5 -Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) on line 2 +Parse error: syntax error, unexpected end of file, expecting variable or heredoc end or "${" or "{$" on line 2 Test case 6 -Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) on line 2 +Parse error: syntax error, unexpected end of file, expecting variable or heredoc end or "${" or "{$" on line 2 Test case 7 @@ -409,8 +409,8 @@ Line 3: T_END_HEREDOC (' INNER_END') Test case 17 -Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) on line 4 +Parse error: syntax error, unexpected end of file, expecting variable or heredoc end or "${" or "{$" on line 4 Test case 18 -Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) on line 4 +Parse error: syntax error, unexpected end of file, expecting variable or heredoc end or "${" or "{$" on line 4 |