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

Explain nesting and adding comments to documentation #51

Open
danilo-bc opened this issue Feb 16, 2023 · 6 comments
Open

Explain nesting and adding comments to documentation #51

danilo-bc opened this issue Feb 16, 2023 · 6 comments

Comments

@danilo-bc
Copy link

From the Wikipedia example on TOML (https://en.wikipedia.org/wiki/TOML#Example) it is possible to nest tags by adding the dot operator, as in [servers], [servers.alpha], [servers.beta], as well as adding comments to a TOML file.

I couldn't find the documentation for these features in this package's doc page (https://docs.julialang.org/en/v1/stdlib/TOML/)

I suppose the features are already built-in and only require explaining.

If not, is there any reason why they are not implemented?

@KristofferC
Copy link
Member

Hm, I am not sure it makes sense to duplicate the full TOML spec in the documentation for the specific TOML parser. It seems better to just read the official docs for that (https://toml.io/en/).

@danilo-bc
Copy link
Author

OK, but tags are implicitly defined in this package as dictionary tags. The TOML specification is language agnostic, but the way we have to organize variables in Julia to write out a valid TOML file is not.

It is not about duplicating the full TOML spec, but explaining how Julia constructs (dictionaries, arrays) should be organized so that you can TOML.print into a valid format.
i.e.: How do I write a comment using TOML.print? How would I write the example from the Wiki page, including the nested tags?

@KristofferC
Copy link
Member

I see, it is about output format.

There are currently only a few formatting options for the output. Comments for example are not written.

@danilo-bc
Copy link
Author

Yes. And also the fact that the sample data given in Julia's Docs

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]

Cannot be reproduced by simply reading the following example and altering variables, because it does not illustrate how to write down a tag like [database]

julia> using TOML

julia> data = Dict(
          "names" => ["Julia", "Julio"],
          "age" => [10, 20],
       );

<CODE REMOVED FOR BRIEFNESS>

julia> TOML.parsefile(fname)
Dict{String, Any} with 2 entries:
  "names" => ["Julia", "Julio"]
  "age"   => [10, 20]

By trial and error I found out that I can create tags by creating a Dict within a Dict with the tag name being the key.

@StefanKarpinski
Copy link
Member

I'm not really following the issue. Is it that it was unclear that the top-level structure would be a Dict?

@danilo-bc
Copy link
Author

Yes, it's in that sense. TOML has comments, tags and key-value pairs (something = "value"). The "names-age" example in the Julia docs covers key-value pairs.

I feel it lacks documentation on how to write comments, tags, and how to nest tags.

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

3 participants