public function parse($value)
{
$this->lexer = new Lexer($value);
$this->lexer->getToken();
while ($this->lexer->getCurrentToken()->getType() !== Lexer::TOKEN_EOF) {
switch ($this->lexer->getCurrentToken()->getType()) {
case Lexer::TOKEN_HASH:
$this->processComment();
// #comment
break;
case Lexer::TOKEN_LBRANK:
$this->processTables();
// [table] or [[array of tables]]
break;
case Lexer::TOKEN_LITERAL:
case Lexer::TOKEN_QUOTES:
$this->processKeyValue();
// key = value or "key name" = value
break;
case Lexer::TOKEN_NEWLINE:
$this->currentLine++;
if ($this->inlineTableCounter > 0) {
throw new ParseException('Syntax error: unexpected newline inside a inline table', $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
break;
case Lexer::TOKEN_RKEY:
if (0 === $this->inlineTableCounter) {
throw new ParseException('Syntax error: unexpected token', $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
--$this->inlineTableCounter;
array_pop($this->inlineTableNameStack);
break;
case Lexer::TOKEN_COMMA:
if ($this->inlineTableCounter > 0) {
break;
} else {
throw new ParseException('Syntax error: unexpected token', $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
default:
throw new ParseException('Syntax error: unexpected token', $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
$this->lexer->getToken();
}
return empty($this->result) ? null : $this->result;
}