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

Support Arrays of Tables #88

Open
NfNitLoop opened this issue Dec 20, 2021 · 15 comments · Fixed by #100 or #104
Open

Support Arrays of Tables #88

NfNitLoop opened this issue Dec 20, 2021 · 15 comments · Fixed by #100 or #104
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed huge task

Comments

@NfNitLoop
Copy link

NfNitLoop commented Dec 20, 2021

I see this is already called out as a feature that's not yet implemented in the README:

❌ Array of Tables

I just wanted to make a ticket for it so folks can vote for it, and so I can get notified when it's implemented. (It's currently a blocker for my use case.)


My use case is this:

I want to support multiple configuration environments in one file. Like:

[[environments]]
name = "foo"
#

[[environments]]
name = "bar"
#

But that currently gives an error:

Not able to parse the key: [[environments]] as it contains invalid symbols. In case you would like to use special symbols - use quotes as it is required by TOML standard: "My key ~ with special % symbols"


Alternatively, I also tried a "Map of Tables" approach like this, but that didn't work either:

[environments.foo]
#

[environments.bar]
#

Error:

Invalid number of key-value arguments provided in the input for deserialization. Missing the required field <0> from class <kotlin.collections.LinkedHashMap> in the input

@orchestr7 orchestr7 self-assigned this Dec 21, 2021
@orchestr7 orchestr7 added good first issue Good for newcomers enhancement New feature or request labels Dec 21, 2021
@orchestr7 orchestr7 pinned this issue Dec 21, 2021
@orchestr7
Copy link
Owner

@NfNitLoop Thank you for this issue, I will pin it. I actually planned to start from it right now :)

@orchestr7
Copy link
Owner

orchestr7 commented Dec 21, 2021

A link for the SPEC: https://toml.io/en/v1.0.0#inline-table

What should we pay attention on:

  1. nested array of tables (may be later)
  2. If the parent of a table or array of tables is an array element, that element must already have been defined before the child can be defined (not sure if this is really needed):
# INVALID TOML DOC
[fruit.physical]  # subtable, but to which parent element should it belong?
color = "red"
shape = "round"

[[fruit]]  # parser must throw an error upon discovering that "fruit" is
           # an array rather than a table
name = "apple"
  1. Attempting to append to a statically defined array, even if that array is empty, must produce an error at parse time:
# INVALID TOML DOC
fruits = []

[[fruits]] # Not allowed
  1. Attempting to define a normal table with the same name as an already established array must produce an error at parse time. Attempting to redefine a normal table as an array must likewise produce a parse-time error.

@orchestr7
Copy link
Owner

Difficult part here is to understand how to represent such structure in a tree.

I suppose that we need to do the following:

  1. If the trimmed string starts with ''Parse [[ ]] and put it to some ArrayTableNode that will contain children TableNode
  2. each time we will append a TableNode to such array

@orchestr7 orchestr7 added the help wanted Extra attention is needed label Feb 5, 2022
@orchestr7 orchestr7 linked a pull request Feb 11, 2022 that will close this issue
@orchestr7
Copy link
Owner

orchestr7 commented Feb 16, 2022

Finally added the support for parsing of arrays of tables: #104
Next step is to make the decoding

@orchestr7 orchestr7 reopened this Feb 16, 2022
@orchestr7 orchestr7 linked a pull request Feb 16, 2022 that will close this issue
@orchestr7 orchestr7 reopened this Feb 16, 2022
@bishiboosh
Copy link
Collaborator

@akuleshov7 so what's still missing for array of tables to work ?

@orchestr7
Copy link
Owner

orchestr7 commented Apr 19, 2022

@akuleshov7 so what's still missing for array of tables to work ?

decoding process. I have added parsing, added tree structures, only decoding is missing now

@Wavesonics
Copy link
Contributor

@akuleshov7 any progress on decoding these? Just ran into this in my project

@sschuberth
Copy link

I'm interested in parsing cargo.lock files, see e.g. this. Am I correct to assume that this issue would need to get resolved for that first?

@orchestr7
Copy link
Owner

orchestr7 commented May 14, 2023

I'm interested in parsing cargo.lock files, see e.g. this. Am I correct to assume that this issue would need to get resolved for that first?

Oh, I missed that question, sorry. Yes, this is a blocker and we will take it as the highest priority. As I didn't know that Cargo has arrays of tables. Will take it into 0.6.0 release, as previously we thought that multiline arrays/strings and streaming had more priority and were focused on that.

This one is a very long story and I hope to finish it in the nearest months.

@sschuberth
Copy link

Will take it into 0.6.0 release

Thanks for prioritizing this!

@kubeliv
Copy link

kubeliv commented Jun 11, 2023

I am also patiently waiting for this feature! 🙂

@severinsch
Copy link

This is also a blocker for my use case, can you provide a rough timeline on when we can expect the new release?
🙏

@orchestr7
Copy link
Owner

This is also a blocker for my use case, can you provide a rough timeline on when we can expect the new release?
🙏

ktoml is community project, driven only by several people, so probably there are some time difficulties in supporting it. But you can also contribute and collaborate if it is a hard stopper for you, we will appreciate it 🙏

My personal estimation was to make it last month, but still did not get a chance for it. I will be on vacation next week, so probably I will give it a try…

Repository owner deleted a comment from sschuberth Jan 9, 2024
@orchestr7
Copy link
Owner

related issues:
#259
#254
#231

@mgroth0
Copy link

mgroth0 commented Apr 10, 2024

For anyone who needs this, I think a temporary workaround is to use TomlJ to convert the toml to json and then decode as json. Theoretically this should be very simple to swap for ktoml once it is ready.

Repository owner deleted a comment from sschuberth Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed huge task
Projects
None yet
8 participants