} elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '{')) {
$node = $this->parseHashExpression();
} else {
- throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine());
+ throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($token->getType(), $token->getLine()), $token->getValue()), $token->getLine());
}
}
}
if (!$stream->test(Twig_Token::STRING_TYPE) && !$stream->test(Twig_Token::NUMBER_TYPE)) {
- throw new Twig_Error_Syntax(sprintf('A hash key must be a quoted string or a number (unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($stream->getCurrent()->getType()), $stream->getCurrent()->getValue()), $stream->getCurrent()->getLine());
+ $current = $stream->getCurrent();
+ throw new Twig_Error_Syntax(sprintf('A hash key must be a quoted string or a number (unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($current->getType(), $current->getLine()), $current->getValue()), $current->getLine());
}
$key = $stream->next()->getValue();
while (true) {
$token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to');
if (in_array($token->getValue(), array('true', 'false', 'none'))) {
- throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s"', $token->getValue()));
+ throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s"', $token->getValue()), $token->getLine());
}
$targets[] = new Twig_Node_Expression_AssignName($token->getValue(), $token->getLine());
*/
public function __toString()
{
- return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value);
+ return sprintf('%s(%s)', self::typeToString($this->type, true, $this->lineno), $this->value);
}
/**
*
* @return string The string representation
*/
- static public function typeToString($type, $short = false)
+ static public function typeToString($type, $short = false, $line = -1)
{
switch ($type) {
case self::EOF_TYPE:
$name = 'PUNCTUATION_TYPE';
break;
default:
- throw new Twig_Error_Syntax(sprintf('Token of type "%s" does not exist.', $type));
+ throw new Twig_Error_Syntax(sprintf('Token of type "%s" does not exist.', $type), $line);
}
return $short ? $name : 'Twig_Token::'.$name;
*
* @return string The string representation
*/
- static public function typeToEnglish($type)
+ static public function typeToEnglish($type, $line = -1)
{
switch ($type) {
case self::EOF_TYPE:
case self::PUNCTUATION_TYPE:
return 'punctuation';
default:
- throw new Twig_Error_Syntax(sprintf('Token of type "%s" does not exist.', $type));
+ throw new Twig_Error_Syntax(sprintf('Token of type "%s" does not exist.', $type), $line);
}
}
}
if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE)) {
if (false === $value) {
- throw new Twig_Error_Syntax(sprintf('Unexpected escaping strategy as you set autoescaping to false.', $lineno), -1);
+ throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $lineno);
}
$value = $this->parser->getStream()->next()->getValue();
{
$token = $this->tokens[$this->current];
if (!$token->test($type, $value)) {
+ $line = $token->getLine();
throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)',
$message ? $message.'. ' : '',
- Twig_Token::typeToEnglish($token->getType()), $token->getValue(),
- Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
- $token->getLine()
+ Twig_Token::typeToEnglish($token->getType(), $line), $token->getValue(),
+ Twig_Token::typeToEnglish($type, $line), $value ? sprintf(' with value "%s"', $value) : ''),
+ $line
);
}
$this->next();