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;
}