@@ -649,18 +649,21 @@ pub fn (mut p Parser) root_table() ! {
649649 key := p.key ()!
650650 dotted_key := DottedKey ([key.str ()])
651651
652+ p.check_implicitly_declared (dotted_key) or {
653+ p.check_explicitly_declared (dotted_key) or {
654+ if p.root_map[key.str ()] or { ast.Bool{} } is map [string ]ast.Value {
655+ // NOTE: Here we "undo" the implicit-explicit special case declaration for:
656+ // https://github.com/toml-lang/toml-test/blob/576db852/tests/invalid/table/array-implicit.toml
657+ // ... to make the following test pass:
658+ // https://github.com/toml-lang/toml-test/blob/229ce2e/tests/valid/table/array-implicit-and-explicit-after.toml
659+ p.undo_special_case_01 (dotted_key)
660+ }
661+ }
662+ }
652663 // Disallow re-declaring the key
653664 p.check_explicitly_declared (dotted_key)!
654665 p.explicit_declared << dotted_key
655666
656- // Check for footgun redeclaration in this odd way:
657- // [[tbl]]
658- // [tbl]
659- if p.last_aot == dotted_key {
660- return error (@MOD + '.' + @STRUCT + '.' + @FN +
661- ' key `${dotted_key} ` has already been explicitly declared. Unexpected redeclaration at "${p.tok.kind} " "${p.tok.lit} " in this (excerpt): "...${p.excerpt()} ..."' )
662- }
663-
664667 // Allow [ key ]
665668 p.ignore_while (space_formatting)
666669
@@ -956,9 +959,10 @@ pub fn (mut p Parser) double_array_of_tables(mut table map[string]ast.Value) ! {
956959 } else {
957960 util.printdbg (@MOD + '.' + @STRUCT + '.' + @FN, 'implicit allocation of map for `${first} ` in dotted key `${dotted_key} `.' )
958961 nm = & map [string ]ast.Value{}
959- // We register this implicit allocation as *explicit* to be able to catch
960- // special cases like:
962+ p.implicit_declared << first
963+ // NOTE: We register this implicit allocation also as *explicit* to be able to catch a special case like:
961964 // https://github.com/toml-lang/toml-test/blob/576db852/tests/invalid/table/array-implicit.toml
965+ // See also: undo_special_case_01
962966 p.explicit_declared << first
963967 }
964968
@@ -974,12 +978,13 @@ pub fn (mut p Parser) double_array_of_tables(mut table map[string]ast.Value) ! {
974978 }
975979 }
976980
977- if table[p.last_aot.str ()] is map [string ]ast.Value {
978- if first == p.last_aot {
979- // Here we "undo" the implicit-explicit special-case declaration above to make the following test pass:
981+ if first == p.last_aot {
982+ if table[p.last_aot.str ()] is map [string ]ast.Value {
983+ // NOTE: Here we "undo" the implicit-explicit special case declaration for:
984+ // https://github.com/toml-lang/toml-test/blob/576db852/tests/invalid/table/array-implicit.toml
985+ // ... to make the following test pass:
980986 // https://github.com/toml-lang/toml-test/blob/229ce2e/tests/valid/array/open-parent-table.toml
981- p.explicit_declared.pop ()
982- p.last_aot.clear ()
987+ p.undo_special_case_01 (dotted_key)
983988 p.next ()!
984989 return
985990 }
@@ -1604,6 +1609,19 @@ pub fn (mut p Parser) time() !ast.Time {
16041609 }
16051610}
16061611
1612+ // undo_special_case_01 reverts an operation needed for a few special case / edge case tests to pass.
1613+ // See:
1614+ // https://github.com/toml-lang/toml-test/blob/576db852/tests/invalid/table/array-implicit.toml
1615+ // https://github.com/toml-lang/toml-test/blob/229ce2e/tests/valid/table/array-implicit-and-explicit-after.toml
1616+ // https://github.com/toml-lang/toml-test/blob/229ce2e/tests/valid/array/open-parent-table.toml
1617+ pub fn (mut p Parser) undo_special_case_01 (dotted_key DottedKey) {
1618+ exd_i := p.explicit_declared.index (dotted_key)
1619+ if exd_i > - 1 {
1620+ p.explicit_declared.delete (exd_i)
1621+ p.last_aot.clear ()
1622+ }
1623+ }
1624+
16071625// eof returns an `ast.EOF` type.
16081626pub fn (mut p Parser) eof () ast.EOF {
16091627 return ast.EOF{
0 commit comments