Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4:
  Add missing dots at the end of exception messages
  [DI][Form] Fixed test suite (TimeType changes & unresolved merge conflict)
  Fix bad merge
  Add missing dots at the end of exception messages
  • Loading branch information
fabpot committed Mar 15, 2020
2 parents 67741ad + 208ceff commit 19b3af1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public function tokenize(string $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 @@ -85,15 +85,15 @@ public function tokenize(string $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(array $functions, array $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 @@ -96,7 +96,7 @@ public function parse(TokenStream $stream, array $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 @@ -192,13 +192,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 @@ -224,7 +224,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 @@ -286,7 +286,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 @@ -324,7 +324,7 @@ public function parsePostfixExpression(Node\Node $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
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(string $message, int $cursor = 0, string $expression = '', string $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 @@ -49,7 +49,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 @@ -65,7 +65,7 @@ public function expect($type, string $value = null, string $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 19b3af1

Please sign in to comment.