/** * @return string */ public function transpile() { $dispatcher = new NodeDispatcher($this->node->expr); $dispatcher->setContext($this); $expression = $dispatcher->dispatch(); return 'return ' . $expression . ';'; }
/** * @return string */ public function transpile() { $conditionDispatcher = new NodeDispatcher($this->node->cond); $conditionDispatcher->setContext($this); $condition = $conditionDispatcher->dispatch(); $thenDispatcher = new NodesDispatcher($this->node->stmts); $thenDispatcher->setContext($this); $thenStatements = $thenDispatcher->dispatch(); if ($this->node->elseifs) { $elseIfDispatcher = new NodesDispatcher($this->node->elseifs); $elseIfDispatcher->setContext($this); $elseIfs = $elseIfDispatcher->dispatch(); } if ($this->node->else) { $elseDispatcher = new NodesDispatcher($this->node->else->stmts); $elseDispatcher->setContext($this); $elseStatements = $elseDispatcher->dispatch(); } $result = "if ({$condition}) {\n"; $result .= $this->indentationManager->indent($thenStatements) . "\n"; $result .= '}'; if (isset($elseIfs)) { foreach ($elseIfs as $elseIf) { $result .= " else "; $result .= $elseIf; } } if (isset($elseStatements)) { $result .= " else {\n"; $result .= $this->indentationManager->indent($elseStatements) . "\n"; $result .= '}'; } return $result; }
/** * @return string */ public function transpile() { $varDispatcher = new NodeDispatcher($this->node->var); $varDispatcher->setContext($this); $dimDispatcher = new NodeDispatcher($this->node->dim); $dimDispatcher->setContext($this); return $varDispatcher->dispatch() . '[' . $dimDispatcher->dispatch() . ']'; }
/** * @return string */ public function transpile() { $varDispatcher = new NodeDispatcher($this->node->var); $varDispatcher->setContext($this); $variable = $varDispatcher->dispatch(); $exprDispatcher = new NodeDispatcher($this->node->expr); $exprDispatcher->setContext($this); $expression = $exprDispatcher->dispatch(); return "{$variable} += {$expression};"; }
/** * @return array * @throws Exceptions\NotImplementedException */ public function dispatch() { $transpiledNodes = []; foreach ($this->nodes as $node) { $dispatcher = new NodeDispatcher($node); $dispatcher->setContext($this->context); $result = $dispatcher->dispatch(); foreach ($this->postHooks as $hook) { $result = $hook($node, $result); } $transpiledNodes[] = $result; } return $transpiledNodes; }
/** * @return string */ public function transpile() { $functionName = $this->node->name->toString(); $args = array(); foreach ($this->node->args as $arg) { $dispatcher = new NodeDispatcher($arg->value); $dispatcher->setContext($this); $args[] = $dispatcher->dispatch(); } if (isset($this->configuration->functions[$functionName])) { return $this->configuration->functions[$functionName]($args); } return $functionName . '(' . implode(',', $args) . ')'; }
/** * @return string */ public function transpile() { $init = $this->node->init; $cond = $this->node->cond; $loop = $this->node->loop; $body = $this->node->stmts; $parts = array('init', 'cond', 'loop', 'stmts'); foreach ($parts as $part) { $node = $this->node->{$part}; if (is_array($node)) { $dispatcher = new NodesDispatcher($node); } else { $dispatcher = new NodeDispatcher($node); } $dispatcher->setContext($this); ${$part} = $dispatcher->dispatch(); } $result = 'for (' . implode('', $init) . implode(';', $cond) . ';' . implode(';', $loop) . ') {' . PHP_EOL . implode(PHP_EOL, $stmts) . PHP_EOL . '}'; return $result; }
public function transpile() { $dispatcher = new NodeDispatcher($this->node->var); $dispatcher->setContext($this); return $dispatcher->dispatch() . '++'; }