From e44ea9b0d4608db773d2dfce48c23f04be24e4d3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Jul 2011 15:27:34 +0200 Subject: [PATCH] added filename when throwing an exception when we know it --- lib/Twig/Parser.php | 8 ++++---- lib/Twig/TokenStream.php | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index f22ad09..0e7a8af 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -121,7 +121,7 @@ class Twig_Parser implements Twig_ParserInterface $token = $this->getCurrentToken(); if ($token->getType() !== Twig_Token::NAME_TYPE) { - throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine()); + throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->stream->getFilename()); } if (null !== $test && call_user_func($test, $token)) { @@ -138,7 +138,7 @@ class Twig_Parser implements Twig_ParserInterface $subparser = $this->handlers->getTokenParser($token->getValue()); if (null === $subparser) { - throw new Twig_Error_Syntax(sprintf('Unknown tag name "%s"', $token->getValue()), $token->getLine()); + throw new Twig_Error_Syntax(sprintf('Unknown tag name "%s"', $token->getValue()), $token->getLine(), $this->stream->getFilename()); } $this->stream->next(); @@ -150,7 +150,7 @@ class Twig_Parser implements Twig_ParserInterface break; default: - throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.'); + throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', -1, $this->stream->getFilename()); } } @@ -301,7 +301,7 @@ class Twig_Parser implements Twig_ParserInterface || (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface) ) { - throw new Twig_Error_Syntax(sprintf('A template that extends another one cannot have a body (%s).', $node), $node->getLine()); + throw new Twig_Error_Syntax(sprintf('A template that extends another one cannot have a body (%s).', $node), $node->getLine(), $this->stream->getFilename()); } } } diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index c5eb912..a2002b4 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -53,7 +53,7 @@ class Twig_TokenStream public function next() { if (!isset($this->tokens[++$this->current])) { - throw new Twig_Error_Syntax('Unexpected end of template'); + throw new Twig_Error_Syntax('Unexpected end of template', -1, $this->filename); } return $this->tokens[$this->current - 1]; @@ -73,7 +73,8 @@ class Twig_TokenStream $message ? $message.'. ' : '', Twig_Token::typeToEnglish($token->getType(), $line), $token->getValue(), Twig_Token::typeToEnglish($type, $line), $value ? sprintf(' with value "%s"', $value) : ''), - $line + $line, + $this->filename ); } $this->next(); @@ -91,7 +92,7 @@ class Twig_TokenStream public function look($number = 1) { if (!isset($this->tokens[$this->current + $number])) { - throw new Twig_Error_Syntax('Unexpected end of template'); + throw new Twig_Error_Syntax('Unexpected end of template', -1, $this->filename); } return $this->tokens[$this->current + $number]; -- 1.7.2.5