Sha256: 030d3ad3f0bdf98c54b786b3c326d8638089149162853a98131feaed3aa6f5b4

Contents?: true

Size: 1.71 KB

Versions: 10

Compression:

Stored size: 1.71 KB

Contents

<?php

namespace CoffeeScript;

class yy_Splat extends yy_Base
{
  public $children = array('name');

  static function compile_splatted_array($options, $list, $apply = FALSE)
  {
    $index = -1;

    while (isset($list[++$index]) && ($node = $list[$index]) && ! ($node instanceof yy_Splat))
    {
      continue;
    }

    if ($index >= count($list))
    {
      return '';
    }

    if (count($list) === 1)
    {
      $code = $list[0]->compile($options, LEVEL_LIST);

      if ($apply)
      {
        return $code;
      }

      return utility('slice').".call({$code})";
    }

    $args = array_slice($list, $index);

    foreach ($args as $i => $node)
    {
      $code = $node->compile($options, LEVEL_LIST);
      $args[$i] = ($node instanceof yy_Splat) ? utility('slice').".call({$code})" : "[{$code}]";
    }

    if ($index === 0)
    {
      return $args[0].'.concat('.implode(', ', array_slice($args, 1)).')';
    }

    $base = array();

    foreach (array_slice($list, 0, $index) as $node)
    {
      $base[] = $node->compile($options, LEVEL_LIST);
    }

    return '['.implode(', ', $base).'].concat('.implode(', ', $args).')';
  }

  function constructor($name)
  {
    if (is_object($name))
    {
      $this->name = $name;
    }
    else
    {
      $this->name = yy('Literal', $name);
    }

    return $this;
  }

  function assigns($name)
  {
    return $this->name->assigns($name);
  }

  function compile($options, $level = NULL)
  {
    if (isset($this->index) && $this->index)
    {
      return $this->compile_param($options);
    }
    else
    {
      return $this->name->compile($options);
    }
  }

  function is_assignable()
  {
    return TRUE;
  }

  function unwrap()
  {
    return $this->name;
  }
}

?>

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
guard-mthaml-0.4.0 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.3.1 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.3.0 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.2.5 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.2.4 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.2.3 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.2.2 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.2.1 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.2.0 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php
guard-mthaml-0.1.0 vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php