emancu/toml-rb

Table Array Parse Error

Closed this issue · 4 comments

The following toml:

[parent.child1]
key = 'value'

[[parent.child2]]
key = 'value'

[[parent.child2]]
key = 'value'

Results in the following parse error:

[8] pry(main)> TOML.parse <<-EOF
[8] pry(main)* [parent.child1]
[8] pry(main)* key = 'value'
[8] pry(main)* 
[8] pry(main)* [[parent.child2]]
[8] pry(main)* key = 'value'
[8] pry(main)* 
[8] pry(main)* [[parent.child2]]
[8] pry(main)* key = 'value'
[8] pry(main)* EOF
NoMethodError: undefined method `last' for {"child1"=>{"key"=>"value"}}:Hash
from /home/bram/Code/bramswenson/project/.bundle/bundle/ruby/2.2.0/gems/toml-rb-0.2.0/lib/toml/table_array.rb:12:in `block in navigate_keys'

Using ruby 2.2.0. That should be valid toml code yes?

@bramswenson I am not sure if it is valid, but seems to be.

So I'm fixing it right now and I'll push a new version at the end of the week when is well tested.

@bramswenson
@emancu
Hm... looking at the specifications at : https://github.com/toml-lang/toml
Under "Array of Tables" and main "Example", It isn't valid..

You have 2 options:

  • 1
    [servers]

  # You can indent as you please. Tabs or spaces. TOML don't care.
  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

  [servers.beta]
  ip = "10.0.0.2"
  dc = "eqdc10"
  • 2
[[fruit]]
  name = "apple"

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

  [[fruit.variety]]
    name = "red delicious"

  [[fruit.variety]]
    name = "granny smith"

[[fruit]]
  name = "banana"

  [[fruit.variety]]
    name = "plantain"

As yours was:

    [parent.child1]
key = 'value'

[[parent.child2]]
key = 'value'

[[parent.child2]]
key = 'value'

You are missing [parent] or [[parent]] at the head of the code before the '.child' starts.

@bararchy thanks for the info!

If we put a [[parent]] at the beginning it will work, but the issue remains if the first line is [parent].
So I fixed the issue for a hash containing a Table Array but this solution supports the toml file described above.

thanks!