diff --git a/app/Cfnpp/Functions.php b/app/Cfnpp/Functions.php index 6321ce1..a4469e5 100644 --- a/app/Cfnpp/Functions.php +++ b/app/Cfnpp/Functions.php @@ -215,23 +215,38 @@ class Functions * @param NodeFunction $function * @return ?Node */ - /* - * TODO: Reimplement public function f_expr(Node $node, NodeFunction $function): ?Node { if (!($function instanceof NodeFunctionValue)) { - throw new \Exception('!if requires scalar argument'); + throw new \Exception('!expr requires scalar argument'); } - $parser = new \App\Cfnpp\Expression\Parser(); - $expression = $parser->parse($function->getValue()); - $result = $expression->evaluate($this->options->getVariables()); + $expression = new \App\Cfnpp\Expression\Expression($function->getValue(), $this->options); - $result = Node::fromPhp($result); - $result->setName($node->hasName() ? $node->getName() : null); + if ($expression->isComplete()) + { + // If we computed a final value/set of values, we can just insert those + // directly. + if ($expression->count() == 1) + { + $solution_node = Node::fromPhp($expression->getValue()); + } + else + { + $solution_node = Node::fromPhp($expression->toArray()); + } + } + else + { + // Otherwise let's convert it to cfn intrinsics + $solution_node = Node::fromPhp($expression->toCloudformation()); + } - return $result; + if ($node->hasName()) + { + $solution_node->setName($node->getName()); + } + return $solution_node; } - */ }