private function processKeyValue()
{
$quotesKey = false;
if (Lexer::TOKEN_QUOTES === $this->lexer->getCurrentToken()->getType()) {
$quotesKey = true;
$this->lexer->getToken();
if (Lexer::TOKEN_STRING !== $this->lexer->getCurrentToken()->getType()) {
throw new ParseException(sprintf('Syntax error: expected string. Key: %s', $this->lexer->getCurrentToken()->getValue()), $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
$key = $this->lexer->getCurrentToken()->getValue();
$this->lexer->getToken();
} else {
$key = $this->lexer->getCurrentToken()->getValue();
while ($this->isTokenValidForKey($this->lexer->getToken())) {
$key = $key . $this->lexer->getCurrentToken()->getValue();
}
}
if ($quotesKey) {
if (Lexer::TOKEN_QUOTES === $this->lexer->getCurrentToken()->getType()) {
$this->lexer->getToken();
} else {
throw new ParseException(sprintf('Syntax error: expected quotes for closing key: %s', $key), $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
}
if (Lexer::TOKEN_EQUAL !== $this->lexer->getCurrentToken()->getType()) {
throw new ParseException(sprintf('Syntax error: expected equal near the key: %s', $key), $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
$key = trim($key);
if (false === $this->isValidKey($key, $quotesKey)) {
throw new ParseException(sprintf('Syntax error: the key %s is invalid. A key without embraces can not contains white spaces', $key), $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
if (array_key_exists($key, $this->data)) {
throw new ParseException(sprintf('Syntax error: the key %s has already been defined', $key), $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
switch ($this->lexer->getToken()->getType()) {
case Lexer::TOKEN_QUOTES:
case Lexer::TOKEN_TRIPLE_QUOTES:
case Lexer::TOKEN_QUOTE:
case Lexer::TOKEN_TRIPLE_QUOTE:
$this->data[$key] = $this->getStringValue($this->lexer->getCurrentToken());
break;
case Lexer::TOKEN_LKEY:
$this->processInlineTable($key);
break;
case Lexer::TOKEN_LBRANK:
$this->data[$key] = $this->getArrayValue();
break;
case Lexer::TOKEN_LITERAL:
$this->data[$key] = $this->getLiteralValue();
break;
default:
throw new ParseException('Syntax error: expected data type', $this->currentLine, $this->lexer->getCurrentToken()->getValue());
}
}