Skip to content

Commit 208ceff

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: Add missing dots at the end of exception messages
2 parents 70649e0 + 5cac0c7 commit 208ceff

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

Lexer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public function tokenize($expression)
5959
} elseif (false !== strpos(')]}', $expression[$cursor])) {
6060
// closing bracket
6161
if (empty($brackets)) {
62-
throw new SyntaxError(sprintf('Unexpected "%s"', $expression[$cursor]), $cursor, $expression);
62+
throw new SyntaxError(sprintf('Unexpected "%s".', $expression[$cursor]), $cursor, $expression);
6363
}
6464

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

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

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

9696
if (!empty($brackets)) {
9797
list($expect, $cur) = array_pop($brackets);
98-
throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur, $expression);
98+
throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $cur, $expression);
9999
}
100100

101101
return new TokenStream($tokens, $expression);

Node/BinaryNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ public function evaluate($functions, $values)
148148
return $left * $right;
149149
case '/':
150150
if (0 == $right) {
151-
throw new \DivisionByZeroError('Division by zero');
151+
throw new \DivisionByZeroError('Division by zero.');
152152
}
153153

154154
return $left / $right;
155155
case '%':
156156
if (0 == $right) {
157-
throw new \DivisionByZeroError('Modulo by zero');
157+
throw new \DivisionByZeroError('Modulo by zero.');
158158
}
159159

160160
return $left % $right;

Parser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function parse(TokenStream $stream, $names = [])
9898

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

104104
return $node;
@@ -194,13 +194,13 @@ public function parsePrimaryExpression()
194194
default:
195195
if ('(' === $this->stream->current->value) {
196196
if (false === isset($this->functions[$token->value])) {
197-
throw new SyntaxError(sprintf('The function "%s" does not exist', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, array_keys($this->functions));
197+
throw new SyntaxError(sprintf('The function "%s" does not exist.', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, array_keys($this->functions));
198198
}
199199

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

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

@@ -288,7 +288,7 @@ public function parseHashExpression()
288288
} else {
289289
$current = $this->stream->current;
290290

291-
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());
291+
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());
292292
}
293293

294294
$this->stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
@@ -326,7 +326,7 @@ public function parsePostfixExpression($node)
326326
// 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.
327327
(Token::OPERATOR_TYPE !== $token->type || !preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A', $token->value))
328328
) {
329-
throw new SyntaxError('Expected name', $token->cursor, $this->stream->getExpression());
329+
throw new SyntaxError('Expected name.', $token->cursor, $this->stream->getExpression());
330330
}
331331

332332
$arg = new Node\ConstantNode($token->value, true);

SyntaxError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SyntaxError extends \LogicException
1515
{
1616
public function __construct(string $message, int $cursor = 0, string $expression = '', string $subject = null, array $proposals = null)
1717
{
18-
$message = sprintf('%s around position %d', $message, $cursor);
18+
$message = sprintf('%s around position %d', rtrim($message, '.'), $cursor);
1919
if ($expression) {
2020
$message = sprintf('%s for expression `%s`', $message, $expression);
2121
}

TokenStream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function next()
4949
++$this->position;
5050

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

5555
$this->current = $this->tokens[$this->position];
@@ -66,7 +66,7 @@ public function expect($type, $value = null, $message = null)
6666
{
6767
$token = $this->current;
6868
if (!$token->test($type, $value)) {
69-
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);
69+
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);
7070
}
7171
$this->next();
7272
}

0 commit comments

Comments
 (0)