Exemple #1
0
 public function compile(Compiler $compiler)
 {
     $compiler->raw('array(');
     $elements = $this->getNode(self::NODE_ELEMENTS);
     $first = true;
     foreach ($elements as $element) {
         if (!$first) {
             $compiler->raw(',');
         }
         list($key, $value) = $element;
         if ($key) {
             if ($key instanceof Constant) {
                 $compiler->subcompile($key);
             } elseif ($key instanceof Name) {
                 $compiler->string($key->getName());
             }
             $compiler->raw(' => ');
         }
         $compiler->subcompile($value);
         $first = false;
     }
     $compiler->raw(')');
 }
Exemple #2
0
 public function compile(Compiler $compiler)
 {
     $args = $this->getNode(self::NODE_ARGS)->getNodes();
     $macroName = $this->getAttribute(self::ATTR_NAME);
     $compiler->writeln('// Line ' . $this->getLineNo())->write('public function macro_' . $macroName)->scopeIn(Compiler::SCOPE_MACRO, $macroName)->raw('( $context = [] , $arguments = [] ) {')->line()->indent()->writeln('$args = [')->indent();
     foreach ($args as $name => $value) {
         $compiler->write('')->string($name)->raw(' => ');
         if ($value) {
             $compiler->subcompile($value);
         } else {
             $compiler->raw('null');
         }
         $compiler->raw(',')->line();
     }
     $compiler->outdent()->writeln('];')->writeln('$context = array_merge( $context , $this->prepareArgs( $args , $arguments ) );')->subcompile($this->getNode(self::NODE_BODY))->scopeOut()->outdent()->writeln('}');
 }
Exemple #3
0
 public function compile(Compiler $compiler)
 {
     /** @var Node[] $tests */
     $tests = $this->getNode(self::NODE_TESTS);
     for ($i = 0; $i < count($tests); $i += 2) {
         $test = $tests[$i];
         $true = $tests[$i + 1];
         if ($i == 0) {
             $compiler->write('if ( ');
         } else {
             $compiler->raw(' elseif ( ');
         }
         $compiler->subcompile($test)->raw(' ) { ' . "\n")->indent()->subcompile($true)->outdent()->write('}');
     }
     if ($this->hasNode(self::NODE_ELSE)) {
         $compiler->raw(' else { ' . "\n")->indent()->subcompile($this->getNode(self::NODE_ELSE))->outdent()->write('}');
     }
     $compiler->line();
 }
Exemple #4
0
 private function renderMacros(Compiler $compiler)
 {
     /** @var Node[] $macros */
     $macros = $this->getNode(self::NODE_MACROS);
     foreach ($macros as $macro) {
         $compiler->subcompile($macro)->line();
     }
 }
Exemple #5
0
 function compile(Compiler $compiler)
 {
     $compiler->writeln('$_sandbox = $context;');
     $compiler->subcompile($this->body);
     $compiler->writeln('$context = $_sandbox;');
 }