Safe Haskell | None |
---|---|
Language | Haskell2010 |
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:
Bool
sNatural
sInteger
sDouble
sText
valuesList
sOptional
values- 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 Bool
s translates to TOML bools:
$ dhall-to-toml <<< ' { t = True, f = False }' f = false t = true
Dhall numbers translate to TOML numbers:
$ dhall-to-toml <<< '{ i = 1, d = 1.2 }' d = 1.2 i = 1
Dhall Text
translates to TOML text:
$ dhall-to-toml <<< '{ t = "Hello!" }' t = "Hello!"
Dhall List
s of records translates to TOML array of tables:
$ dhall-to-toml <<< '{ l = [ { a = 1 } , { a = 2 }] }' [[l]] a = 1 [[l]] a = 2
All other List
s 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 = 1
Dhall 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
Dhall 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 = 10
Also, all Dhall expressions are normalized before translation:
$ dhall-to-toml <<< ' { b = True == False }' b = false
Synopsis
- 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 = fromList [("foo" :| [],Integer 1),("bar" :| [],Text "ABC")], tomlTables = fromList [], tomlTableArrays = fromList []})>>>
fmap Toml.Type.Printer.pretty toml
Right "bar = \"ABC\"\nfoo = 1\n"
dhallToTomlMain :: IO () Source #
Runs the dhall-to-toml
command
Exceptions
data CompileError Source #
Instances
Show CompileError Source # | |
Defined in Dhall.DhallToToml showsPrec :: Int -> CompileError -> ShowS # show :: CompileError -> String # showList :: [CompileError] -> ShowS # | |
Exception CompileError Source # | |
Defined in Dhall.DhallToToml |