Skip to content

Commit af98b91

Browse files
authored
toml: fix for 2 key related test exceptions and small clean up (#26154)
1 parent a640ddc commit af98b91

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

vlib/toml/parser/parser.v

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
16081626
pub fn (mut p Parser) eof() ast.EOF {
16091627
return ast.EOF{

vlib/toml/tests/toml_lang_test.v

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ const valid_exceptions = [
2020
'do_not_remove',
2121
'string/escapes.toml',
2222
'string/multiline-quotes.toml',
23-
'table/array-implicit-and-explicit-after.toml',
2423
]
2524
// NOTE: entries in this list are tests of invalid TOML that should have the parser fail, but currently does not.
2625
const invalid_exceptions = [
2726
'do_not_remove',
2827
'inline-table/duplicate-key-02.toml',
2928
'string/multiline-escape-space-02.toml',
3029
'string/missing-quotes-array.toml',
31-
'table/duplicate-key-dotted-array.toml',
3230
'table/append-with-dotted-keys-05.toml',
3331
'table/duplicate-key-03.toml',
3432
'table/duplicate-key-10.toml',

0 commit comments

Comments
 (0)