lessc_parser::parse PHP 메소드

parse() 공개 메소드

public parse ( $buffer )
    public function parse($buffer)
    {
        $this->count = 0;
        $this->line = 1;
        $this->env = null;
        // block stack
        $this->buffer = $this->writeComments ? $buffer : $this->removeComments($buffer);
        $this->pushSpecialBlock("root");
        $this->eatWhiteDefault = true;
        $this->seenComments = array();
        // trim whitespace on head
        // if (preg_match('/^\s+/', $this->buffer, $m)) {
        // 	$this->line += substr_count($m[0], "\n");
        // 	$this->buffer = ltrim($this->buffer);
        // }
        $this->whitespace();
        // parse the entire file
        $lastCount = $this->count;
        while (false !== $this->parseChunk()) {
        }
        if ($this->count != strlen($this->buffer)) {
            $this->throwError();
        }
        // TODO report where the block was opened
        if (!is_null($this->env->parent)) {
            throw new exception('parse error: unclosed block');
        }
        return $this->env;
    }

Usage Example

예제 #1
0
 function mixImport($import, $parentBlock, &$props)
 {
     list(, $url, $media) = $import;
     if (empty($media) && substr_compare($url, '.css', -4, 4) !== 0) {
         if ($this->importDisabled) {
             $props[] = array('raw', '/* import disabled */');
             return true;
         }
         $realPath = $this->findImport($url);
         if (!is_null($realPath)) {
             $this->addParsedFile($realPath);
             $parser = new lessc_parser($this, $realPath);
             $root = $parser->parse(file_get_contents($realPath));
             $root->isRoot = false;
             $root->parent = $parentBlock;
             // handle all the imports in the new file
             $pi = pathinfo($realPath);
             $this->mixImports($root, $pi['dirname'] . '/');
             // inject imported blocks into this block, local will overwrite import
             $parentBlock->children = array_merge($root->children, $parentBlock->children);
             // splice in the props
             foreach ($root->props as $prop) {
                 // leave a reference to the file where it came from
                 if (isset($prop[-1]) && !is_array($prop[-1])) {
                     $prop[-1] = array($parser, $prop[-1]);
                 }
                 $props[] = $prop;
             }
             return true;
         }
     }
     // fallback to regular css import
     $props[] = array('raw', '@import url("' . $url . '")' . ($media ? ' ' . $media : '') . ';');
     return false;
 }