diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2018-11-04 20:51:08 +0100 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2018-11-04 20:51:08 +0100 |
commit | dc150df8e19f13e836fde05f5401b0f99288815b (patch) | |
tree | 2dc4417055f9e69bd77dc74f7aba6b339bc00259 /src/Text/Pandoc/App | |
parent | 41b8ad6dd710c747c7f2e8541b0760b731d5be0b (diff) | |
download | pandoc-dc150df8e19f13e836fde05f5401b0f99288815b.tar.gz |
Add cabal flag `derive_json_via_th`
Disabling the flag will cause derivation of ToJSON and FromJSON
instances via GHC Generics instead of Template Haskell. The flag is
enabled by default, as deriving via Generics can be slow (see #4083).
Diffstat (limited to 'src/Text/Pandoc/App')
-rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index 9cbef3ee6..0fb88aeb3 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -2,8 +2,10 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TupleSections #-} +#ifdef DERIVE_JSON_VIA_TH +{-# LANGUAGE TemplateHaskell #-} +#endif {- Copyright (C) 2006-2018 John MacFarlane <jgm@berkeley.edu> @@ -46,7 +48,6 @@ import Control.Monad import Control.Monad.Trans import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder, defConfig, Indent(..), NumberFormat(..)) -import Data.Aeson.TH (deriveJSON, defaultOptions) import Data.Char (toLower, toUpper) import Data.List (intercalate, sort) import Data.Maybe (fromMaybe) @@ -65,6 +66,13 @@ import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL) import Text.Pandoc.Shared (ordNub, safeRead) import Text.Printf +#ifdef DERIVE_JSON_VIA_TH +import Data.Aeson.TH (deriveJSON, defaultOptions) +#else +import Data.Aeson (FromJSON (..), ToJSON (..), + defaultOptions, genericToEncoding) +#endif + #ifdef EMBED_DATA_FILES import Text.Pandoc.Data (dataFiles) import System.Directory (getAppUserDataDirectory) @@ -1086,5 +1094,15 @@ deprecatedOption o msg = -- see https://github.com/jgm/pandoc/pull/4083 -- using generic deriving caused long compilation times +#ifdef DERIVE_JSON_VIA_TH $(deriveJSON defaultOptions ''LineEnding) $(deriveJSON defaultOptions ''Opt) +#else +instance ToJSON LineEnding where + toEncoding = genericToEncoding defaultOptions +instance FromJSON LineEnding + +instance ToJSON Opt where + toEncoding = genericToEncoding defaultOptions +instance FromJSON Opt +#endif |