Skip to content

Commit 69b1e82

Browse files
committed
remove unused parseComparison method and simplify binary operator parsing logic
1 parent 152a1c7 commit 69b1e82

2 files changed

Lines changed: 2 additions & 19 deletions

File tree

src/Core/Parser.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,27 +219,10 @@ private function parseAssignment(): Node
219219
* @throws \PhpScript\Exceptions\ParseException
220220
*/
221221
private function parseComparison(): Node
222-
{
223-
$node = $this->parseConcat();
224-
225-
while ($this->match(TokenType::T_COMPARE_EQUALS, TokenType::T_COMPARE_UNEQUALS, TokenType::T_GREATER_THAN, TokenType::T_LESS_THAN)) {
226-
$token = $this->previous();
227-
$operator = $this->previous()->type;
228-
$right = $this->parseConcat();
229-
$node = new BinaryOperation($node, $operator, $right, $token);
230-
}
231-
232-
return $node;
233-
}
234-
235-
/**
236-
* @throws \PhpScript\Exceptions\ParseException
237-
*/
238-
private function parseConcat(): Node
239222
{
240223
$node = $this->parseAdditive();
241224

242-
while ($this->match(TokenType::T_CONCAT)) {
225+
while ($this->match(TokenType::T_COMPARE_EQUALS, TokenType::T_COMPARE_UNEQUALS, TokenType::T_GREATER_THAN, TokenType::T_LESS_THAN)) {
243226
$token = $this->previous();
244227
$operator = $this->previous()->type;
245228
$right = $this->parseAdditive();

tests/Unit/Core/ParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function parse(string $code): Node
8181
});
8282

8383
it('parses various binary operators', function (): void {
84-
$operators = ['+', '-', '*', '/', '~', '==', '!=', '>', '<'];
84+
$operators = ['+', '-', '*', '/', '==', '!=', '>', '<'];
8585
foreach ($operators as $op) {
8686
$program = parse("1 {$op} 2;");
8787
$statement = $program->statements[0];

0 commit comments

Comments
 (0)