diff --git a/src/TokenStream.php b/src/TokenStream.php index b5b089fd6..459781695 100644 --- a/src/TokenStream.php +++ b/src/TokenStream.php @@ -97,9 +97,10 @@ class TokenStream $token = $this->tokens[$this->current]; if (!$token->test($type, $value)) { $line = $token->getLine(); - throw new SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', + throw new SyntaxError(sprintf('%sUnexpected token "%s"%s ("%s" expected%s).', $message ? $message.'. ' : '', - Token::typeToEnglish($token->getType()), $token->getValue(), + Token::typeToEnglish($token->getType()), + $token->getValue() ? sprintf(' of value "%s"', $token->getValue()) : '', Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), $line, $this->source diff --git a/test/Twig/Tests/Fixtures/tags/macro/from_syntax_error.test b/test/Twig/Tests/Fixtures/tags/macro/from_syntax_error.test new file mode 100644 index 000000000..6223cfe94 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/macro/from_syntax_error.test @@ -0,0 +1,8 @@ +--TEST-- +"from" tag with syntax error +--TEMPLATE-- +{% from 'forms.twig' %} +--DATA-- +return [] +--EXCEPTION-- +Twig\Error\SyntaxError: Unexpected token "end of statement block" ("name" expected with value "import") in "index.twig" at line 2. diff --git a/test/Twig/Tests/Fixtures/tags/macro/from_with_reserved_name.test b/test/Twig/Tests/Fixtures/tags/macro/from_with_reserved_name.test index c844ae3b0..19adb9df4 100644 --- a/test/Twig/Tests/Fixtures/tags/macro/from_with_reserved_name.test +++ b/test/Twig/Tests/Fixtures/tags/macro/from_with_reserved_name.test @@ -2,7 +2,6 @@ "from" tag with reserved name --TEMPLATE-- {% from 'forms.twig' import templateName %} ---TEMPLATE(forms.twig)-- --DATA-- return [] --EXCEPTION-- diff --git a/test/Twig/Tests/Fixtures/tags/macro/import_syntax_error.test b/test/Twig/Tests/Fixtures/tags/macro/import_syntax_error.test new file mode 100644 index 000000000..b9817f0ee --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/macro/import_syntax_error.test @@ -0,0 +1,10 @@ +--TEST-- +"import" tag with reserved name +--TEMPLATE-- +{% import 'forms.twig' %} + +{{ macros.parent() }} +--DATA-- +return [] +--EXCEPTION-- +Twig\Error\SyntaxError: Unexpected token "end of statement block" ("name" expected with value "as") in "index.twig" at line 2. diff --git a/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_nam.test b/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_name.test similarity index 91% rename from test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_nam.test rename to test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_name.test index dc7a81001..34b8d43a2 100644 --- a/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_nam.test +++ b/test/Twig/Tests/Fixtures/tags/macro/import_with_reserved_name.test @@ -4,7 +4,6 @@ {% import 'forms.twig' as macros %} {{ macros.parent() }} ---TEMPLATE(forms.twig)-- --DATA-- return [] --EXCEPTION--