} 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::getTypeAsString($token->getType()), $token->getValue()), $token->getLine());
+ throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($token->getType()), $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::getTypeAsString($stream->getCurrent()->getType()), $stream->getCurrent()->getValue()), $stream->getCurrent()->getLine());
+ 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());
}
$key = $stream->next()->getValue();
public function __toString()
{
- return sprintf('%s(%s)', self::getTypeAsString($this->type, true), $this->value);
+ return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value);
}
/**
$this->value = $value;
}
- static public function getTypeAsString($type, $short = false)
+ static public function typeToString($type, $short = false)
{
switch ($type) {
case self::EOF_TYPE:
return $short ? $name : 'Twig_Token::'.$name;
}
+
+ static public function typeToEnglish($type)
+ {
+ switch ($type) {
+ case self::EOF_TYPE:
+ return 'end of template';
+ case self::TEXT_TYPE:
+ return 'text';
+ case self::BLOCK_START_TYPE:
+ return 'begin of statement block';
+ case self::VAR_START_TYPE:
+ return 'begin of print statement';
+ case self::BLOCK_END_TYPE:
+ return 'end of statement block';
+ case self::VAR_END_TYPE:
+ return 'end of print statement';
+ case self::NAME_TYPE:
+ return 'name';
+ case self::NUMBER_TYPE:
+ return 'number';
+ case self::STRING_TYPE:
+ return 'string';
+ case self::OPERATOR_TYPE:
+ return 'operator';
+ case self::PUNCTUATION_TYPE:
+ return 'punctuation';
+ default:
+ throw new Twig_Error_Syntax(sprintf('Token of type %s does not exist.', $type));
+ }
+ }
}
if (!$token->test($primary, $secondary)) {
throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)',
$message ? $message.'. ' : '',
- Twig_Token::getTypeAsString($token->getType()), $token->getValue(),
- Twig_Token::getTypeAsString($primary), $secondary ? sprintf(' with value "%s"', $secondary) : ''),
+ Twig_Token::typeToEnglish($token->getType()), $token->getValue(),
+ Twig_Token::typeToEnglish($primary), $secondary ? sprintf(' with value "%s"', $secondary) : ''),
$this->current->getLine()
);
}