Skip to content

Commit 55a15f3

Browse files
IMSoPnikic
authored andcommitted
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 \\
1 parent d4fdf79 commit 55a15f3

File tree

53 files changed

+311
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+311
-232
lines changed

Zend/tests/attributes/019_variable_attribute_name.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class A {}
88

99
?>
1010
--EXPECTF--
11-
Parse error: syntax error, unexpected '$x' (T_VARIABLE), expecting identifier (T_STRING) or static (T_STATIC) or namespace (T_NAMESPACE) or \\ (T_NS_SEPARATOR) in %s on line %d
11+
Parse error: syntax error, unexpected variable "$x", expecting identifier or "static" or "namespace" or "\" in %s on line %d

Zend/tests/bug43343.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ $foo = 'bar';
88
var_dump(new namespace::$foo);
99
?>
1010
--EXPECTF--
11-
Parse error: %s error%sexpecting%sT_NS_SEPARATOR%sin %sbug43343.php on line 5
11+
Parse error: %s error%sexpecting%s"\"%sin %sbug43343.php on line 5

Zend/tests/bug70430.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ $"*** Testing function() : ***\n";
77

88
?>
99
--EXPECTF--
10-
Parse error: syntax error, unexpected '"*** Testing function() : ***' (T_CONSTANT_ENCAPSED_STRING), expecting variable (T_VARIABLE) or '{' or '$' in %s on line %d
10+
Parse error: syntax error, unexpected double-quoted string "*** Testing function() : ***\n", expecting variable or "{" or "$" in %s on line %d

Zend/tests/bug75252.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ try {
2424

2525
?>
2626
--EXPECT--
27-
string(41) "syntax error, unexpected 'FOO' (T_STRING)"
28-
string(41) "syntax error, unexpected 'FOO' (T_STRING)"
27+
string(41) "syntax error, unexpected identifier "FOO""
28+
string(41) "syntax error, unexpected identifier "FOO""

Zend/tests/bug77993.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Bug #77993 (Wrong parse error for invalid hex literal on Windows)
44
<?php
55
0xg10;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected 'xg10' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "xg10" in %s on line %d

Zend/tests/bug78454_1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid consecutive numeric separators after hex literal
44
<?php
55
0x0__F;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected '__F' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "__F" in %s on line %d

Zend/tests/bug78454_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid consecutive numeric separators after binary literal
44
<?php
55
0b0__1
66
--EXPECTF--
7-
Parse error: syntax error, unexpected '__1' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "__1" in %s on line %d

Zend/tests/ctor_promotion_additional_modifiers.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class Test {
99

1010
?>
1111
--EXPECTF--
12-
Parse error: syntax error, unexpected 'static' (T_STATIC), expecting variable (T_VARIABLE) in %s on line %d
12+
Parse error: syntax error, unexpected token "static", expecting variable in %s on line %d

Zend/tests/flexible-heredoc-error7.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Note: the closing ?> has been deliberately elided.
88
echo <<<END
99

1010
--EXPECTF--
11-
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) in %s on line %d
11+
Parse error: syntax error, unexpected end of file, expecting variable or heredoc end or "${" or "{$" in %s on line %d

Zend/tests/flexible-nowdoc-error7.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Note: the closing ?> has been deliberately elided.
88
echo <<<'END'
99
1010
--EXPECTF--
11-
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) in %s on line %d
11+
Parse error: syntax error, unexpected end of file, expecting variable or heredoc end or "${" or "{$" in %s on line %d

Zend/tests/flexible-nowdoc-error8.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ eval('<<<\'end\'
88

99
?>
1010
--EXPECTF--
11-
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) in %s on line %d
11+
Parse error: syntax error, unexpected end of file, expecting variable or heredoc end or "${" or "{$" in %s on line %d

Zend/tests/function_arguments/call_with_leading_comma_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Leading commas in function calls is not allowed
55
foo(,$foo);
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',' in %s on line %d
8+
Parse error: syntax error, unexpected token "," in %s on line %d

Zend/tests/function_arguments/call_with_multi_inner_comma_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Multiple inner commas in function calls is not allowed
55
foo($foo,,$bar);
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting ')' in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting ")" in %s on line %d

Zend/tests/function_arguments/call_with_multi_trailing_comma_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Multiple trailing commas in function calls is not allowed
55
foo($foo,,);
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting ')' in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting ")" in %s on line %d

