SamboyCoding / Tomlet

Zero-Dependency, model-based TOML De/Serializer for .NET
MIT License
155 stars 29 forks source link

Fail to load toml file with array-table #39

Open oldkingOK opened 6 months ago

oldkingOK commented 6 months ago

Using latest Tomlet (5.3.0)

Code

using Tomlet;
...
var doc = new TomlParser().Parse("test.toml")

test.toml

[[a.b]]
name = "nick"
ishuman = true

[[a.b]]
name = "jack"
ishuman = false

Log

Unhandled exception. Tomlet.Exceptions.MissingIntermediateInTomlTableArraySpecException: Missing intermediate definition for a.b in table-array specification on line 1. This is undefined behavior, and I chose to define it as an error.
   at Tomlet.TomlParser.ReadTableArrayStatement(TomletStringReader reader, TomlDocument document) in /_/Tomlet/TomlParser.cs:line 911
   at Tomlet.TomlParser.Parse(String input) in /_/Tomlet/TomlParser.cs:line 65
   at Tomlet.TomlParser.ParseFile(String filePath) in /_/Tomlet/TomlParser.cs:line 30
   at Program.Main(String[] args)
oldkingOK commented 6 months ago

It works with test.toml:

[[a]]

[[a.b]]
name = "nick"
ishuman = true

[[a.b]]
name = "jack"
ishuman = false

While the TOML 1.0.0 specification allows us to ignore the parent node definition.

SamboyCoding commented 4 months ago

Coming back to this, I'm not seeing anywhere in the TOML spec that actually says this is allowed, and they show many similar cases which are not allowed, so I'm not inclined to allow this behavior. There's a certain lack of clarity here - you're defining, essentially, an array b of name, ishuman on a table a, but you don't define a anywhere earlier, so it's ambiguous.