Permalink
Browse files

Fix bug in chainr combinator.

  • Loading branch information...
nielssp committed Feb 13, 2016
1 parent b27a844 commit 2c1abd53c7204f8a1ba6c8293fcdbdcae8cf5035
@@ -602,7 +602,7 @@ public function chainr(Parser $p, Parser $sep)
for ($i = $length - 2; $i >= 0; $i--) {
$f = $ops[$i + 1][1];
$leftOperand = $ops[$i][0];
$rightOpreand = call_user_func($f, $leftOperand, $rightOperand);
$rightOperand = call_user_func($f, $leftOperand, $rightOperand);
}
return new Success($rightOperand, $pos, $input, $nextPos);
});
@@ -36,7 +36,6 @@ protected function head($input)
*/
protected function tail($input, array $pos)
{
$head = $input[0];
$tail = array_slice($input, 1);
if (isset($tail[0])) {
$pos = $tail[0]->getPosition();
@@ -320,9 +320,6 @@ public function group($i, Parser $p)
if (isset($offset)) {
$pos[1] += $offset;
}
if (! count($input)) {
$nextPos = array(-1, -1);
}
return new Success($group, $pos, $r->nextInput, $r->nextPos);
});
}
@@ -18,5 +18,5 @@ class Parco
*
* @var string
*/
const VERSION = '1.1.0';
const VERSION = '1.1.1';
}
@@ -359,23 +359,23 @@ public function testChainl()
public function testChainr()
{
$p1 = $this->elem(1);
$p1 = $this->acceptIf('is_int');
$p2 = $this->elem('-')->withResult(function ($left, $right) {
return $left - $right;
});
$c1 = $this->chainr($p1, $p2);
$result = $this->apply($c1);
$this->assertFalse($result->successful);
$this->assertEquals('unexpected end of input, expected "1"', $result->message);
$this->assertEquals('unexpected end of input', $result->message);
$result = $this->apply($c1, array(1, '-'));
$this->assertTrue($result->successful);
$this->assertEquals(1, $result->get());
$result = $this->apply($c1, array(1, '-', 1, '-', 1));
$result = $this->apply($c1, array(5, '-', 2, '-', 1));
$this->assertTrue($result->successful);
$this->assertEquals(1, $result->get());
$this->assertEquals(4, $result->get());
$this->assertEquals(array(), $result->nextInput);
$this->assertEquals(array(-1, -1), $result->nextPos);
}

0 comments on commit 2c1abd5

Please sign in to comment.