Skip to content

Commit

Permalink
Patch 1 (#1)
Browse files Browse the repository at this point in the history
* Fix "Quantified nested groups do not work"

If we have rule with quantified nested groups, like example: (("a")+ "bc")+, outer quantifier works not correct, because both quantifiers use  variables with same name - $count.
  • Loading branch information
djaf77 authored Jan 28, 2020
1 parent a509226 commit 3dc972b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/hafriedlander/Peg/Compiler/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,19 @@ protected function zero_or_more($code, $id)

protected function n_or_more($code, $id, $n)
{
$counterName = '$count' . $id;
return PHPBuilder::build()->l(
'$count = 0;'
$counterName . ' = 0;'
)->b(
'while (\true)',
$this->save($id),
$code->replace(array(
'MATCH' => \null,
'FAIL' => $this->restore($id, \true)->l('break;')
)),
'$count++;'
$counterName . '++;'
)->b(
'if ($count >= '.$n.')',
'if (' . $counterName . ' >= '.$n.')',
'MATCH'
)->b(
'else',
Expand All @@ -152,19 +153,20 @@ protected function n_or_more($code, $id, $n)
protected function n_to_x($code, $id, $min, $max)
{
if(1 === $min && 1 === $max) return $code;


$counterName = '$count' . $id;
return PHPBuilder::build()->l(
'$count = 0;'
$counterName . ' = 0;'
)->b(
'while ($count < '.$max.')',
'while (' . $counterName . ' < '.$max.')',
$this->save($id),
$code->replace(array(
'MATCH' => \null,
'FAIL' => $this->restore($id, \true)->l('break;')
)),
'$count++;'
$counterName . '++;'
)->b(
'if ($count >= '.$min.')',
'if (' . $counterName . ' >= '.$min.')',
'MATCH'
)->b(
'else',
Expand Down

0 comments on commit 3dc972b

Please sign in to comment.