Skip to content

Commit

Permalink
dhall-toml: support integers (#2469)
Browse files Browse the repository at this point in the history
The docs *said* we support integers, but that seems to not actually have
been empirically true (actually, most amusingly, fromInteger is partial
so it would crash TomlToDhall).

I fixed it.
  • Loading branch information
lf- committed Nov 10, 2022
1 parent efdb794 commit 6dd9dd3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dhall-toml/src/Dhall/DhallToToml.hs
Expand Up @@ -265,6 +265,7 @@ toToml :: TOML -> Key -> Expr Void Void -> Either CompileError TOML
toToml toml key expr = case expr of
Core.BoolLit a -> return $ insertPrim (Toml.Value.Bool a)
Core.NaturalLit a -> return $ insertPrim (Toml.Value.Integer $ toInteger a)
Core.IntegerLit a -> return $ insertPrim (Toml.Value.Integer a)
Core.DoubleLit (DhallDouble a) -> return $ insertPrim (Toml.Value.Double a)
Core.TextLit (Core.Chunks [] a) -> return $ insertPrim (Toml.Value.Text a)
Core.App Core.None _ -> return toml
Expand Down Expand Up @@ -327,6 +328,7 @@ toToml toml key expr = case expr of
-- be represented as inline tables.
isInline v = case v of
Core.BoolLit _ -> True
Core.IntegerLit _ -> True
Core.NaturalLit _ -> True
Core.DoubleLit _ -> True
Core.TextLit _ -> True
Expand All @@ -348,6 +350,7 @@ toToml toml key expr = case expr of
toAny :: Expr Void Void -> Either CompileError Toml.AnyValue.AnyValue
toAny e = case e of
Core.BoolLit x -> rightAny $ Toml.Value.Bool x
Core.IntegerLit x -> rightAny $ Toml.Value.Integer x
Core.NaturalLit x -> rightAny $ Toml.Value.Integer $ toInteger x
Core.DoubleLit (DhallDouble x) -> rightAny $ Toml.Value.Double x
Core.TextLit (Core.Chunks [] x) -> rightAny $ Toml.Value.Text x
Expand Down
1 change: 1 addition & 0 deletions dhall-toml/src/Dhall/TomlToDhall.hs
Expand Up @@ -171,6 +171,7 @@ tomlToDhall schema toml = toDhall (Core.normalize schema) (tomlToObject toml)
tomlValueToDhall :: Expr Src Void -> Value t -> Either CompileError (Expr Src Void)
tomlValueToDhall exprType v = case (exprType, v) of
(Core.Bool , Value.Bool a ) -> Right $ Core.BoolLit a
(Core.Integer , Value.Integer a) -> Right $ Core.IntegerLit a
(Core.Natural , Value.Integer a) -> Right $ Core.NaturalLit $ fromInteger a
(Core.Double , Value.Double a ) -> Right $ Core.DoubleLit $ DhallDouble a
(Core.Text , Value.Text a ) -> Right $ Core.TextLit $ Core.Chunks [] a
Expand Down
1 change: 1 addition & 0 deletions dhall-toml/tasty/data/inline-list-schema.dhall
Expand Up @@ -3,6 +3,7 @@
, lists : List (List Natural)
, nested :
{ floats : List Double
, ints : List Integer
, moreLists : List (List Natural)
}
, nested1 :
Expand Down
1 change: 1 addition & 0 deletions dhall-toml/tasty/data/inline-list.dhall
Expand Up @@ -3,6 +3,7 @@
, lists = [[1, 2], [3, 4], [] : List Natural]
, nested =
{ floats = [1.1, 2.2]
, ints = [-5, +2]
, moreLists = [[1, 2], [3, 4], [] : List Natural]
}
, nested1 =
Expand Down
1 change: 1 addition & 0 deletions dhall-toml/tasty/data/inline-list.toml
Expand Up @@ -4,6 +4,7 @@ lists = [[1, 2], [3, 4], []]

[nested]
floats = [1.1, 2.2]
ints = [-5, 2]
moreLists = [[1, 2], [3, 4], []]

[nested1]
Expand Down

0 comments on commit 6dd9dd3

Please sign in to comment.