Exemplo n.º 1
0
 function compile_with_declarations($options)
 {
     $code = $post = '';
     foreach ($this->expressions as $i => &$expr) {
         $expr = $expr->unwrap();
         if (!($expr instanceof yy_Comment || $expr instanceof yy_Literal)) {
             break;
         }
     }
     $options = array_merge($options, array('level' => LEVEL_TOP));
     if ($i) {
         $rest = array_splice($this->expressions, $i, count($this->expressions));
         // TODO: Figure out why there end up being missing newlines sometimes
         // (not important). The fix below isn't correct.
         $code = $this->compile_node($options) . "\n";
         $this->expressions = $rest;
     }
     $post = $this->compile_node($options);
     $scope = $options['scope'];
     if ($scope->expressions === $this) {
         if ($scope->has_declarations()) {
             $code .= $this->tab . 'var ' . implode(', ', $scope->declared_variables()) . ";\n";
         }
         if ($scope->has_assignments()) {
             $code .= $this->tab . 'var ' . multident(implode(', ', $scope->assigned_variables()), $this->tab) . ";\n";
         }
     }
     return $code . $post;
 }
Exemplo n.º 2
0
 function compile_with_declarations($options)
 {
     $code = $post = '';
     foreach ($this->expressions as $i => $expr) {
         $expr = $expr->unwrap();
         if (!($expr instanceof yy_Comment || $expr instanceof yy_Literal)) {
             break;
         }
     }
     $options = array_merge($options, array('level' => LEVEL_TOP));
     if ($i) {
         $rest = array_splice($this->expressions, $i, count($this->expressions));
         $code = $this->compile_node($options);
         $this->expressions = $rest;
     }
     $post = $this->compile_node($options);
     $scope = $options['scope'];
     if ($scope->expressions === $this) {
         if ($scope->has_declarations()) {
             $code .= $this->tab . 'var ' . implode(', ', $scope->declared_variables()) . ";\n";
         }
         if ($scope->has_assignments()) {
             $code .= $this->tab . 'var ' . multident(implode(', ', $scope->assigned_variables()), $this->tab) . ";\n";
         }
     }
     return $code . $post;
 }
Exemplo n.º 3
0
 function compile_node($options, $level = NULL)
 {
     $code = '/*' . multident($this->comment, $this->tab) . "\n{$this->tab}*/\n";
     if ($level === LEVEL_TOP || $options['level'] === LEVEL_TOP) {
         $code = $options['indent'] . $code;
     }
     return $code;
 }