Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dhall quasi-quoter #2198

Merged
merged 4 commits into from
May 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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