コード例 #1
0
 /**
  * @return string
  */
 public function transpile()
 {
     $dispatcher = new NodesDispatcher([$this->node->left, $this->node->right]);
     $dispatcher->setContext($this);
     $expressions = $dispatcher->dispatch();
     return $this->join($expressions[0], $expressions[1]);
 }
コード例 #2
0
 /**
  * @return string
  */
 public function transpile()
 {
     $dispatcher = new NodesDispatcher($this->node->exprs);
     $dispatcher->setContext($this);
     $expressions = $dispatcher->dispatch();
     return 'console.log(' . implode(' + ', $expressions) . ');';
 }
コード例 #3
0
 /**
  * @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;
 }
コード例 #4
0
 /**
  * @return string
  */
 public function transpile()
 {
     $expressionDispatcher = new NodesDispatcher([$this->node->var, $this->node->expr]);
     $expressionDispatcher->setContext($this);
     list($variable, $expression) = $expressionDispatcher->dispatch();
     return "{$variable} = {$expression};";
 }
 /**
  * @return string
  */
 public function transpile()
 {
     $dispatcher = new NodesDispatcher([$this->node->left, $this->node->right]);
     $dispatcher->setContext($this);
     $dispatcher->addPostTranspilationHook(function (Node $node, $result) {
         if ($node->getType() == 'Expr_BinaryOp_Plus' || $node->getType() == 'Expr_BinaryOp_Minus') {
             return '(' . $result . ')';
         }
         return $result;
     });
     $expressions = $dispatcher->dispatch();
     return $this->join($expressions[0], $expressions[1]);
 }
コード例 #6
0
 /**
  * @return string
  */
 public function transpile()
 {
     $this->indentationManager = new IndentationManager($this->configuration);
     $dispatcher = new NodesDispatcher($this->ast);
     $dispatcher->setContext($this);
     $transpiledAst = $dispatcher->dispatch();
     $result = '';
     if ($this->prependArray) {
         $result .= join("\n", $this->prependArray);
         $result .= "\n\n";
     }
     $result .= join("\n", $transpiledAst);
     return $result;
 }