Skip to content

Commit

Permalink
Add missing dots at the end of exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 15, 2020
1 parent e186bec commit 5cac0c7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public function tokenize($expression)
} elseif (false !== strpos(')]}', $expression[$cursor])) {
// closing bracket
if (empty($brackets)) {
throw new SyntaxError(sprintf('Unexpected "%s"', $expression[$cursor]), $cursor, $expression);
throw new SyntaxError(sprintf('Unexpected "%s".', $expression[$cursor]), $cursor, $expression);
}

list($expect, $cur) = array_pop($brackets);
if ($expression[$cursor] != strtr($expect, '([{', ')]}')) {
throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur, $expression);
throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $cur, $expression);
}

$tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1);
Expand All @@ -87,15 +87,15 @@ public function tokenize($expression)
$cursor += \strlen($match[0]);
} else {
// unlexable
throw new SyntaxError(sprintf('Unexpected character "%s"', $expression[$cursor]), $cursor, $expression);
throw new SyntaxError(sprintf('Unexpected character "%s".', $expression[$cursor]), $cursor, $expression);
}
}

$tokens[] = new Token(Token::EOF_TYPE, null, $cursor + 1);

if (!empty($brackets)) {
list($expect, $cur) = array_pop($brackets);
throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur, $expression);
throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $cur, $expression);
}

return new TokenStream($tokens, $expression);
Expand Down
4 changes: 2 additions & 2 deletions Node/BinaryNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ public function evaluate($functions, $values)
return $left * $right;
case '/':
if (0 == $right) {
throw new \DivisionByZeroError('Division by zero');
throw new \DivisionByZeroError('Division by zero.');
}

return $left / $right;
case '%':
if (0 == $right) {
throw new \DivisionByZeroError('Modulo by zero');
throw new \DivisionByZeroError('Modulo by zero.');
}

return $left % $right;
Expand Down
12 changes: 6 additions & 6 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function parse(TokenStream $stream, $names = [])

$node = $this->parseExpression();
if (!$stream->isEOF()) {
throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $stream->current->type, $stream->current->value), $stream->current->cursor, $stream->getExpression());
throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', $stream->current->type, $stream->current->value), $stream->current->cursor, $stream->getExpression());
}

return $node;
Expand Down Expand Up @@ -195,13 +195,13 @@ public function parsePrimaryExpression()
default:
if ('(' === $this->stream->current->value) {
if (false === isset($this->functions[$token->value])) {
throw new SyntaxError(sprintf('The function "%s" does not exist', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, array_keys($this->functions));
throw new SyntaxError(sprintf('The function "%s" does not exist.', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, array_keys($this->functions));
}

$node = new Node\FunctionNode($token->value, $this->parseArguments());
} else {
if (!\in_array($token->value, $this->names, true)) {
throw new SyntaxError(sprintf('Variable "%s" is not valid', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, $this->names);
throw new SyntaxError(sprintf('Variable "%s" is not valid.', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, $this->names);
}

// is the name used in the compiled code different
Expand All @@ -227,7 +227,7 @@ public function parsePrimaryExpression()
} elseif ($token->test(Token::PUNCTUATION_TYPE, '{')) {
$node = $this->parseHashExpression();
} else {
throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $token->type, $token->value), $token->cursor, $this->stream->getExpression());
throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', $token->type, $token->value), $token->cursor, $this->stream->getExpression());
}
}

Expand Down Expand Up @@ -289,7 +289,7 @@ public function parseHashExpression()
} else {
$current = $this->stream->current;

throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s"', $current->type, $current->value), $current->cursor, $this->stream->getExpression());
throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', $current->type, $current->value), $current->cursor, $this->stream->getExpression());
}

$this->stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
Expand Down Expand Up @@ -327,7 +327,7 @@ public function parsePostfixExpression($node)
// As a result, if $token is NOT an operator OR $token->value is NOT a valid property or method name, an exception shall be thrown.
(Token::OPERATOR_TYPE !== $token->type || !preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A', $token->value))
) {
throw new SyntaxError('Expected name', $token->cursor, $this->stream->getExpression());
throw new SyntaxError('Expected name.', $token->cursor, $this->stream->getExpression());
}

$arg = new Node\ConstantNode($token->value, true);
Expand Down
14 changes: 7 additions & 7 deletions ParserCache/ParserCacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,54 +67,54 @@ public function save(CacheItemInterface $item)
*/
public function getItems(array $keys = [])
{
throw new \BadMethodCallException('Not implemented');
throw new \BadMethodCallException('Not implemented.');
}

/**
* {@inheritdoc}
*/
public function hasItem($key)
{
throw new \BadMethodCallException('Not implemented');
throw new \BadMethodCallException('Not implemented.');
}

/**
* {@inheritdoc}
*/
public function clear()
{
throw new \BadMethodCallException('Not implemented');
throw new \BadMethodCallException('Not implemented.');
}

/**
* {@inheritdoc}
*/
public function deleteItem($key)
{
throw new \BadMethodCallException('Not implemented');
throw new \BadMethodCallException('Not implemented.');
}

/**
* {@inheritdoc}
*/
public function deleteItems(array $keys)
{
throw new \BadMethodCallException('Not implemented');
throw new \BadMethodCallException('Not implemented.');
}

/**
* {@inheritdoc}
*/
public function saveDeferred(CacheItemInterface $item)
{
throw new \BadMethodCallException('Not implemented');
throw new \BadMethodCallException('Not implemented.');
}

/**
* {@inheritdoc}
*/
public function commit()
{
throw new \BadMethodCallException('Not implemented');
throw new \BadMethodCallException('Not implemented.');
}
}
2 changes: 1 addition & 1 deletion SyntaxError.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SyntaxError extends \LogicException
{
public function __construct($message, $cursor = 0, $expression = '', $subject = null, array $proposals = null)
{
$message = sprintf('%s around position %d', $message, $cursor);
$message = sprintf('%s around position %d', rtrim($message, '.'), $cursor);
if ($expression) {
$message = sprintf('%s for expression `%s`', $message, $expression);
}
Expand Down
4 changes: 2 additions & 2 deletions TokenStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function next()
++$this->position;

if (!isset($this->tokens[$this->position])) {
throw new SyntaxError('Unexpected end of expression', $this->current->cursor, $this->expression);
throw new SyntaxError('Unexpected end of expression.', $this->current->cursor, $this->expression);
}

$this->current = $this->tokens[$this->position];
Expand All @@ -70,7 +70,7 @@ public function expect($type, $value = null, $message = null)
{
$token = $this->current;
if (!$token->test($type, $value)) {
throw new SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)', $message ? $message.'. ' : '', $token->type, $token->value, $type, $value ? sprintf(' with value "%s"', $value) : ''), $token->cursor, $this->expression);
throw new SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', $message ? $message.'. ' : '', $token->type, $token->value, $type, $value ? sprintf(' with value "%s"', $value) : ''), $token->cursor, $this->expression);
}
$this->next();
}
Expand Down

0 comments on commit 5cac0c7

Please sign in to comment.