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

Create EDSL for manually specifying TOML data types #8

Closed
chshersh opened this issue Mar 29, 2018 · 0 comments
Closed

Create EDSL for manually specifying TOML data types #8

chshersh opened this issue Mar 29, 2018 · 0 comments
Assignees
Labels
ast Type of TOML

Comments

@chshersh
Copy link
Contributor

Sometimes you don't want to specify TOML in file, you want to have configuration embedded to code. Currently you can specify everything manually using HashMaps and constructors:

myToml :: TOML
myToml = TOML (fromList
    [ (Key "a", Bool True)
    , (Key "list", Array [String "one", String "two"])
    , (Key "time", Array [Date $ Day (fromGregorian 2018 3 29)])
    ] ) myInnerToml mempty

myInnerToml :: HashMap TableId TOML
myInnerToml = fromList $ [ ( TableId (NonEmpty.fromList ["table", "name", "1"])
                           , TOML (fromList [ (Key "aInner", Int 1)
                                            , (Key "listInner", Array [Bool True, Bool False])
                                            ]) myInnerInnerToml mempty
                           )
                         , ( TableId (NonEmpty.fromList ["table", "name", "2"])
                           , TOML (fromList [ (Key "2Inner", Int 42)
                                            ]) mempty mempty
                           )
                         ]

But this is ugly and not convenient. What would be great is to have some EDSL so the above can be configured like this:

myToml :: TOML
myToml = configure $ do
  "a"    :=: True
  "list" :=: ["one", "two"]
  "time" :=: Day (fromGregorian 2018 3 29) -- maybe something more convenient here
  table "table.name.1" $ do
    "aInner"    :=: 1
    "listInner" :=: [True, False]
    ...

The last one looks more convenient and simpler to me.

@chshersh chshersh added the ast Type of TOML label Mar 29, 2018
@chshersh chshersh added this to the v1.0.0: Public release milestone May 22, 2018
vrom911 added a commit that referenced this issue Jun 3, 2018
chshersh pushed a commit that referenced this issue Jun 3, 2018
* [#8] Create EDSL for tomland

* Add Value t Num and IsString, refactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast Type of TOML
Projects
None yet
Development

No branches or pull requests

2 participants