Parse a single chunk off the head of the buffer and place it.
Signature
public function parseChunk()
Returns
false
when the buffer is empty, or there is an error This functions 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 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
then 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 doing 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.
When something is successfully parsed, depending on what it is, it is
placed in the document's tree by being put in the recursive structure
lessc::$env. $env is an anonymous object with a $store and a $parent.
$store is an associative array of all the objects held, and $parent is
the $env object one level above.
When parsing is complete on a valid document, there is only one $env
left and the $store member contains the block of the entire structure
of the document. This block can then be passed to compile block to
generate the CSS.