FOF30\Less\Parser\Parser::parseChunk PHP Method

parseChunk() protected method

Returns false when the buffer is empty, or when there is an error. This function is called repeatedly until the entire document is parsed. This parser is most similar to a recursive descent parser. Single functions represent discrete grammatical rules for the language, and they are able to capture the text that represents those rules. Consider the function lessc::keyword(). (all parse functions are structured the same) The function takes a single reference argument. When calling the function it will attempt to match a keyword on the head of the buffer. If it is successful, it will place the keyword in the referenced argument, advance the position in the buffer, and return true. If it fails then it won't advance the buffer and it will return false. All of these parse functions are powered by lessc::match(), which behaves the same way, but takes a literal regular expression. Sometimes it is more convenient to use match instead of creating a new function. Because of the format of the functions, to parse an entire string of grammatical rules, you can chain them together using &&. But, if some of the rules in the chain succeed before one fails, then the buffer position will be left at an invalid state. In order to avoid this, lessc::seek() is used to remember and set buffer positions. Before parsing a chain, use $s = $this->seek() to remember the current position into $s. Then if a chain fails, use $this->seek($s) to go back where we started.
protected parseChunk ( ) : boolean
return boolean
    protected function parseChunk()
    {
        if (empty($this->buffer)) {
            return false;
        }
        $s = $this->seek();
        // Setting a property
        if ($this->keyword($key) && $this->assign() && $this->propertyValue($value, $key) && $this->end()) {
            $this->append(array('assign', $key, $value), $s);
            return true;
        } else {
            $this->seek($s);
        }
        // Look for special css blocks
        if ($this->literal('@', false)) {
            $this->count--;
            // Media
            if ($this->literal('@media')) {
                if (($this->mediaQueryList($mediaQueries) || true) && $this->literal('{')) {
                    $media = $this->pushSpecialBlock("media");
                    $media->queries = is_null($mediaQueries) ? array() : $mediaQueries;
                    return true;
                } else {
                    $this->seek($s);
                    return false;
                }
            }
            if ($this->literal("@", false) && $this->keyword($dirName)) {
                if ($this->isDirective($dirName, $this->blockDirectives)) {
                    if (($this->openString("{", $dirValue, null, array(";")) || true) && $this->literal("{")) {
                        $dir = $this->pushSpecialBlock("directive");
                        $dir->name = $dirName;
                        if (isset($dirValue)) {
                            $dir->value = $dirValue;
                        }
                        return true;
                    }
                } elseif ($this->isDirective($dirName, $this->lineDirectives)) {
                    if ($this->propertyValue($dirValue) && $this->end()) {
                        $this->append(array("directive", $dirName, $dirValue));
                        return true;
                    }
                }
            }
            $this->seek($s);
        }
        // Setting a variable
        if ($this->variable($var) && $this->assign() && $this->propertyValue($value) && $this->end()) {
            $this->append(array('assign', $var, $value), $s);
            return true;
        } else {
            $this->seek($s);
        }
        if ($this->import($importValue)) {
            $this->append($importValue, $s);
            return true;
        }
        // Opening parametric mixin
        if ($this->tag($tag, true) && $this->argumentDef($args, $isVararg) && ($this->guards($guards) || true) && $this->literal('{')) {
            $block = $this->pushBlock($this->fixTags(array($tag)));
            $block->args = $args;
            $block->isVararg = $isVararg;
            if (!empty($guards)) {
                $block->guards = $guards;
            }
            return true;
        } else {
            $this->seek($s);
        }
        // Opening a simple block
        if ($this->tags($tags) && $this->literal('{')) {
            $tags = $this->fixTags($tags);
            $this->pushBlock($tags);
            return true;
        } else {
            $this->seek($s);
        }
        // Closing a block
        if ($this->literal('}', false)) {
            try {
                $block = $this->pop();
            } catch (exception $e) {
                $this->seek($s);
                $this->throwError($e->getMessage());
            }
            $hidden = false;
            if (is_null($block->type)) {
                $hidden = true;
                if (!isset($block->args)) {
                    foreach ($block->tags as $tag) {
                        if (!is_string($tag) || $tag[0] != $this->lessc->mPrefix) {
                            $hidden = false;
                            break;
                        }
                    }
                }
                foreach ($block->tags as $tag) {
                    if (is_string($tag)) {
                        $this->env->children[$tag][] = $block;
                    }
                }
            }
            if (!$hidden) {
                $this->append(array('block', $block), $s);
            }
            // This is done here so comments aren't bundled into he block that was just closed
            $this->whitespace();
            return true;
        }
        // Mixin
        if ($this->mixinTags($tags) && ($this->argumentValues($argv) || true) && ($this->keyword($suffix) || true) && $this->end()) {
            $tags = $this->fixTags($tags);
            $this->append(array('mixin', $tags, $argv, $suffix), $s);
            return true;
        } else {
            $this->seek($s);
        }
        // Spare ;
        if ($this->literal(';')) {
            return true;
        }
        // Got nothing, throw error
        return false;
    }