Skip to content

Commit 68da434

Browse files
mmhatGabriella439
andauthored
Dhall quasi-quoter (#2198)
* 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]>
1 parent 3a42c98 commit 68da434

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

dhall/src/Dhall/TH.hs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
module Dhall.TH
99
( -- * Template Haskell
1010
staticDhallExpression
11+
, dhall
1112
, makeHaskellTypeFromUnion
1213
, makeHaskellTypes
1314
, HaskellType(..)
@@ -18,7 +19,7 @@ import Data.Text.Prettyprint.Doc (Pretty)
1819
import Dhall (FromDhall, ToDhall)
1920
import Dhall.Syntax (Expr (..))
2021
import GHC.Generics (Generic)
21-
import Language.Haskell.TH.Quote (dataToExpQ)
22+
import Language.Haskell.TH.Quote (QuasiQuoter (..), dataToExpQ)
2223

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

87+
{-| A quasi-quoter for Dhall expressions.
88+
89+
This quoter is build on top of 'staticDhallExpression'. Therefore consult the
90+
documentation of that function for further information.
91+
92+
This quoter is meant to be used in expression context only; Other contexts
93+
like pattern contexts or declaration contexts are not supported and will
94+
result in an error.
95+
-}
96+
dhall :: QuasiQuoter
97+
dhall = QuasiQuoter
98+
{ quoteExp = staticDhallExpression . Text.pack
99+
, quotePat = const $ error "dhall quasi-quoter: Quoting patterns is not supported!"
100+
, quoteType = const $ error "dhall quasi-quoter: Quoting types is not supported!"
101+
, quoteDec = const $ error "dhall quasi-quoter: Quoting declarations is not supported!"
102+
}
103+
86104
{-| Convert a Dhall type to a Haskell type that does not require any new
87105
data declarations beyond the data declarations supplied as the first
88106
argument

0 commit comments

Comments
 (0)