cies / htoml

TOML file format parser in Haskell
https://hackage.haskell.org/package/htoml
Other
38 stars 13 forks source link

Bug with nested tables and arrays #16

Open barrucadu opened 8 years ago

barrucadu commented 8 years ago
[[fruit.blah]]
  name = "apple"

  [fruit.blah.physical]
    color = "red"
    shape = "round"

[[fruit.blah]]
  name = "banana"

  [fruit.blah.physical]
    color = "yellow"
    shape = "bent"

From my reading of the toml spec, that should work, and give rise to the following JSON:

{  
   "fruit":{  
      "blah":[  
         {  
            "name":"apple",
            "physical":{  
               "color":"red",
               "shape":"round"
            }
         },
         {  
            "name":"banana",
            "physical":{  
               "color":"yellow",
               "shape":"bent"
            }
         }
      ]
   }
}

And tomlv accepts it:

$ tomlv -types fruit.toml                                                                                                                         ~
    fruit.blah                         ArrayHash
        fruit.blah.name                String
        fruit.blah.physical            Hash
            fruit.blah.physical.color  String
            fruit.blah.physical.shape  String
    fruit.blah                         ArrayHash
        fruit.blah.name                String
        fruit.blah.physical            Hash
            fruit.blah.physical.color  String
            fruit.blah.physical.shape  String

However attempting to parse with htoml gives Cannot redefine table ('fruit, blah, physical'.

cies commented 8 years ago

This is a very interesting issue. Thanks for reporting it.

cies commented 8 years ago

I've made a test case for it: https://github.com/cies/htoml/tree/fix/issue-16

@HuwCampbell This issue will need --as I can see it-- quite serious overhaul of the "implicitness tracking logic"; as we need to keep track of it "per array item". Any thoughts on this?

HuwCampbell commented 8 years ago

I don't think it should be that complicated, could be such that sub tables of the table arrays are filtered out of the parser state each time a new table array item is declared.