You are here

private function SassParser::createToken in Sassy 7

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

* Returns an object that contains the source statement and meta data about * it. * If the statement is just and end block we update the meta data and return null. *

Parameters

string source statement: * @return SassToken

1 call to SassParser::createToken()
SassParser::scss2Token in phamlp/sass/SassParser.php
* Returns an object that contains the next source statement and meta data * about it from SCSS source. *

File

phamlp/sass/SassParser.php, line 744

Class

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

Code

private function createToken($statement) {
  static $level = 0;
  $this->line += substr_count($statement, "\n");
  $statement = trim($statement);
  if (substr($statement, 0, strlen(self::BEGIN_CSS_COMMENT)) !== self::BEGIN_CSS_COMMENT) {
    $statement = str_replace(array(
      "\n",
      "\r",
    ), '', $statement);
  }
  $last = substr($statement, -1);

  // Trim the statement removing whitespace, end statement (;), begin block ({), and (unless the statement ends in an interpolation block) end block (})
  $statement = rtrim($statement, ' ' . self::BEGIN_BLOCK . self::END_STATEMENT);
  $statement = preg_match('/#\\{.+?\\}$/i', $statement) ? $statement : rtrim($statement, self::END_BLOCK);
  $token = $statement ? (object) array(
    'source' => $statement,
    'level' => $level,
    'filename' => $this->filename,
    'line' => $this->line,
  ) : null;
  $level += $last === self::BEGIN_BLOCK ? 1 : ($last === self::END_BLOCK ? -1 : 0);
  return $token;
}