You are here

private function SassParser::scss2Token in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/SassParser.php \SassParser::scss2Token()

Returns an object that contains the next source statement and meta data about it from SCSS source.

Return value

object Statement token. Null if end of source.

1 call to SassParser::scss2Token()
SassParser::getToken in phpsass/SassParser.php
Returns a token object that contains the next source statement and meta data about it.

File

phpsass/SassParser.php, line 741

Class

SassParser
SassParser class. Parses {@link http://sass-lang.com/ .sass and .sccs} files. @package PHamlP @subpackage Sass

Code

private function scss2Token() {
  static $srcpos = 0;

  // current position in the source stream
  static $srclen;

  // the length of the source stream
  $statement = '';
  $token = null;
  if (empty($srclen)) {
    $srclen = strlen($this->source);
  }
  while (is_null($token) && $srcpos < strlen($this->source)) {
    $c = $this->source[$srcpos++];
    switch ($c) {
      case self::BEGIN_COMMENT:
        if (substr($this->source, $srcpos - 1, strlen(self::BEGIN_SASS_COMMENT)) === self::BEGIN_SASS_COMMENT) {
          while ($this->source[$srcpos++] !== "\n") {
          }
          $statement .= "\n";
        }
        elseif (substr($this->source, $srcpos - 1, strlen(self::BEGIN_CSS_COMMENT)) === self::BEGIN_CSS_COMMENT) {
          if (ltrim($statement)) {
            if ($this->debug) {
              throw new SassException('Invalid comment', (object) array(
                'source' => $statement,
                'filename' => $this->filename,
                'line' => $this->line,
              ));
            }
          }
          $statement .= $c . $this->source[$srcpos++];
          while (substr($this->source, $srcpos, strlen(self::END_CSS_COMMENT)) !== self::END_CSS_COMMENT) {
            $statement .= $this->source[$srcpos++];
          }
          $srcpos += strlen(self::END_CSS_COMMENT);
          $token = $this
            ->createToken($statement . self::END_CSS_COMMENT);
        }
        else {
          $statement .= $c;
        }
        break;
      case self::DOUBLE_QUOTE:
      case self::SINGLE_QUOTE:
        $statement .= $c;
        while ($this->source[$srcpos] !== $c) {
          $statement .= $this->source[$srcpos++];
        }
        $statement .= $this->source[$srcpos++];
        break;
      case self::BEGIN_INTERPOLATION:
        $statement .= $c;
        if (substr($this->source, $srcpos - 1, strlen(self::BEGIN_INTERPOLATION_BLOCK)) === self::BEGIN_INTERPOLATION_BLOCK) {
          while ($this->source[$srcpos] !== self::END_BLOCK) {
            $statement .= $this->source[$srcpos++];
          }
          $statement .= $this->source[$srcpos++];
        }
        break;
      case self::BEGIN_BLOCK:
      case self::END_BLOCK:
      case self::END_STATEMENT:
        $token = $this
          ->createToken($statement . $c);
        if (is_null($token)) {
          $statement = '';
        }
        break;
      default:
        $statement .= $c;
        break;
    }
  }
  if (is_null($token)) {
    $srclen = $srcpos = 0;
  }
  return $token;
}