]> granicus.if.org Git - php/commit
Improve output of tokens in Parse Errors
authorRowan Tommins <git@rwec.co.uk>
Thu, 11 Jun 2020 19:56:22 +0000 (20:56 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 13 Jul 2020 09:07:40 +0000 (11:07 +0200)
commit55a15f32ced0bd2467e6dec0c1287a4f11b1852f
treea88ec4ac9a7c7480fa877b8248cfdfb5c178ea00
parentd4fdf79add800b4c529e6a31f2a0ff665b8b97ce
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 \\
53 files changed:
Zend/tests/attributes/019_variable_attribute_name.phpt
Zend/tests/bug43343.phpt
Zend/tests/bug70430.phpt
Zend/tests/bug75252.phpt
Zend/tests/bug77993.phpt
Zend/tests/bug78454_1.phpt
Zend/tests/bug78454_2.phpt
Zend/tests/ctor_promotion_additional_modifiers.phpt
Zend/tests/flexible-heredoc-error7.phpt
Zend/tests/flexible-nowdoc-error7.phpt
Zend/tests/flexible-nowdoc-error8.phpt
Zend/tests/function_arguments/call_with_leading_comma_error.phpt
Zend/tests/function_arguments/call_with_multi_inner_comma_error.phpt
Zend/tests/function_arguments/call_with_multi_trailing_comma_error.phpt
Zend/tests/function_arguments/call_with_only_comma_error.phpt
Zend/tests/grammar/regression_004.phpt
Zend/tests/grammar/regression_005.phpt
Zend/tests/grammar/regression_012.phpt
Zend/tests/list_011.phpt
Zend/tests/ns_088.phpt
Zend/tests/ns_094.phpt
Zend/tests/ns_096.phpt
Zend/tests/ns_trailing_comma_error_01.phpt
Zend/tests/ns_trailing_comma_error_02.phpt
Zend/tests/ns_trailing_comma_error_03.phpt
Zend/tests/ns_trailing_comma_error_04.phpt
Zend/tests/ns_trailing_comma_error_05.phpt
Zend/tests/ns_trailing_comma_error_06.phpt
Zend/tests/ns_trailing_comma_error_07.phpt
Zend/tests/ns_trailing_comma_error_08.phpt
Zend/tests/numeric_literal_separator_002.phpt
Zend/tests/numeric_literal_separator_003.phpt
Zend/tests/numeric_literal_separator_004.phpt
Zend/tests/numeric_literal_separator_005.phpt
Zend/tests/numeric_literal_separator_006.phpt
Zend/tests/numeric_literal_separator_007.phpt
Zend/tests/numeric_literal_separator_008.phpt
Zend/tests/numeric_literal_separator_009.phpt
Zend/tests/require_parse_exception.phpt
Zend/tests/traits/bug55524.phpt
Zend/tests/traits/bugs/interfaces.phpt
Zend/tests/type_declarations/mixed/casting/mixed_cast_error.phpt
Zend/tests/type_declarations/static_type_param.phpt
Zend/tests/type_declarations/static_type_property.phpt
Zend/tests/type_declarations/typed_properties_025.phpt
Zend/tests/varSyntax/globalNonSimpleVariableError.phpt
Zend/zend_language_parser.y
ext/reflection/tests/bug74454.phpt
ext/spl/tests/bug74372.phpt
ext/tokenizer/tests/token_get_all_TOKEN_PARSE_000.phpt
ext/tokenizer/tests/token_get_all_heredoc_nowdoc.phpt
tests/lang/bug21820.phpt
tests/lang/bug71897.phpt