Skip to content

Commit

Permalink
Dhall quasi-quoter (#2198)
Browse files Browse the repository at this point in the history
* Added quasi-quoter for Dhall expressions

* Run stylish-haskell on Dhall.TH

* Updated error messages

Co-authored-by: Gabriel Gonzalez <[email protected]>

Co-authored-by: Gabriel Gonzalez <[email protected]>
  • Loading branch information
mmhat and Gabriella439 authored May 26, 2021
1 parent 3a42c98 commit 68da434
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion dhall/src/Dhall/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
module Dhall.TH
( -- * Template Haskell
staticDhallExpression
, dhall
, makeHaskellTypeFromUnion
, makeHaskellTypes
, HaskellType(..)
Expand All @@ -18,7 +19,7 @@ import Data.Text.Prettyprint.Doc (Pretty)
import Dhall (FromDhall, ToDhall)
import Dhall.Syntax (Expr (..))
import GHC.Generics (Generic)
import Language.Haskell.TH.Quote (dataToExpQ)
import Language.Haskell.TH.Quote (QuasiQuoter (..), dataToExpQ)

import Language.Haskell.TH.Syntax
( Bang (..)
Expand Down Expand Up @@ -83,6 +84,23 @@ staticDhallExpression text = do
-- https://stackoverflow.com/questions/38143464/cant-find-inerface-file-declaration-for-variable)
liftText = fmap (AppE (VarE 'Text.pack)) . Syntax.lift . Text.unpack

{-| A quasi-quoter for Dhall expressions.
This quoter is build on top of 'staticDhallExpression'. Therefore consult the
documentation of that function for further information.
This quoter is meant to be used in expression context only; Other contexts
like pattern contexts or declaration contexts are not supported and will
result in an error.
-}
dhall :: QuasiQuoter
dhall = QuasiQuoter
{ quoteExp = staticDhallExpression . Text.pack
, quotePat = const $ error "dhall quasi-quoter: Quoting patterns is not supported!"
, quoteType = const $ error "dhall quasi-quoter: Quoting types is not supported!"
, quoteDec = const $ error "dhall quasi-quoter: Quoting declarations is not supported!"
}

{-| Convert a Dhall type to a Haskell type that does not require any new
data declarations beyond the data declarations supplied as the first
argument
Expand Down

0 comments on commit 68da434

Please sign in to comment.