Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested arrays of tables #353

Closed
yasammez opened this issue Sep 19, 2015 · 8 comments
Closed

Nested arrays of tables #353

yasammez opened this issue Sep 19, 2015 · 8 comments

Comments

@yasammez
Copy link

Hi everyone!

TOML has arrays:

array = [ [1, 0], [0, 1] ]
"array":[ [ 1, 0], [0, 1] ]

TOML has tables:

[table]
value = 1
"table":{ "value":1 }

TOML even has arraytables:

[[arraytable]]
value = 1
[[arraytable]]
value = 2
"arraytable":[ { "value":1 }, { "value":2} ]

But is there any way to do something like

"nested_array_table":[ 
  [ { "value":1 }, {"value":0} ], 
  [ {"value":0}, {"value":1, "comment":"bottom right diagonal element"} ] ]

in TOML? If so, how can I do this? If not, why can't I do this?

I understand that there is always a way around this, by for instance flattening arrays

[[matrix]]
value = 1
[[matrix]]
value = 0
[[matrix]]
value = 1
[[matrix]]
value = 0
comment = "bottom right diagonal element"

or introducing filler structs:

[[matrix.row]]
  [[matrix.row.column]]
  value = 1
  [[matrix.row.column]]
  value = 0
[[matrix.row]]
  [[matrix.row.column]]
  value = 1
  [[matrix.row.column]]
  value = 0
  comment = "bottom right diagonal element"

However, none of these seems really appropriate. Also, in that case, TOML would be strict less expressive than JSON, which is kind of a pitty, since JSON is so darn unreadable.

@yasammez
Copy link
Author

One possible idea for an extension, which, I admit, scales not very well, would be to add additional layers of brackets around the table names: one for each level of array depth:

[[[matrix]]]
value = 1
[[matrix]]
value = 0
[[[matrix]]]
value = 0
[[matrix]]
value = 1
comment = "bottom right diagonal element"

This would be equivalent to the following JSON:

"matrix":[ [ { "value":1 }, { "value":0 } ], [ { "value":0 }, { "value":1, "comment":"bottom right diagonal element" } ] ]

@sanmai-NL
Copy link

Why does the lack of a matrix notation make TOML strictly less expressive than JSON? I'm interested to know, since I'm not aware of any such notation in JSON.

@ChristianSi
Copy link
Contributor

ChristianSi commented May 19, 2016

@Fischmax: TOML has inline tables, so you should be able to write your example as follows (I think):

nested_array_table = [ 
    [ {value = 1}, {value = 0} ], 
    [ {value = 0}, {value = 1, comment = "bottom right diagonal element"} ] ]

@FranklinYu
Copy link

In #309 @jodastephen suggested an alternative grammar for array table:

[analyzers.filter]
  [#]
  type = "icu-tokenizer"

  [#]
  type = "lowercase"

  [#]
  type = "length"
  min = 2
  max = 35

If this is accepted, it can be easily extended to allow n-dimension matrix:

[nested_array_table]
  [#]
    [##]
    value = 1
    [##]
    value = 0

  [#]
    [##]
    value = 0
    [##]
    value = 1
    comment = "bottom right diagonal element"

@nikitindiz
Copy link

Any workaround?

@a-teammate a-teammate mentioned this issue Oct 14, 2017
26 tasks
@pradyunsg
Copy link
Member

IMO, this issue is a duplicate of #309. It can be closed in favour of that.

@pradyunsg
Copy link
Member

Closing as a duplicate of #309.

@tmccombs
Copy link

I disagree that this is a duplicate of #309. Related, certainly, but not a duplicate. Different syntax for arrays of tables, including several that were proposed on that thread, won't necessarily allow arrays of arrays of tables, and likewise support for arrays of arrays of tables could potentially be added without changing the existing syntax for arrays of tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants