on master help sign in
Merge pull request #100 from mitchellwrosen/master

Add Data.Yaml.TH

commit4e3075b6a0408c5f067d42dc3dd1f62c413b65ed authorMichael Snoyman <michael@snoyman.com> dateSun 16 Oct 2016, 05:43 (10 years ago) parent64bf822a8ce1c6
3 files changed+54−3
ChangeLog.md+4 Data/Yaml/TH.hs+44 yaml.cabal+6−3
ChangeLog.md+4
@@ -1,3 +1,7 @@
1+## 0.8.19.0
2+
3+* Add `Data.Yaml.TH` module
4+
15## 0.8.18.7
26
37* Add `O_TRUNC` when opening files
Data/Yaml/TH.hsnew file+44
@@ -0,0 +1,44 @@
1+{-# LANGUAGE LambdaCase #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE TemplateHaskell #-}
4+
5+module 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
21+
22+import Data.Yaml hiding (decodeFile)
23+import Language.Haskell.TH
24+import Language.Haskell.TH.Syntax
25+
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+-- @
39+decodeFile :: forall a. (Lift a, FromJSON a) => FilePath -> Q (TExp a)
40+decodeFile path = do
41+ addDependentFile path
42+ runIO (decodeFileEither path) >>= \case
43+ Left err -> fail (prettyPrintParseException err)
44+ Right x -> fmap TExp (lift (x :: a))
yaml.cabal+6−3
@@ -1,5 +1,5 @@
11name: yaml
2−version: 0.8.18.7
2+version: 0.8.19.0
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
@@ -64,9 +64,12 @@ library
6464 Data.Yaml.Aeson
6565 Data.Yaml.Builder
6666 Data.Yaml.Config
67− Data.Yaml.Pretty
68− Data.Yaml.Parser
6967 Data.Yaml.Include
68+ Data.Yaml.Parser
69+ Data.Yaml.Pretty
70+ if impl(ghc >= 7.8.1)
71+ build-depends: template-haskell >= 2.8.0.0
72+ exposed-modules: Data.Yaml.TH
7073 other-modules:
7174 Data.Yaml.Internal
7275 ghc-options: -Wall