| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Dhall.DhallToToml
Contents
Description
This module exports the dhallToToml function for translating a
Dhall syntax tree to a TOML syntax tree (TOML) for the tomland
library.
For converting source code into a Dhall syntax tree see the dhall
package, and for converting the TOML syntax tree to source code see
the tomland package.
This module also exports dhallToTomlMain which implements the
dhall-to-toml command which converts Dhall source directly into
TOML source.
Not all Dhall expressions can be converted to TOML since TOML is not a programming language. The only things you can convert are:
BoolsNaturalsIntegersDoublesTextvaluesListsOptionalvalues- unions
- records
Additionally the Dhall top-level value being converted **must be a record** since TOML cannot represent bare values (ex. a single boolean or integer)
Dhall Bools translates to TOML bools:
$ dhall-to-toml <<< ' { t = True, f = False }'
f = false
t = trueDhall numbers translate to TOML numbers:
$ dhall-to-toml <<< '{ i = 1, d = 1.2 }'
d = 1.2
i = 1Dhall Text translates to TOML text:
$ dhall-to-toml <<< '{ t = "Hello!" }'
t = "Hello!"Dhall Lists of records translates to TOML array of tables:
$ dhall-to-toml <<< '{ l = [ { a = 1 } , { a = 2 }] }'
[[l]]
a = 1
[[l]]
a = 2All other Lists are translated to TOML inline lists:
$ dhall-to-toml <<< '{ l1 = [1, 2, 3], l2 = [[1, 1], [2, 2]] }'
l1 = [1, 2, 3]
l2 = [[1, 1], [2, 2]]Note, lists of lists of objects are currently not supported, for example, [[{a = 1}]] will not be converted.
Dhall Optional values are ignored if None or the unwraped value if Some
$ dhall-to-toml <<< '{ n = None Natural, s = Some 1 }'
s = 1Dhall records translate to TOML tables:
$ dhall-to-toml <<< '{ v = 1, r1 = { a = 1, b = 2, nested = { a = 3 } } }'
v = 1
[r]
a = 1
b = 2
[r.nested]
c = 3… and Prelude.Map.Type also translates to a TOML table:
$ dhall-to-toml <<< '[ { mapKey = "foo", mapValue = 1 } ]'
foo = 1Dhall unions translate to the wrapped value, or a string if the alternative is empty:
$ dhall-to-toml <<< '{ u = < A | B >.A }'
u = "A"
$ dhall-to-toml <<< '{ u = < A : Natural | B >.A 10}'
u = 10Also, all Dhall expressions are normalized before translation:
$ dhall-to-toml <<< ' { b = True == False }'
b = falseSynopsis
- dhallToToml :: Expr s Void -> Either CompileError TOML
- dhallToTomlMain :: IO ()
- data CompileError
Dhall To TOML
dhallToToml :: Expr s Void -> Either CompileError TOML Source #
Converts a Dhall expression into a tomland TOML expression
>>>:set -XOverloadedStrings>>>:set -XOverloadedLists>>>import Dhall.Core>>>import Toml.Type.Printer>>>f = makeRecordField>>>let toml = dhallToToml $ RecordLit [("foo", f $ NaturalLit 1), ("bar", f $ TextLit "ABC")]>>>toml == Right (TOML {tomlPairs = HashMap.fromList [("foo",AnyValue (Value.Integer 1)),("bar",AnyValue (Value.Text "ABC"))], tomlTables = HashMap.fromList [], tomlTableArrays = HashMap.fromList []})True>>>fmap Toml.Type.Printer.pretty tomlRight "bar = \"ABC\"\nfoo = 1\n"
dhallToTomlMain :: IO () Source #
Runs the dhall-to-toml command
Exceptions
data CompileError Source #
Instances
| Exception CompileError Source # | |
Defined in Dhall.DhallToToml Methods toException :: CompileError -> SomeException # fromException :: SomeException -> Maybe CompileError # displayException :: CompileError -> String # | |
| Show CompileError Source # | |
Defined in Dhall.DhallToToml Methods showsPrec :: Int -> CompileError -> ShowS # show :: CompileError -> String # showList :: [CompileError] -> ShowS # | |
| Eq CompileError Source # | |
Defined in Dhall.DhallToToml | |