Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module exports the tomlToDhall
function for translating a
TOML syntax tree from tomland
to a Dhall syntax tree. For now,
this package does not have type inference so a Dhall type is needed.
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 tomlToDhallMain
which implements the
toml-to-dhall
command which converts TOML source directly into
Dhall source.
In theory all TOML objects should be converted but there are some known
failure cases:
* Arrays of arrays of objects - not supported by tomland
* Arrays of heterogeneous primitive types - not supported by tomland
* Arrays of objects of different types are allowed (note that this
requires conversion to a Dhall union)
TOML bools translate to Dhall Bool
s:
$ cat schema.dhall { b : Bool } $ toml-to-dhall schema.dhall <<< 'b = true' { b = True }
TOML numbers translate to Dhall numbers:
$ cat schema.dhall { n : Natural, d : Double } $ toml-to-dhall schema.dhall << EOF n = 1 d = 3.14 EOF { d = 3.14, n = 1}
TOML text translates to Dhall Text
:
$ cat schema.dhall { t : Text } $ toml-to-dhall schema.dhall << EOF t = "Hello!" EOF { t = "Hello!" }
TOML arrays and table arrays translate to Dhall List
:
$ cat schema.dhall { nums : List Natural, tables : List { a : Natural, b : Text } } $ toml-to-dhall schema.dhall << EOF nums = [1, 2, 3] [[tables]] a = 1 b = "Hello," [[tables]] a = 2 b = " World!" EOF { nums = [ 1, 2, 3 ] , tables = [ { a = 1, b = "Hello," }, { a = 2, b = " World!" } ] }
Note, lists of lists of objects
and heterogeneous lists are not
supported by tomland
so a paraser error will be returned:
$ cat schema.dhall { list : List (<a : Natural | b : Bool>) } $ toml-to-dhall schema.dhall << EOF list = [1, true] EOF toml-to-dhall: invalid TOML: 1:12: | 1 | list = [1, true] | ^ unexpected 't' expecting ',', ']', or integer
Because of this, unions have limited use in lists, but can be used fully in tables:
$ cat schema.dhall { list : List (<a : Natural | b : Bool>), item : <a : Natural | b : Bool> } $ toml-to-dhall schema.dhall << EOF list = [1, 2] item = true EOF { item = < a : Natural | b : Bool >.b True , list = [ < a : Natural | b : Bool >.a 1, < a : Natural | b : Bool >.a 2 ] }
TOML tables translate to Dhall records:
$ cat schema.dhall { num : Natural, table : { num1 : Natural, table1 : { num2 : Natural } } } $ toml-to-dhall schema.dhall << EOF num = 0 [table] num1 = 1 [table.table1] num2 = 2 EOF { num = 0, table = { num1 = 1, table1.num2 = 2 } }
Documentation
tomlToDhallMain :: IO () Source #
data CompileError Source #
Instances
Exception CompileError Source # | |
Defined in Dhall.TomlToDhall | |
Show CompileError Source # | |
Defined in Dhall.TomlToDhall showsPrec :: Int -> CompileError -> ShowS # show :: CompileError -> String # showList :: [CompileError] -> ShowS # |