Leafo\ScssPhp\Parser::parse PHP Method

parse() public method

Parser buffer
public parse ( string $buffer ) : Leafo\ScssPhp\Block
$buffer string
return Leafo\ScssPhp\Block
    public function parse($buffer)
    {
        // strip BOM (byte order marker)
        if (substr($buffer, 0, 3) === "") {
            $buffer = substr($buffer, 3);
        }
        $this->buffer = rtrim($buffer, "..");
        $this->count = 0;
        $this->env = null;
        $this->inParens = false;
        $this->eatWhiteDefault = true;
        $this->saveEncoding();
        $this->extractLineNumbers($buffer);
        $this->pushBlock(null);
        // root block
        $this->whitespace();
        $this->pushBlock(null);
        $this->popBlock();
        while ($this->parseChunk()) {
        }
        if ($this->count !== strlen($this->buffer)) {
            $this->throwParseError();
        }
        if (!empty($this->env->parent)) {
            $this->throwParseError('unclosed block');
        }
        if ($this->charset) {
            array_unshift($this->env->children, $this->charset);
        }
        $this->env->isRoot = true;
        $this->restoreEncoding();
        return $this->env;
    }

Usage Example

Beispiel #1
0
 /**
  * Import file
  *
  * @param string $path
  * @param array  $out
  */
 protected function importFile($path, $out)
 {
     // see if tree is cached
     $realPath = realpath($path);
     if (isset($this->importCache[$realPath])) {
         $this->handleImportLoop($realPath);
         $tree = $this->importCache[$realPath];
     } else {
         $code = file_get_contents($path);
         $parser = new Parser($path, false);
         $tree = $parser->parse($code);
         $this->addParsedFile($path);
         $this->importCache[$realPath] = $tree;
     }
     $pi = pathinfo($path);
     array_unshift($this->importPaths, $pi['dirname']);
     $this->compileChildren($tree->children, $out);
     array_shift($this->importPaths);
 }
All Usage Examples Of Leafo\ScssPhp\Parser::parse