Zend/tests/function_arguments/call_with_only_comma_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Single comma in function calls is not allowed
55
foo(,);
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',' in %s on line %d
8+
Parse error: syntax error, unexpected token "," in %s on line %d

Zend/tests/grammar/regression_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class Obj
1111

1212
function echo(){} // not valid
1313
--EXPECTF--
14-
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting %s in %s on line 9
14+
Parse error: syntax error, unexpected token "echo", expecting "(" in %s on line %d

Zend/tests/grammar/regression_005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class Obj
1010

1111
const return = 'nope';
1212
--EXPECTF--
13-
Parse error: syntax error, unexpected 'return' (T_RETURN), expecting identifier (T_STRING) in %s on line 8
13+
Parse error: syntax error, unexpected token "return", expecting identifier in %s on line %d

Zend/tests/grammar/regression_012.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class A {
99

1010
?>
1111
--EXPECTF--
12-
Parse error: syntax error, unexpected 'FOREACH' (T_FOREACH), expecting ']' in %s on line %d
12+
Parse error: syntax error, unexpected token "foreach", expecting "]" in %s on line %d

Zend/tests/list_011.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ var_dump(list(1, 2, 3));
77

88
?>
99
--EXPECTF--
10-
Parse error: syntax error, unexpected ')', expecting '=' in %s on line %d
10+
Parse error: syntax error, unexpected token ")", expecting "=" in %s on line %d

Zend/tests/ns_088.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ namespace Fiz\Biz\Buz {
1414
}
1515
?>
1616
--EXPECTF--
17-
Parse error: syntax error, unexpected '{', expecting '}' in %sns_088.php on line 5
17+
Parse error: syntax error, unexpected token "{", expecting "}" in %s on line %d

Zend/tests/ns_094.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ use const Foo\Bar\{
1111
function C
1212
};
1313
--EXPECTF--
14-
Parse error: syntax error, unexpected 'const' (T_CONST), expecting '}' in %s on line 7
14+
Parse error: syntax error, unexpected token "const", expecting "}" in %s on line %d

Zend/tests/ns_096.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ use Foo\Bar\{\Baz};
77

88
?>
99
--EXPECTF--
10-
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting identifier (T_STRING) or function (T_FUNCTION) or const (T_CONST) in %s on line 3
10+
Parse error: syntax error, unexpected token "\", expecting identifier or "function" or "const" in %s on line %d

Zend/tests/ns_trailing_comma_error_01.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Group use declarations mustn't be empty
55
use Baz\{};
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected '}', expecting identifier (T_STRING) or function (T_FUNCTION) or const (T_CONST) in %s on line %d
8+
Parse error: syntax error, unexpected token "}", expecting identifier or "function" or "const" in %s on line %d

Zend/tests/ns_trailing_comma_error_02.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Group use declarations mustn't contain just a comma
55
use Baz\{,};
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting identifier (T_STRING) or function (T_FUNCTION) or const (T_CONST) in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting identifier or "function" or "const" in %s on line %d

Zend/tests/ns_trailing_comma_error_03.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Group use declarations mustn't allow more than one comma
55
use Baz\{Foo,,};
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting '}' in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting "}" in %s on line %d

Zend/tests/ns_trailing_comma_error_04.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Group use declarations mustn't begin with a comma
55
use Baz\{,Foo};
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting identifier (T_STRING) or function (T_FUNCTION) or const (T_CONST) in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting identifier or "function" or "const" in %s on line %d

Zend/tests/ns_trailing_comma_error_05.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Group use declarations mustn't contain two commas mid-list
55
use Baz\{Foo,,Bar};
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting '}' in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting "}" in %s on line %d

Zend/tests/ns_trailing_comma_error_06.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Unmixed group use declarations mustn't allow more than one comma
55
use const Baz\{Foo,,};
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting '}' in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting "}" in %s on line %d

Zend/tests/ns_trailing_comma_error_07.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Unmixed group use declarations mustn't begin with a comma
55
use function Baz\{,Foo};
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting identifier (T_STRING) in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting identifier in %s on line %d

Zend/tests/ns_trailing_comma_error_08.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Unmixed group use declarations mustn't contain two commas mid-list
55
use const Baz\{Foo,,Bar};
66
?>
77
--EXPECTF--
8-
Parse error: syntax error, unexpected ',', expecting '}' in %s on line %d
8+
Parse error: syntax error, unexpected token ",", expecting "}" in %s on line %d

Zend/tests/numeric_literal_separator_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid use: trailing underscore
44
<?php
55
100_;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected '_' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "_" in %s on line %d

Zend/tests/numeric_literal_separator_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid use: adjacent underscores
44
<?php
55
10__0;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected '__0' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "__0" in %s on line %d

Zend/tests/numeric_literal_separator_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid use: underscore left of period
44
<?php
55
100_.0;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected '_' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "_" in %s on line %d

Zend/tests/numeric_literal_separator_005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid use: underscore right of period
44
<?php
55
100._0;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected '_0' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "_0" in %s on line %d

Zend/tests/numeric_literal_separator_006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid use: underscore next to 0x
44
<?php
55
0x_0123;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected 'x_0123' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "x_0123" in %s on line %d

Zend/tests/numeric_literal_separator_007.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid use: underscore next to 0b
44
<?php
55
0b_0101;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected 'b_0101' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "b_0101" in %s on line %d

Zend/tests/numeric_literal_separator_008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid use: underscore left of e
44
<?php
55
1_e2;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected '_e2' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "_e2" in %s on line %d

Zend/tests/numeric_literal_separator_009.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Invalid use: underscore right of e
44
<?php
55
1e_2;
66
--EXPECTF--
7-
Parse error: syntax error, unexpected 'e_2' (T_STRING) in %s on line %d
7+
Parse error: syntax error, unexpected identifier "e_2" in %s on line %d

Zend/tests/require_parse_exception.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var_dump("\u{ffffff}");');
4545
Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0
4646
Unclosed '{' on line 2
4747
Unclosed '{' on line 3
48-
syntax error, unexpected end of file, expecting '(' on line 2
48+
syntax error, unexpected end of file, expecting "(" on line 2
4949
Invalid numeric literal on line 2
5050
Invalid UTF-8 codepoint escape sequence on line 2
5151
Invalid UTF-8 codepoint escape sequence: Codepoint too large on line 2

Zend/tests/traits/bug55524.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ trait Foo extends Base {
1212
echo 'DONE';
1313
?>
1414
--EXPECTF--
15-
Parse error: syntax error, unexpected 'extends' (T_EXTENDS), expecting '{' in %s on line %d
15+
Parse error: syntax error, unexpected token "extends", expecting "{" in %s on line %d

Zend/tests/traits/bugs/interfaces.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ trait THello implements MyInterface {
1616

1717
?>
1818
--EXPECTF--
19-
Parse error: syntax error, unexpected 'implements' (T_IMPLEMENTS), expecting '{' in %s on line %d
19+
Parse error: syntax error, unexpected token "implements", expecting "{" in %s on line %d

Zend/tests/type_declarations/mixed/casting/mixed_cast_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ $foo = (mixed) 12;
77

88
?>
99
--EXPECTF--
10-
Parse error: syntax error, unexpected '12' (T_LNUMBER) in %s on line %d
10+
Parse error: syntax error, unexpected integer "12" in %s on line %d

Zend/tests/type_declarations/static_type_param.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ class Test {
1212

1313
?>
1414
--EXPECTF--
15-
Parse error: syntax error, unexpected 'static' (T_STATIC), expecting variable (T_VARIABLE) in %s on line %d
15+
Parse error: syntax error, unexpected token "static", expecting variable in %s on line %d

Zend/tests/type_declarations/static_type_property.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class Test {
1010

1111
?>
1212
--EXPECTF--
13-
Parse error: syntax error, unexpected 'static' (T_STATIC) in %s on line %d
13+
Parse error: syntax error, unexpected token "static" in %s on line %d

Zend/tests/type_declarations/typed_properties_025.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class Foo {
88
}
99
?>
1010
--EXPECTF--
11-
Parse error: syntax error, unexpected 'int' (T_STRING), expecting variable (T_VARIABLE) in %s on line 4
11+
Parse error: syntax error, unexpected identifier "int", expecting variable in %s on line %d

Zend/tests/varSyntax/globalNonSimpleVariableError.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ global $$foo->bar;
77

88
?>
99
--EXPECTF--
10-
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ';' or ',' in %s on line %d
10+
Parse error: syntax error, unexpected token "->", expecting ";" or "," in %s on line %d

0 commit comments

Comments
 (0)