htoml icon indicating copy to clipboard operation
htoml copied to clipboard

Bug with nested tables and arrays

Open barrucadu opened this issue 8 years ago • 3 comments

[[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'.

barrucadu avatar Jun 26 '16 23:06 barrucadu

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

cies avatar Jun 27 '16 10:06 cies

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?

cies avatar Jun 27 '16 11:06 cies

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.

HuwCampbell avatar Jun 29 '16 02:06 HuwCampbell