Merge branch 'master' of https://git.mcnd.ca/mcndave/picea
This commit is contained in:
commit
f143b082ae
|
@ -20,23 +20,18 @@ class ForToken implements ControlStructure {
|
||||||
return "<?php for ($arguments): {$uid} = 1; ?>";
|
return "<?php for ($arguments): {$uid} = 1; ?>";
|
||||||
|
|
||||||
case "endfor":
|
case "endfor":
|
||||||
if ( $context->iterationStack === null ){
|
$last = end($context->iterationStack);
|
||||||
|
|
||||||
}
|
if ( $last['or'] === false ) {
|
||||||
|
|
||||||
if ( end($context->iterationStack)['or'] === false ) {
|
|
||||||
$output = "<?php endfor; ?>";
|
$output = "<?php endfor; ?>";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$output = "<?php endif; ?>";
|
$output = "<?php endif; unset({$last['uid']}) ?>";
|
||||||
}
|
}
|
||||||
|
|
||||||
array_pop($context->iterationStack);
|
array_pop($context->iterationStack);
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
|
||||||
case "continue":
|
|
||||||
return "<?php continue; ?>";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,10 @@ namespace Picea\ControlStructure;
|
||||||
|
|
||||||
class ForeachToken implements ControlStructure {
|
class ForeachToken implements ControlStructure {
|
||||||
|
|
||||||
public array $token = [ "foreach", "endforeach", "continue" ];
|
public array $token = [ "foreach", "endforeach" ];
|
||||||
|
|
||||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
||||||
switch($token) {
|
switch($token) {
|
||||||
case "continue":
|
|
||||||
return "<?php continue; ?>";
|
|
||||||
|
|
||||||
case "foreach":
|
case "foreach":
|
||||||
$name = "$".uniqid("foreach_");
|
$name = "$".uniqid("foreach_");
|
||||||
|
|
||||||
|
@ -30,14 +27,16 @@ class ForeachToken implements ControlStructure {
|
||||||
'token' => 'endforeach',
|
'token' => 'endforeach',
|
||||||
];
|
];
|
||||||
|
|
||||||
return "<?php foreach ($arguments): $name = ( $name ?? 0 ) + 1; ?>";
|
return "<?php foreach ($arguments): $name = ( $name ?? 0 ) + 1; ; ?>";
|
||||||
|
|
||||||
case "endforeach":
|
case "endforeach":
|
||||||
if ( end($context->iterationStack)['or'] === false ) {
|
$last = end($context->iterationStack);
|
||||||
|
|
||||||
|
if ( $last['or'] === false ) {
|
||||||
$output = "<?php endforeach; ?>";
|
$output = "<?php endforeach; ?>";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$output = "<?php endif; ?>";
|
$output = "<?php endif; unset({$last['uid']}) ?>";
|
||||||
}
|
}
|
||||||
|
|
||||||
array_pop($context->iterationStack);
|
array_pop($context->iterationStack);
|
||||||
|
|
Loading…
Reference in New Issue