Skip to content

Commit

Permalink
Fix test case e77bcec
Browse files Browse the repository at this point in the history
  • Loading branch information
Muqsit committed Oct 1, 2022
1 parent e77bcec commit 873d32e
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/muqsit/arithmexp/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,22 +195,17 @@ private function deparenthesizeTokens(string $expression, array &$tokens) : void
* @throws ParseException
*/
private function groupUnaryOperatorTokens(string $expression, array &$tokens) : void{
$stack = [&$tokens];
while(($index = array_key_last($stack)) !== null){
$entry = &$stack[$index];
unset($stack[$index]);
for($i = count($entry) - 1; $i >= 0; --$i){
$token = $entry[$i];
if(!($token instanceof UnaryOperatorToken)){
if(is_array($token)){
$stack[] = &$entry[$i];
}
continue;
}

array_splice($entry, $i, 2, [[
foreach($tokens as $i => $value){
if(is_array($value)){
$this->groupUnaryOperatorTokens($expression, $tokens[$i]);
}
}
for($i = count($tokens) - 1; $i >= 0; --$i){
$token = $tokens[$i];
if($token instanceof UnaryOperatorToken){
array_splice($tokens, $i, 2, [[
$token,
$entry[$i + 1] ?? throw new ParseException("No right operand specified for unary operator at \"" . substr($expression, $token->getStartPos(), $token->getEndPos() - $token->getStartPos()) . "\" ({$token->getStartPos()}:{$token->getEndPos()}) in \"{$expression}\"")
$tokens[$i + 1] ?? throw new ParseException("No right operand specified for unary operator at \"" . substr($expression, $token->getStartPos(), $token->getEndPos() - $token->getStartPos()) . "\" ({$token->getStartPos()}:{$token->getEndPos()}) in \"{$expression}\"")
]]);
}
}
Expand Down

0 comments on commit 873d32e

Please sign in to comment.