@@ -1,10 +1,10 @@
1{-# LANGUAGE LambdaCase #-}
1{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE TemplateHaskell #-}
5module Data.Yaml.TH
4module Data.Yaml.TH
6 ( -- * Decoding
5 ( -- * Decoding
8 -- * Re-exports from "Data.Yaml"
8 -- * Re-exports from "Data.Yaml"
9 , Value (..)
9 , Value (..)
@@ -19,9 +19,13 @@ module Data.Yaml.TH
19 , FromJSON (..)
19 , FromJSON (..)
22+import Data.Text.Encoding
23+import qualified Data.Text as T
24+import Language.Haskell.TH
25+import Language.Haskell.TH.Syntax
26+import Language.Haskell.TH.Quote
22−import Data.Yaml hiding (decodeFile)
28+import Data.Yaml hiding (decodeFile)
23−import Language.Haskell.TH
24−import Language.Haskell.TH.Syntax
26-- | Decode a @yaml@ file at compile time. Only available on GHC version @7.8.1@
30-- | Decode a @yaml@ file at compile time. Only available on GHC version @7.8.1@
27-- or higher.
31-- or higher.
@@ -42,3 +46,20 @@ decodeFile path = do
42 runIO (decodeFileEither path) >>= \case
46 runIO (decodeFileEither path) >>= \case
43 Left err -> fail (prettyPrintParseException err)
47 Left err -> fail (prettyPrintParseException err)
44 Right x -> fmap TExp (lift (x :: a))
48 Right x -> fmap TExp (lift (x :: a))
50+decodeValue :: String -> Either String Value
51+decodeValue = decodeEither . encodeUtf8 . T.pack
53+yamlExp :: String -> Q Exp
54+yamlExp input = case decodeValue input of
59+yamlQQ = QuasiQuoter {
61+, quotePat = notDefined "quotePat"
62+, quoteType = notDefined "quoteType"
63+, quoteDec = notDefined "quoteDec"
65+ notDefined name _ = fail (name ++ " is not defined for yamlQQ")