Commit f09ac799 authored by yosymfony's avatar yosymfony
Browse files

Fixed bug #12: "Does not parse a table with an array of tables"

parent fd0cf776
......@@ -12,6 +12,7 @@ CHANGELOG
`LexerException` and `RuntimeException` have been removed.
* Added the inner exception when a `ParseException` is thrown in method `parse` of class `Toml`.
* Fixed bug #13: "Inline sub-tables don't work".
* Fixed bug #12: "Does not parse a table with an array of tables".
* Better support for dates as specified in the latest TOML spec. See PR #11.
0.3.3 (2015-08-24)
......
......@@ -550,7 +550,8 @@ class Parser extends AbstractParser
{
if (in_array($keyName, $this->keys, true) === true) {
$this->syntaxError(sprintf(
'The key "%s" has already been defined previously.', $keyName
'The key "%s" has already been defined previously.',
$keyName
));
}
......@@ -562,6 +563,7 @@ class Parser extends AbstractParser
$this->addKeyToKeyStore($keyName);
$this->keyOfTables[] = $keyName;
}
private function addArrayOfTableKeyToKeyStore(string $keyName) : void
{
if (isset($this->arrayOfTablekeyCounters[$keyName]) === false) {
......@@ -571,6 +573,8 @@ class Parser extends AbstractParser
$keyNameParts = explode('.', $keyName);
if ($this->isNecesaryToProcessImplicitKeyNameParts($keyNameParts)) {
array_pop($keyNameParts);
foreach ($keyNameParts as $keyNamePart) {
$this->keysOfImplicitArrayOfTables[] = implode('.', $keyNameParts);
array_pop($keyNameParts);
......@@ -579,7 +583,8 @@ class Parser extends AbstractParser
return;
}
if (in_array($keyName, $this->keysOfImplicitArrayOfTables) === true) {
if (in_array($keyName, $this->keysOfImplicitArrayOfTables) === true
&& isset($this->arrayOfTablekeyCounters[$keyName]) === false) {
$this->syntaxError(
sprintf('The array of tables "%s" has already been defined as previous table', $keyName)
);
......
......@@ -301,7 +301,8 @@ class TomlBuilder
{
if (in_array($key, $this->keyListArryOfTables)) {
throw new DumpException(
sprintf('The table %s has already been defined as previous array of tables', $key));
sprintf('The table %s has already been defined as previous array of tables', $key)
);
}
$this->currentTable = $key;
......@@ -320,7 +321,8 @@ class TomlBuilder
if (in_array($key, $this->keyListInvalidArrayOfTables)) {
throw new DumpException(
sprintf('The array of tables %s has already been defined as previous table', $key));
sprintf('The array of tables %s has already been defined as previous table', $key)
);
}
if (false == isset($this->keyListArryOfTables[$key])) {
......
......@@ -779,6 +779,35 @@ toml;
], $array);
}
/**
* @see https://github.com/yosymfony/toml/issues/12
*/
public function testParseMustParseATableAndArrayOfTables()
{
$toml = <<<'toml'
[fruit]
name = "apple"
[[fruit.variety]]
name = "red delicious"
[[fruit.variety]]
name = "granny smith"
toml;
$array = $this->parser->parse($toml);
$this->assertEquals([
'fruit' => [
'name' => 'apple',
'variety' => [
['name' => 'red delicious'],
['name' => 'granny smith'],
],
],
], $array);
}
public function testParseMustParseCommentsEverywhere()
{
$toml = <<<'toml'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment