Skip to content

Commit

Permalink
Fix bug when expanding an Ast leaf which is a single token
Browse files Browse the repository at this point in the history
  • Loading branch information
marcioAlmada committed Apr 17, 2019
1 parent 6c13805 commit cd407ee
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Expansion.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ private function mutate(TokenStream $ts, Ast $context, Engine $engine) : TokenSt

$delimiters = $result->{'delimiters'};

// normalize when context is a single token
if ($context instanceof Token) $context = [[$context]];

// normalize associative arrays
if (array_values($context) !== $context) $context = [$context];

Expand Down
51 changes: 51 additions & 0 deletions tests/phpt/issues/ircmaxell-php-compiler#29.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
Test for bug found at https://github.com/ircmaxell/php-compiler/pull/29 --pretty-print
--FILE--
<?php

$(macro :unsafe :recursive) {
$(optional(buffer('unsigned')) as unsigned) compile {
$(
repeat(
either(
chain(
T_VARIABLE as result,
token('='),
either(
chain(
T_VARIABLE as binary_left,
either(token('^') as binary_xor) as binary_op,
either(T_VARIABLE as binary_variable, T_LNUMBER as binary_number) as binary_right
) as binary
),
token(';')
) as assignop
)
) as stmts
)
}
} >> {
$(stmts ... {
$(assignop ? ... {
$(binary ? ... {
$(binary_op ... {
$(binary_xor ? ... {
$(result) = $this->context->builder->bitwiseXor($(binary_left), $__right);
})
})
})
})
})
}

compile {
$result = $value ^ 1;
}

?>
--EXPECTF--
<?php

$result = $this->context->builder->bitwiseXor($value, $__right);

?>

0 comments on commit cd407ee

Please sign in to comment.