@@ -1,10 +1,13 @@
1{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE TemplateHaskell #-}
5module Data.Yaml.TH
5module Data.Yaml.TH
6 ( -- * Decoding
6 ( -- * Decoding
8+#if MIN_VERSION_template_haskell(2,9,0)
7− decodeFile
9+ , decodeFile
8 -- * Re-exports from "Data.Yaml"
11 -- * Re-exports from "Data.Yaml"
9 , Value (..)
12 , Value (..)
@@ -19,11 +22,16 @@ module Data.Yaml.TH
19 , FromJSON (..)
22 , FromJSON (..)
22−import Data.Yaml hiding (decodeFile)
25+import Data.Text.Encoding
26+import qualified Data.Text as T
23−import Language.Haskell.TH
27+import Language.Haskell.TH
24−import Language.Haskell.TH.Syntax
28+import Language.Haskell.TH.Syntax
29+import Language.Haskell.TH.Quote
31+import Data.Yaml hiding (decodeFile)
33+#if MIN_VERSION_template_haskell(2,9,0)
26−-- | Decode a @yaml@ file at compile time. Only available on GHC version @7.8.1@
34+-- | Decode a YAML file at compile time. Only available on GHC version @7.8.1@
27-- or higher.
35-- or higher.
29-- @since 0.8.19.0
37-- @since 0.8.19.0
@@ -42,3 +50,37 @@ decodeFile path = do
42 runIO (decodeFileEither path) >>= \case
50 runIO (decodeFileEither path) >>= \case
43 Left err -> fail (prettyPrintParseException err)
51 Left err -> fail (prettyPrintParseException err)
44 Right x -> fmap TExp (lift (x :: a))
52 Right x -> fmap TExp (lift (x :: a))
55+decodeValue :: String -> Either String Value
56+decodeValue = decodeEither . encodeUtf8 . T.pack
58+yamlExp :: String -> Q Exp
59+yamlExp input = case decodeValue input of
63+-- | A @QuasiQuoter@ for YAML.
70+-- {-\# LANGUAGE QuasiQuotes \#-}
71+-- import Data.Yaml.TH
80+yamlQQ = QuasiQuoter {
82+, quotePat = notDefined "quotePat"
83+, quoteType = notDefined "quoteType"
84+, quoteDec = notDefined "quoteDec"
86+ notDefined name _ = fail (name ++ " is not defined for yamlQQ")