on de41665 help sign in
44 lines 946 B history raw
1{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE TemplateHaskell #-}
5module Data.Yaml.TH
6 ( -- * Decoding
7 decodeFile
8 -- * Re-exports from "Data.Yaml"
9 , Value (..)
10 , Parser
11 , Object
12 , Array
13 , object
14 , array
15 , (.=)
16 , (.:)
17 , (.:?)
18 , (.!=)
19 , FromJSON (..)
20 ) where
22import Data.Yaml hiding (decodeFile)
23import Language.Haskell.TH
24import Language.Haskell.TH.Syntax
26-- | Decode a @yaml@ file at compile time. Only available on GHC version @7.8.1@
27-- or higher.
28--
29-- @since 0.8.19.0
30--
31-- ==== __Examples__
32--
33-- @
34-- {-\# LANGUAGE TemplateHaskell \#-}
35--
36-- config :: Config
37-- config = $$('decodeFile' "config.yaml")
38-- @
39decodeFile :: forall a. (Lift a, FromJSON a) => FilePath -> Q (TExp a)
40decodeFile path = do
41 addDependentFile path
42 runIO (decodeFileEither path) >>= \case
43 Left err -> fail (prettyPrintParseException err)
44 Right x -> fmap TExp (lift (x :: a))