You are here

private function SassParser::sass2Token in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/SassParser.php \SassParser::sass2Token()

* Returns an object that contains the next source statement and meta data * about it from SASS source. * Sass statements are passed over. Statements spanning multiple lines, e.g. * CSS comments and selectors, are assembled into a single statement. *

Return value

object Statement token. Null if end of source.

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

File

phamlp/sass/SassParser.php, line 578

Class

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

Code

private function sass2Token() {
  $statement = '';

  // source line being tokenised
  $token = null;
  while (is_null($token) && !empty($this->source)) {
    while (empty($statement) && !empty($this->source)) {
      $source = array_shift($this->source);
      $statement = trim($source);
      $this->line++;
    }
    if (empty($statement)) {
      break;
    }
    $level = $this
      ->getLevel($source);

    // Comment statements can span multiple lines
    if ($statement[0] === self::BEGIN_COMMENT) {

      // Consume Sass comments
      if (substr($statement, 0, strlen(self::BEGIN_SASS_COMMENT)) === self::BEGIN_SASS_COMMENT) {
        unset($statement);
        while ($this
          ->getLevel($this->source[0]) > $level) {
          array_shift($this->source);
          $this->line++;
        }
        continue;
      }
      elseif (substr($statement, 0, strlen(self::BEGIN_CSS_COMMENT)) === self::BEGIN_CSS_COMMENT) {
        while ($this
          ->getLevel($this->source[0]) > $level) {
          $statement .= "\n" . ltrim(array_shift($this->source));
          $this->line++;
        }
      }
      else {
        $this->source = $statement;
        throw new SassException('Illegal comment type', array(), $this);
      }
    }
    elseif (substr($statement, -1) === SassRuleNode::CONTINUED) {

      // Build the selector statement
      while ($this
        ->getLevel($this->source[0]) === $level) {
        $statement .= ltrim(array_shift($this->source));
        $this->line++;
      }
    }
    $token = (object) array(
      'source' => $statement,
      'level' => $level,
      'filename' => $this->filename,
      'line' => $this->line - 1,
    );
  }
  return $token;
}