git.iko.soy/typeable/pandoc
on master help sign in
Remove derive_json_via_th flag; always use TH.

This cuts down on code duplication and reduces the chance for errors. See #4083.

commit8fb9a0d168517462860d6916c1f882958520988b authorJohn MacFarlane <jgm@berkeley.edu> dateMon 7 Oct 2019, 21:22 (7 years ago) parentb235a18
7 files changed+1−104
pandoc.cabal+1−9 src/Text/Pandoc/App/CommandLineOptions.hs−3 src/Text/Pandoc/App/Opt.hs−14 src/Text/Pandoc/Extensions.hs−18 src/Text/Pandoc/Filter.hs−13 src/Text/Pandoc/Options.hs−46 stack.yaml−1
pandoc.cabal+1−9
@@ -359,11 +359,6 @@ flag embed_data_files
359359 Description: Embed data files in binary for relocatable executable.
360360 Default: False
361361
362−flag derive_json_via_th
363− Description: Use Template Haskell instead of GHC Generics to derive ToJSON
364− and FromJSON instances.
365− Default: False
366−
367362flag trypandoc
368363 Description: Build trypandoc cgi executable.
369364 Default: False
@@ -441,9 +436,6 @@ library
441436 cpp-options: -DEMBED_DATA_FILES
442437 build-depends: file-embed >= 0.0 && < 0.1
443438 other-modules: Text.Pandoc.Data
444− if flag(derive_json_via_th)
445− cpp-options: -DDERIVE_JSON_VIA_TH
446− other-extensions: TemplateHaskell
447439 if os(windows)
448440 cpp-options: -D_WINDOWS
449441 ghc-options: -Wall -fno-warn-unused-do-bind
@@ -462,7 +454,7 @@ library
462454 -fhide-source-paths
463455
464456 default-language: Haskell2010
465− other-extensions: NoImplicitPrelude
457+ other-extensions: NoImplicitPrelude, TemplateHaskell
466458 hs-source-dirs: src
467459
468460 exposed-modules: Text.Pandoc,
src/Text/Pandoc/App/CommandLineOptions.hs−3
@@ -2,9 +2,6 @@
22{-# LANGUAGE CPP #-}
33{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE TupleSections #-}
5−#ifdef DERIVE_JSON_VIA_TH
6−{-# LANGUAGE TemplateHaskell #-}
7−#endif
85{- |
96 Module : Text.Pandoc.App.CommandLineOptions
107 Copyright : Copyright (C) 2006-2019 John MacFarlane
src/Text/Pandoc/App/Opt.hs−14
@@ -2,9 +2,7 @@
22{-# LANGUAGE NoImplicitPrelude #-}
33{-# LANGUAGE CPP #-}
44{-# LANGUAGE DeriveGeneric #-}
5−#ifdef DERIVE_JSON_VIA_TH
65{-# LANGUAGE TemplateHaskell #-}
7−#endif
86{- |
97 Module : Text.Pandoc.App.Opt
108 Copyright : Copyright (C) 2006-2019 John MacFarlane
@@ -36,11 +34,7 @@ import qualified Data.Text as T
3634import Data.Aeson (defaultOptions, Options(..), FromJSON(..), ToJSON(..),
3735 Value(..))
3836import Data.Aeson.Types (typeMismatch)
39−#ifdef DERIVE_JSON_VIA_TH
4037import Data.Aeson.TH (deriveJSON)
41−#else
42−import Data.Aeson (genericToEncoding)
43−#endif
4438
4539-- | The type of line-endings to be used when writing plain-text.
4640data LineEnding = LF | CRLF | Native deriving (Show, Generic)
@@ -203,16 +197,8 @@ defaultOpts = Opt
203197 , optStripComments = False
204198 }
205199
206−#ifdef DERIVE_JSON_VIA_TH
207200-- see https://github.com/jgm/pandoc/pull/4083
208201-- using generic deriving caused long compilation times
209202$(deriveJSON
210203 defaultOptions{ fieldLabelModifier =
211204 camelCaseToHyphenated . drop 3 } ''Opt)
212−#else
213−instance ToJSON Opt where
214− toEncoding = genericToEncoding
215− defaultOptions{ fieldLabelModifier =
216− camelCaseToHyphenated . drop 3 }
217−instance FromJSON Opt
218−#endif
src/Text/Pandoc/Extensions.hs−18
@@ -2,10 +2,8 @@
22{-# LANGUAGE NoImplicitPrelude #-}
33{-# LANGUAGE DeriveDataTypeable #-}
44{-# LANGUAGE DeriveGeneric #-}
5−#ifdef DERIVE_JSON_VIA_TH
65{-# LANGUAGE GeneralizedNewtypeDeriving #-}
76{-# LANGUAGE TemplateHaskell #-}
8−#endif
97{- |
108 Module : Text.Pandoc.Extensions
119 Copyright : Copyright (C) 2012-2019 John MacFarlane
@@ -41,13 +39,7 @@ import Data.Typeable (Typeable)
4139import GHC.Generics (Generic)
4240import Safe (readMay)
4341import Text.Parsec
44−
45−#ifdef DERIVE_JSON_VIA_TH
4642import Data.Aeson.TH (deriveJSON, defaultOptions)
47−#else
48−import Data.Aeson (FromJSON (..), ToJSON (..),
49− defaultOptions, genericToEncoding)
50−#endif
5143
5244newtype Extensions = Extensions Integer
5345 deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)
@@ -538,15 +530,5 @@ parseFormatSpec = parse formatSpec ""
538530 '+' -> (ext : extsToEnable, extsToDisable)
539531 _ -> (extsToEnable, ext : extsToDisable)
540532
541−#ifdef DERIVE_JSON_VIA_TH
542533$(deriveJSON defaultOptions ''Extension)
543534$(deriveJSON defaultOptions ''Extensions)
544−#else
545−instance ToJSON Extension where
546− toEncoding = genericToEncoding defaultOptions
547−instance FromJSON Extension
548−
549−instance ToJSON Extensions where
550− toEncoding = genericToEncoding defaultOptions
551−instance FromJSON Extensions
552−#endif
src/Text/Pandoc/Filter.hs−13
@@ -1,9 +1,7 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE DeriveGeneric #-}
33{-# LANGUAGE NoImplicitPrelude #-}
4−#ifdef DERIVE_JSON_VIA_TH
54{-# LANGUAGE TemplateHaskell #-}
6−#endif
75{- |
86 Module : Text.Pandoc.Filter
97 Copyright : Copyright (C) 2006-2019 John MacFarlane
@@ -21,12 +19,7 @@ module Text.Pandoc.Filter
2119 ) where
2220
2321import Prelude
24−#ifdef DERIVE_JSON_VIA_TH
2522import Data.Aeson.TH (deriveJSON, defaultOptions)
26−#else
27−import Data.Aeson (FromJSON (..), ToJSON (..),
28− defaultOptions, genericToEncoding)
29−#endif
3023import Data.Foldable (foldrM)
3124import GHC.Generics (Generic)
3225import Text.Pandoc.Class (PandocIO)
@@ -59,10 +52,4 @@ expandFilterPath :: Filter -> PandocIO Filter
5952expandFilterPath (LuaFilter fp) = LuaFilter <$> Path.expandFilterPath fp
6053expandFilterPath (JSONFilter fp) = JSONFilter <$> Path.expandFilterPath fp
6154
62−#ifdef DERIVE_JSON_VIA_TH
6355$(deriveJSON defaultOptions ''Filter)
64−#else
65−instance ToJSON Filter where
66− toEncoding = genericToEncoding defaultOptions
67−instance FromJSON Filter
68−#endif
src/Text/Pandoc/Options.hs−46
@@ -2,9 +2,7 @@
22{-# LANGUAGE DeriveDataTypeable #-}
33{-# LANGUAGE DeriveGeneric #-}
44{-# LANGUAGE NoImplicitPrelude #-}
5−#ifdef DERIVE_JSON_VIA_TH
65{-# LANGUAGE TemplateHaskell #-}
7−#endif
86{- |
97 Module : Text.Pandoc.Options
108 Copyright : Copyright (C) 2012-2019 John MacFarlane
@@ -42,13 +40,7 @@ import Skylighting (SyntaxMap, defaultSyntaxMap)
4240import Text.Pandoc.Extensions
4341import Text.Pandoc.Highlighting (Style, pygments)
4442import Text.DocTemplates (Template)
45−
46−#ifdef DERIVE_JSON_VIA_TH
4743import Data.Aeson.TH (deriveJSON, defaultOptions)
48−#else
49−import Data.Aeson (FromJSON (..), ToJSON (..),
50− defaultOptions, genericToEncoding)
51−#endif
5244
5345class HasSyntaxExtensions a where
5446 getExtensions :: a -> Extensions
@@ -230,7 +222,6 @@ instance HasSyntaxExtensions WriterOptions where
230222isEnabled :: HasSyntaxExtensions a => Extension -> a -> Bool
231223isEnabled ext opts = ext `extensionEnabled` getExtensions opts
232224
233−#ifdef DERIVE_JSON_VIA_TH
234225$(deriveJSON defaultOptions ''ReaderOptions)
235226$(deriveJSON defaultOptions ''HTMLMathMethod)
236227$(deriveJSON defaultOptions ''CiteMethod)
@@ -240,40 +231,3 @@ $(deriveJSON defaultOptions ''TrackChanges)
240231$(deriveJSON defaultOptions ''WrapOption)
241232$(deriveJSON defaultOptions ''TopLevelDivision)
242233$(deriveJSON defaultOptions ''ReferenceLocation)
243−#else
244−instance ToJSON CiteMethod where
245− toEncoding = genericToEncoding defaultOptions
246−instance FromJSON CiteMethod
247−
248−instance ToJSON ReaderOptions where
249− toEncoding = genericToEncoding defaultOptions
250−instance FromJSON ReaderOptions
251−
252−instance ToJSON ObfuscationMethod where
253− toEncoding = genericToEncoding defaultOptions
254−instance FromJSON ObfuscationMethod
255−
256−instance ToJSON WrapOption where
257− toEncoding = genericToEncoding defaultOptions
258−instance FromJSON WrapOption
259−
260−instance ToJSON HTMLMathMethod where
261− toEncoding = genericToEncoding defaultOptions
262−instance FromJSON HTMLMathMethod
263−
264−instance ToJSON HTMLSlideVariant where
265− toEncoding = genericToEncoding defaultOptions
266−instance FromJSON HTMLSlideVariant
267−
268−instance ToJSON TopLevelDivision where
269− toEncoding = genericToEncoding defaultOptions
270−instance FromJSON TopLevelDivision
271−
272−instance ToJSON ReferenceLocation where
273− toEncoding = genericToEncoding defaultOptions
274−instance FromJSON ReferenceLocation
275−
276−instance ToJSON TrackChanges where
277− toEncoding = genericToEncoding defaultOptions
278−instance FromJSON TrackChanges
279−#endif
stack.yaml−1
@@ -2,7 +2,6 @@ flags:
22 pandoc:
33 trypandoc: false
44 embed_data_files: true
5− derive_json_via_th: false
65 static: false
76 pandoc-citeproc:
87 bibutils: true