From 536c0edac72a2b76d67ca2f9bc9fc2f4608bd0e6 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Mon, 13 Jan 2014 11:19:04 -0500 Subject: [PATCH] Include line number with syntax errors Contains changes suggested in #184 --- src/Mustache/Parser.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Mustache/Parser.php b/src/Mustache/Parser.php index 227e00b..f44153c 100644 --- a/src/Mustache/Parser.php +++ b/src/Mustache/Parser.php @@ -71,12 +71,22 @@ class Mustache_Parser case Mustache_Tokenizer::T_END_SECTION: if (!isset($parent)) { - $msg = sprintf('Unexpected closing tag: /%s', $token[Mustache_Tokenizer::NAME]); + $msg = sprintf( + 'Unexpected closing tag: /%s on line %d', + $token[Mustache_Tokenizer::NAME], + $token[Mustache_Tokenizer::LINE] + ); throw new Mustache_Exception_SyntaxException($msg, $token); } if ($token[Mustache_Tokenizer::NAME] !== $parent[Mustache_Tokenizer::NAME]) { - $msg = sprintf('Nesting error: %s vs. %s', $parent[Mustache_Tokenizer::NAME], $token[Mustache_Tokenizer::NAME]); + $msg = sprintf( + 'Nesting error: %s (on line %d) vs. %s (on line %d)', + $parent[Mustache_Tokenizer::NAME], + $parent[Mustache_Tokenizer::LINE], + $token[Mustache_Tokenizer::NAME], + $token[Mustache_Tokenizer::LINE] + ); throw new Mustache_Exception_SyntaxException($msg, $token); } @@ -109,7 +119,11 @@ class Mustache_Parser } if (isset($parent)) { - $msg = sprintf('Missing closing tag: %s', $parent[Mustache_Tokenizer::NAME]); + $msg = sprintf( + 'Missing closing tag: %s opened on line %s', + $parent[Mustache_Tokenizer::NAME], + $parent[Mustache_Tokenizer::LINE] + ); throw new Mustache_Exception_SyntaxException($msg, $parent); }