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

Add parsing of inline tables #14

Closed
chshersh opened this issue Apr 4, 2018 · 4 comments
Closed

Add parsing of inline tables #14

chshersh opened this issue Apr 4, 2018 · 4 comments
Labels
Hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Extra attention is needed parser Everything related to `Text -> Toml`

Comments

@chshersh
Copy link
Contributor

chshersh commented Apr 4, 2018

This might be convenient with #13.

@chshersh chshersh added the parser Everything related to `Text -> Toml` label Apr 4, 2018
@chshersh chshersh added this to the v1.0.0: Public release milestone May 22, 2018
@vrom911
Copy link
Member

vrom911 commented Sep 30, 2018

Blocked by #13

@vrom911 vrom911 added help wanted Extra attention is needed Hacktoberfest https://hacktoberfest.digitalocean.com/ labels Sep 30, 2018
@jiegillet
Copy link
Collaborator

I played around a bit and I wrote a parser for inline tables, but it only works for simple key/value pairs at the moment.
When I tried to parse

table = { x = 1, y = 2, subtable = { deep = true } }

I realized that it's much harder because key/value pairs and tables are stored in different data structures. Related problem:

x = 1
table = { hello = "world"}
y = 2

which should be the same as

x = 1
y = 2
table = { hello = "world"}

won't be parsed easily since it once again mixes key/value and table data types. One possibility to change that is to make the parsers return TOML values and fuse them later.

I also ran into something that bothers me a bit. The toml files

[dog]
type.name = "pug"

and

dog.type.name = "pug"

or

[dog.type]
name = "pug"

should, to my understanding, be parsed to the same tree, but since keys associated to values are separate from the table keys, all three input are saved differently. I think they should all be saved as the last input would be. That would probably help in checking name collisions and such.

What do you think?

@chshersh
Copy link
Contributor Author

@jiegillet

should, to my understanding, be parsed to the same tree

I don't think this should be parsed to the same tree. Maybe only if you parse and then convert to JSON these configurations can have the same structure. But with TOML you can visually separate keys on tables and key-value pairs. There're two reasons to store keys and tables separately — optimisations and simplicity.

You can see more uniform way to represent TOML in this library:

But the goal of tomland is not to be able to parse structurally equivalent configurations, it's more about more clear specification of configuration format and adding restrictions. Also, it brings a lot of complexity to the code if you want to be able to specify path for key like dog.type.name and be able to parse different TOML configurations. Probably somebody can do this in different library 🙂

Regarding parsing things like this one:

x = 1
table = { hello = "world"}
y = 2

I think that solution can be to replace the type of keyValP from the current one:

keyValP :: Parser (Key, AnyValue)

To something like:

keyValP :: Parser (Key, Either TOML AnyValue)

And then you can convert [(Key, TOML)] and [(Key, Either TOML AnyValue)] to TOML.

@jiegillet
Copy link
Collaborator

There're two reasons to store keys and tables separately — optimisations and simplicity.

Well then most of my problems go away, that's fine :)

I think that solution can be to replace the type of keyValP from the current one
To something like:

keyValP :: Parser (Key, Either TOML AnyValue)

And then you can convert [(Key, TOML)] and [(Key, Either TOML AnyValue)] to TOML.

I had explored that idea for a bit before I questioned the key/value - table structure, I'm glad that it wasn't a stupid idea ^^

chshersh pushed a commit that referenced this issue Oct 31, 2018
* Added containers dependency

* Added _Int and 4 list-type bimaps

* used nonEmpty and cosmetic changes

* Added ScopedTypeVariables to default extensions and removed from Combinators.hs

* Made _BoundedInteger polymorphic

* Parsing inline tables

inline table treated with kev/value

bug fix

clean code

* [#110] Example of TOML for the benchmarks (#114)

* [#110] Add toml with data type

* Improve FruitInside and SizeInside

* Fix array to homogrneous

* Delete

* Add -02

* Swap digit with letter

* Delete tomlData, fix types and names

* Fix style

* Changed hasKeyP signature

* Signature for ditribute

* Unit tests for hasKeyP

* Test was incorrect

* text instead of char in tableNameP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Extra attention is needed parser Everything related to `Text -> Toml`
Projects
None yet
Development

No branches or pull requests

3 participants