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

0 commit comments

Comments
 (0)