Skip to content

Commit

Permalink
Merge pull request #1 from superjobru/patch-1
Browse files Browse the repository at this point in the history
Fix "Quantified nested groups do not work"
  • Loading branch information
smuuf authored Feb 19, 2020
2 parents 0327b97 + 69af4a5 commit 2d3c1a1
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 2d3c1a1

Please sign in to comment.