{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-|
Module      : $header$
Copyright   : (c) Laurent P René de Cotret, 2020
License     : GNU GPL, version 2 or above
Maintainer  : laurent.decotret@outlook.com
Stability   : internal
Portability : portable

Reading configuration from file
-}

module Text.Pandoc.Filter.Plot.Configuration (
      configuration
    , configurationPathMeta
    , defaultConfiguration
) where

import           Data.Maybe             (fromMaybe)
import           Data.Text              (Text, pack, unpack)
import qualified Data.Text.IO           as TIO
import           Data.Yaml
import           Data.Yaml.Config       (ignoreEnv, loadYamlSettings)

import           System.FilePath        (normalise)

import           Text.Pandoc.Definition (Format(..), Pandoc(..), MetaValue(..), Inline(..), lookupMeta)

import Text.Pandoc.Filter.Plot.Monad   

-- | Read configuration from a YAML file. The

-- keys are exactly the same as for code blocks.

--

-- If a key is not present, its value will be set

-- to the default value. Parsing errors result in thrown exceptions.

configuration :: FilePath -> IO Configuration
configuration :: FilePath -> IO Configuration
configuration FilePath
fp = ([FilePath] -> [Value] -> EnvUsage -> IO ConfigPrecursor
forall settings.
FromJSON settings =>
[FilePath] -> [Value] -> EnvUsage -> IO settings
loadYamlSettings [FilePath -> FilePath
normalise FilePath
fp] [] EnvUsage
ignoreEnv) IO ConfigPrecursor
-> (ConfigPrecursor -> IO Configuration) -> IO Configuration
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConfigPrecursor -> IO Configuration
renderConfig


-- | Default configuration values.

--

-- @since 0.5.0.0

defaultConfiguration :: Configuration
defaultConfiguration :: Configuration
defaultConfiguration = 
    Configuration :: FilePath
-> Bool
-> Int
-> SaveFormat
-> [FilePath]
-> Format
-> Verbosity
-> LogSink
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> Bool
-> Bool
-> Configuration
Configuration
        { defaultDirectory :: FilePath
defaultDirectory    = FilePath
"plots/"
        , defaultWithSource :: Bool
defaultWithSource   = Bool
False
        , defaultDPI :: Int
defaultDPI          = Int
80
        , defaultSaveFormat :: SaveFormat
defaultSaveFormat   = SaveFormat
PNG
        , defaultDependencies :: [FilePath]
defaultDependencies = [FilePath]
forall a. Monoid a => a
mempty
        , captionFormat :: Format
captionFormat       = Script -> Format
Format Script
"markdown+tex_math_dollars"

        , logVerbosity :: Verbosity
logVerbosity        = Verbosity
Warning
        , logSink :: LogSink
logSink             = LogSink
StdErr
        
        , matplotlibPreamble :: Script
matplotlibPreamble  = Script
forall a. Monoid a => a
mempty
        , plotlyPythonPreamble :: Script
plotlyPythonPreamble= Script
forall a. Monoid a => a
mempty
        , plotlyRPreamble :: Script
plotlyRPreamble     = Script
forall a. Monoid a => a
mempty
        , matlabPreamble :: Script
matlabPreamble      = Script
forall a. Monoid a => a
mempty
        , mathematicaPreamble :: Script
mathematicaPreamble = Script
forall a. Monoid a => a
mempty
        , octavePreamble :: Script
octavePreamble      = Script
forall a. Monoid a => a
mempty
        , ggplot2Preamble :: Script
ggplot2Preamble     = Script
forall a. Monoid a => a
mempty
        , gnuplotPreamble :: Script
gnuplotPreamble     = Script
forall a. Monoid a => a
mempty
        , graphvizPreamble :: Script
graphvizPreamble    = Script
forall a. Monoid a => a
mempty
        , bokehPreamble :: Script
bokehPreamble       = Script
forall a. Monoid a => a
mempty
        , plotsjlPreamble :: Script
plotsjlPreamble     = Script
forall a. Monoid a => a
mempty

        , matplotlibExe :: FilePath
matplotlibExe       = FilePath
python
        , matlabExe :: FilePath
matlabExe           = FilePath
"matlab"
        , plotlyPythonExe :: FilePath
plotlyPythonExe     = FilePath
python
        , plotlyRExe :: FilePath
plotlyRExe          = FilePath
"Rscript"
        , mathematicaExe :: FilePath
mathematicaExe      = FilePath
"math"
        , octaveExe :: FilePath
octaveExe           = FilePath
"octave"
        , ggplot2Exe :: FilePath
ggplot2Exe          = FilePath
"Rscript"
        , gnuplotExe :: FilePath
gnuplotExe          = FilePath
"gnuplot"
        , graphvizExe :: FilePath
graphvizExe         = FilePath
"dot"
        , bokehExe :: FilePath
bokehExe            = FilePath
python
        , plotsjlExe :: FilePath
plotsjlExe          = FilePath
"julia"
        
        , matplotlibTightBBox :: Bool
matplotlibTightBBox   = Bool
False
        , matplotlibTransparent :: Bool
matplotlibTransparent = Bool
False
        }
        where
            python :: FilePath
python = if Bool
isWindows then FilePath
"python" else FilePath
"python3"

-- | Extact path to configuration from the metadata in a Pandoc document.

-- The path to the configuration file should be under the @plot-configuration@ key.

-- In case there is no such metadata, return the default configuration.

--

-- For example, at the top of a markdown file:

--

-- @

--     ---

--     title: My document

--     author: John Doe

--     plot-configuration: /path/to/file.yml

--     ---     

-- @

--

-- The same can be specified via the command line using Pandoc's @-M@ flag:

--

-- > pandoc --filter pandoc-plot -M plot-configuration="path/to/file.yml" ...

--

-- @since 0.6.0.0

configurationPathMeta :: Pandoc -> Maybe FilePath
configurationPathMeta :: Pandoc -> Maybe FilePath
configurationPathMeta (Pandoc Meta
meta [Block]
_) = 
        Script -> Meta -> Maybe MetaValue
lookupMeta Script
"plot-configuration" Meta
meta Maybe MetaValue -> (MetaValue -> Maybe FilePath) -> Maybe FilePath
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MetaValue -> Maybe FilePath
getPath
    where
        getPath :: MetaValue -> Maybe FilePath
getPath (MetaString Script
t)        = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (Script -> FilePath
unpack Script
t)
        getPath (MetaInlines [Str Script
s]) = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (Script -> FilePath
unpack Script
s)
        getPath MetaValue
_                     = Maybe FilePath
forall a. Maybe a
Nothing


-- We define a precursor type because preambles are best specified as file paths,

-- but we want to read those files before building a full

-- @Configuration@ value.

data ConfigPrecursor = ConfigPrecursor
    { ConfigPrecursor -> FilePath
_defaultDirectory    :: !FilePath    
    , ConfigPrecursor -> Bool
_defaultWithSource   :: !Bool        
    , ConfigPrecursor -> Int
_defaultDPI          :: !Int         
    , ConfigPrecursor -> SaveFormat
_defaultSaveFormat   :: !SaveFormat  
    , ConfigPrecursor -> [FilePath]
_defaultDependencies :: ![FilePath]  
    , ConfigPrecursor -> Format
_captionFormat       :: !Format
    
    , ConfigPrecursor -> LoggingPrecursor
_logPrec             :: !LoggingPrecursor

    , ConfigPrecursor -> MatplotlibPrecursor
_matplotlibPrec      :: !MatplotlibPrecursor
    , ConfigPrecursor -> MatlabPrecursor
_matlabPrec          :: !MatlabPrecursor
    , ConfigPrecursor -> PlotlyPythonPrecursor
_plotlyPythonPrec    :: !PlotlyPythonPrecursor
    , ConfigPrecursor -> PlotlyRPrecursor
_plotlyRPrec         :: !PlotlyRPrecursor
    , ConfigPrecursor -> MathematicaPrecursor
_mathematicaPrec     :: !MathematicaPrecursor
    , ConfigPrecursor -> OctavePrecursor
_octavePrec          :: !OctavePrecursor
    , ConfigPrecursor -> GGPlot2Precursor
_ggplot2Prec         :: !GGPlot2Precursor
    , ConfigPrecursor -> GNUPlotPrecursor
_gnuplotPrec         :: !GNUPlotPrecursor
    , ConfigPrecursor -> GraphvizPrecursor
_graphvizPrec        :: !GraphvizPrecursor
    , ConfigPrecursor -> BokehPrecursor
_bokehPrec           :: !BokehPrecursor
    , ConfigPrecursor -> PlotsjlPrecursor
_plotsjlPrec         :: !PlotsjlPrecursor
    }

defaultConfigPrecursor :: ConfigPrecursor
defaultConfigPrecursor :: ConfigPrecursor
defaultConfigPrecursor =  
    ConfigPrecursor :: FilePath
-> Bool
-> Int
-> SaveFormat
-> [FilePath]
-> Format
-> LoggingPrecursor
-> MatplotlibPrecursor
-> MatlabPrecursor
-> PlotlyPythonPrecursor
-> PlotlyRPrecursor
-> MathematicaPrecursor
-> OctavePrecursor
-> GGPlot2Precursor
-> GNUPlotPrecursor
-> GraphvizPrecursor
-> BokehPrecursor
-> PlotsjlPrecursor
-> ConfigPrecursor
ConfigPrecursor
        { _defaultDirectory :: FilePath
_defaultDirectory    = Configuration -> FilePath
defaultDirectory Configuration
defaultConfiguration
        , _defaultWithSource :: Bool
_defaultWithSource   = Configuration -> Bool
defaultWithSource Configuration
defaultConfiguration
        , _defaultDPI :: Int
_defaultDPI          = Configuration -> Int
defaultDPI Configuration
defaultConfiguration
        , _defaultSaveFormat :: SaveFormat
_defaultSaveFormat   = Configuration -> SaveFormat
defaultSaveFormat Configuration
defaultConfiguration
        , _defaultDependencies :: [FilePath]
_defaultDependencies = Configuration -> [FilePath]
defaultDependencies Configuration
defaultConfiguration
        , _captionFormat :: Format
_captionFormat       = Configuration -> Format
captionFormat Configuration
defaultConfiguration

        , _logPrec :: LoggingPrecursor
_logPrec             = Verbosity -> Maybe FilePath -> LoggingPrecursor
LoggingPrecursor (Configuration -> Verbosity
logVerbosity Configuration
defaultConfiguration) Maybe FilePath
forall a. Maybe a
Nothing -- _logFilePath=Nothing implies log to stderr

        
        , _matplotlibPrec :: MatplotlibPrecursor
_matplotlibPrec      = Maybe FilePath -> Bool -> Bool -> FilePath -> MatplotlibPrecursor
MatplotlibPrecursor   Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> Bool
matplotlibTightBBox Configuration
defaultConfiguration) (Configuration -> Bool
matplotlibTransparent Configuration
defaultConfiguration) (Configuration -> FilePath
matplotlibExe Configuration
defaultConfiguration)
        , _matlabPrec :: MatlabPrecursor
_matlabPrec          = Maybe FilePath -> FilePath -> MatlabPrecursor
MatlabPrecursor       Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
matlabExe Configuration
defaultConfiguration)
        , _plotlyPythonPrec :: PlotlyPythonPrecursor
_plotlyPythonPrec    = Maybe FilePath -> FilePath -> PlotlyPythonPrecursor
PlotlyPythonPrecursor Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
plotlyPythonExe Configuration
defaultConfiguration)
        , _plotlyRPrec :: PlotlyRPrecursor
_plotlyRPrec         = Maybe FilePath -> FilePath -> PlotlyRPrecursor
PlotlyRPrecursor      Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
plotlyRExe Configuration
defaultConfiguration)
        , _mathematicaPrec :: MathematicaPrecursor
_mathematicaPrec     = Maybe FilePath -> FilePath -> MathematicaPrecursor
MathematicaPrecursor  Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
mathematicaExe Configuration
defaultConfiguration)
        , _octavePrec :: OctavePrecursor
_octavePrec          = Maybe FilePath -> FilePath -> OctavePrecursor
OctavePrecursor       Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
octaveExe Configuration
defaultConfiguration)
        , _ggplot2Prec :: GGPlot2Precursor
_ggplot2Prec         = Maybe FilePath -> FilePath -> GGPlot2Precursor
GGPlot2Precursor      Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
ggplot2Exe Configuration
defaultConfiguration)
        , _gnuplotPrec :: GNUPlotPrecursor
_gnuplotPrec         = Maybe FilePath -> FilePath -> GNUPlotPrecursor
GNUPlotPrecursor      Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
gnuplotExe Configuration
defaultConfiguration)
        , _graphvizPrec :: GraphvizPrecursor
_graphvizPrec        = Maybe FilePath -> FilePath -> GraphvizPrecursor
GraphvizPrecursor     Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
graphvizExe Configuration
defaultConfiguration)
        , _bokehPrec :: BokehPrecursor
_bokehPrec           = Maybe FilePath -> FilePath -> BokehPrecursor
BokehPrecursor        Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
bokehExe Configuration
defaultConfiguration)
        , _plotsjlPrec :: PlotsjlPrecursor
_plotsjlPrec         = Maybe FilePath -> FilePath -> PlotsjlPrecursor
PlotsjlPrecursor      Maybe FilePath
forall a. Maybe a
Nothing (Configuration -> FilePath
plotsjlExe Configuration
defaultConfiguration)
        }


data LoggingPrecursor = LoggingPrecursor { LoggingPrecursor -> Verbosity
_logVerbosity :: !Verbosity
                                         , LoggingPrecursor -> Maybe FilePath
_logFilePath  :: !(Maybe FilePath)
                                         }

-- Separate YAML clauses have their own types.

data MatplotlibPrecursor = MatplotlibPrecursor
        { MatplotlibPrecursor -> Maybe FilePath
_matplotlibPreamble    :: !(Maybe FilePath)
        , MatplotlibPrecursor -> Bool
_matplotlibTightBBox   :: !Bool
        , MatplotlibPrecursor -> Bool
_matplotlibTransparent :: !Bool
        , MatplotlibPrecursor -> FilePath
_matplotlibExe         :: !FilePath
        }
data MatlabPrecursor        = MatlabPrecursor       {MatlabPrecursor -> Maybe FilePath
_matlabPreamble       :: !(Maybe FilePath), MatlabPrecursor -> FilePath
_matlabExe       :: !FilePath}
data PlotlyPythonPrecursor  = PlotlyPythonPrecursor {PlotlyPythonPrecursor -> Maybe FilePath
_plotlyPythonPreamble :: !(Maybe FilePath), PlotlyPythonPrecursor -> FilePath
_plotlyPythonExe :: !FilePath}
data PlotlyRPrecursor       = PlotlyRPrecursor      {PlotlyRPrecursor -> Maybe FilePath
_plotlyRPreamble      :: !(Maybe FilePath), PlotlyRPrecursor -> FilePath
_plotlyRExe      :: !FilePath}
data MathematicaPrecursor   = MathematicaPrecursor  {MathematicaPrecursor -> Maybe FilePath
_mathematicaPreamble  :: !(Maybe FilePath), MathematicaPrecursor -> FilePath
_mathematicaExe  :: !FilePath}
data OctavePrecursor        = OctavePrecursor       {OctavePrecursor -> Maybe FilePath
_octavePreamble       :: !(Maybe FilePath), OctavePrecursor -> FilePath
_octaveExe       :: !FilePath}
data GGPlot2Precursor       = GGPlot2Precursor      {GGPlot2Precursor -> Maybe FilePath
_ggplot2Preamble      :: !(Maybe FilePath), GGPlot2Precursor -> FilePath
_ggplot2Exe      :: !FilePath}
data GNUPlotPrecursor       = GNUPlotPrecursor      {GNUPlotPrecursor -> Maybe FilePath
_gnuplotPreamble      :: !(Maybe FilePath), GNUPlotPrecursor -> FilePath
_gnuplotExe      :: !FilePath}
data GraphvizPrecursor      = GraphvizPrecursor     {GraphvizPrecursor -> Maybe FilePath
_graphvizPreamble     :: !(Maybe FilePath), GraphvizPrecursor -> FilePath
_graphvizExe     :: !FilePath}
data BokehPrecursor         = BokehPrecursor        {BokehPrecursor -> Maybe FilePath
_bokehPreamble        :: !(Maybe FilePath), BokehPrecursor -> FilePath
_bokehExe        :: !FilePath}
data PlotsjlPrecursor       = PlotsjlPrecursor      {PlotsjlPrecursor -> Maybe FilePath
_plotsjlPreamble      :: !(Maybe FilePath), PlotsjlPrecursor -> FilePath
_plotsjlExe      :: !FilePath}

instance FromJSON LoggingPrecursor where
    parseJSON :: Value -> Parser LoggingPrecursor
parseJSON (Object Object
v) = 
        Verbosity -> Maybe FilePath -> LoggingPrecursor
LoggingPrecursor (Verbosity -> Maybe FilePath -> LoggingPrecursor)
-> Parser Verbosity -> Parser (Maybe FilePath -> LoggingPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe Verbosity)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? Script
"verbosity" Parser (Maybe Verbosity) -> Verbosity -> Parser Verbosity
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> Verbosity
logVerbosity Configuration
defaultConfiguration)
                         Parser (Maybe FilePath -> LoggingPrecursor)
-> Parser (Maybe FilePath) -> Parser LoggingPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? Script
"filepath"
    parseJSON Value
_ = FilePath -> Parser LoggingPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser LoggingPrecursor)
-> FilePath -> Parser LoggingPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse logging configuration. "]

instance FromJSON MatplotlibPrecursor where
    parseJSON :: Value -> Parser MatplotlibPrecursor
parseJSON (Object Object
v) = 
        Maybe FilePath -> Bool -> Bool -> FilePath -> MatplotlibPrecursor
MatplotlibPrecursor
            (Maybe FilePath -> Bool -> Bool -> FilePath -> MatplotlibPrecursor)
-> Parser (Maybe FilePath)
-> Parser (Bool -> Bool -> FilePath -> MatplotlibPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK)
            Parser (Bool -> Bool -> FilePath -> MatplotlibPrecursor)
-> Parser Bool -> Parser (Bool -> FilePath -> MatplotlibPrecursor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
MatplotlibTightBBoxK)   Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> Bool
matplotlibTightBBox Configuration
defaultConfiguration) 
            Parser (Bool -> FilePath -> MatplotlibPrecursor)
-> Parser Bool -> Parser (FilePath -> MatplotlibPrecursor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
MatplotlibTransparentK) Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> Bool
matplotlibTransparent Configuration
defaultConfiguration)
            Parser (FilePath -> MatplotlibPrecursor)
-> Parser FilePath -> Parser MatplotlibPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK)  Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
matplotlibExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser MatplotlibPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser MatplotlibPrecursor)
-> FilePath -> Parser MatplotlibPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Matplotlib, FilePath
" configuration."]

instance FromJSON MatlabPrecursor where
    parseJSON :: Value -> Parser MatlabPrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> MatlabPrecursor
MatlabPrecursor (Maybe FilePath -> FilePath -> MatlabPrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> MatlabPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> MatlabPrecursor)
-> Parser FilePath -> Parser MatlabPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
matlabExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser MatlabPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser MatlabPrecursor)
-> FilePath -> Parser MatlabPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Matlab, FilePath
" configuration."]

instance FromJSON PlotlyPythonPrecursor where
    parseJSON :: Value -> Parser PlotlyPythonPrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> PlotlyPythonPrecursor
PlotlyPythonPrecursor (Maybe FilePath -> FilePath -> PlotlyPythonPrecursor)
-> Parser (Maybe FilePath)
-> Parser (FilePath -> PlotlyPythonPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> PlotlyPythonPrecursor)
-> Parser FilePath -> Parser PlotlyPythonPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
plotlyPythonExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser PlotlyPythonPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser PlotlyPythonPrecursor)
-> FilePath -> Parser PlotlyPythonPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
PlotlyPython, FilePath
" configuration."]

instance FromJSON PlotlyRPrecursor where
    parseJSON :: Value -> Parser PlotlyRPrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> PlotlyRPrecursor
PlotlyRPrecursor (Maybe FilePath -> FilePath -> PlotlyRPrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> PlotlyRPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> PlotlyRPrecursor)
-> Parser FilePath -> Parser PlotlyRPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
plotlyRExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser PlotlyRPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser PlotlyRPrecursor)
-> FilePath -> Parser PlotlyRPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
PlotlyR, FilePath
" configuration."]

instance FromJSON MathematicaPrecursor where
    parseJSON :: Value -> Parser MathematicaPrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> MathematicaPrecursor
MathematicaPrecursor (Maybe FilePath -> FilePath -> MathematicaPrecursor)
-> Parser (Maybe FilePath)
-> Parser (FilePath -> MathematicaPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> MathematicaPrecursor)
-> Parser FilePath -> Parser MathematicaPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
mathematicaExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser MathematicaPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser MathematicaPrecursor)
-> FilePath -> Parser MathematicaPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Mathematica, FilePath
" configuration."]

instance FromJSON OctavePrecursor where
    parseJSON :: Value -> Parser OctavePrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> OctavePrecursor
OctavePrecursor (Maybe FilePath -> FilePath -> OctavePrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> OctavePrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> OctavePrecursor)
-> Parser FilePath -> Parser OctavePrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
octaveExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser OctavePrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser OctavePrecursor)
-> FilePath -> Parser OctavePrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Octave, FilePath
" configuration."]

instance FromJSON GGPlot2Precursor where
    parseJSON :: Value -> Parser GGPlot2Precursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> GGPlot2Precursor
GGPlot2Precursor (Maybe FilePath -> FilePath -> GGPlot2Precursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> GGPlot2Precursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> GGPlot2Precursor)
-> Parser FilePath -> Parser GGPlot2Precursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
ggplot2Exe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser GGPlot2Precursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser GGPlot2Precursor)
-> FilePath -> Parser GGPlot2Precursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
GGPlot2, FilePath
" configuration."]

instance FromJSON GNUPlotPrecursor where
    parseJSON :: Value -> Parser GNUPlotPrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> GNUPlotPrecursor
GNUPlotPrecursor (Maybe FilePath -> FilePath -> GNUPlotPrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> GNUPlotPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> GNUPlotPrecursor)
-> Parser FilePath -> Parser GNUPlotPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
gnuplotExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser GNUPlotPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser GNUPlotPrecursor)
-> FilePath -> Parser GNUPlotPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
GNUPlot, FilePath
" configuration."]

instance FromJSON GraphvizPrecursor where
    parseJSON :: Value -> Parser GraphvizPrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> GraphvizPrecursor
GraphvizPrecursor (Maybe FilePath -> FilePath -> GraphvizPrecursor)
-> Parser (Maybe FilePath)
-> Parser (FilePath -> GraphvizPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> GraphvizPrecursor)
-> Parser FilePath -> Parser GraphvizPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
graphvizExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser GraphvizPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser GraphvizPrecursor)
-> FilePath -> Parser GraphvizPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Graphviz, FilePath
" configuration."]

instance FromJSON BokehPrecursor where
    parseJSON :: Value -> Parser BokehPrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> BokehPrecursor
BokehPrecursor (Maybe FilePath -> FilePath -> BokehPrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> BokehPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> BokehPrecursor)
-> Parser FilePath -> Parser BokehPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
bokehExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser BokehPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser BokehPrecursor)
-> FilePath -> Parser BokehPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Bokeh, FilePath
" configuration."]

instance FromJSON PlotsjlPrecursor where
    parseJSON :: Value -> Parser PlotsjlPrecursor
parseJSON (Object Object
v) = Maybe FilePath -> FilePath -> PlotsjlPrecursor
PlotsjlPrecursor (Maybe FilePath -> FilePath -> PlotsjlPrecursor)
-> Parser (Maybe FilePath) -> Parser (FilePath -> PlotsjlPrecursor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
PreambleK) Parser (FilePath -> PlotsjlPrecursor)
-> Parser FilePath -> Parser PlotsjlPrecursor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
ExecutableK) Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (Configuration -> FilePath
plotsjlExe Configuration
defaultConfiguration)
    parseJSON Value
_ = FilePath -> Parser PlotsjlPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> Parser PlotsjlPrecursor)
-> FilePath -> Parser PlotsjlPrecursor
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
forall a. Monoid a => [a] -> a
mconcat [FilePath
"Could not parse ", Toolkit -> FilePath
forall a. Show a => a -> FilePath
show Toolkit
Plotsjl, FilePath
" configuration."]


instance FromJSON ConfigPrecursor where
    parseJSON :: Value -> Parser ConfigPrecursor
parseJSON (Value
Null) = ConfigPrecursor -> Parser ConfigPrecursor
forall (m :: * -> *) a. Monad m => a -> m a
return ConfigPrecursor
defaultConfigPrecursor -- In case of empty file

    parseJSON (Object Object
v) = do
        
        FilePath
_defaultDirectory    <- Object
v Object -> Script -> Parser (Maybe FilePath)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
DirectoryK)     Parser (Maybe FilePath) -> FilePath -> Parser FilePath
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> FilePath
_defaultDirectory ConfigPrecursor
defaultConfigPrecursor)
        Bool
_defaultWithSource   <- Object
v Object -> Script -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
WithSourceK)    Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> Bool
_defaultWithSource ConfigPrecursor
defaultConfigPrecursor)
        Int
_defaultDPI          <- Object
v Object -> Script -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
DpiK)           Parser (Maybe Int) -> Int -> Parser Int
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> Int
_defaultDPI ConfigPrecursor
defaultConfigPrecursor)
        SaveFormat
_defaultSaveFormat   <- Object
v Object -> Script -> Parser (Maybe SaveFormat)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
SaveFormatK)    Parser (Maybe SaveFormat) -> SaveFormat -> Parser SaveFormat
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> SaveFormat
_defaultSaveFormat ConfigPrecursor
defaultConfigPrecursor)
        [FilePath]
_defaultDependencies <- Object
v Object -> Script -> Parser (Maybe [FilePath])
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
DependenciesK)  Parser (Maybe [FilePath]) -> [FilePath] -> Parser [FilePath]
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> [FilePath]
_defaultDependencies ConfigPrecursor
defaultConfigPrecursor)
        Format
_captionFormat       <- Object
v Object -> Script -> Parser (Maybe Format)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (InclusionKey -> Script
forall a. Show a => a -> Script
tshow InclusionKey
CaptionFormatK) Parser (Maybe Format) -> Format -> Parser Format
forall a. Parser (Maybe a) -> a -> Parser a
.!= (ConfigPrecursor -> Format
_captionFormat ConfigPrecursor
defaultConfigPrecursor)

        LoggingPrecursor
_logPrec             <- Object
v Object -> Script -> Parser (Maybe LoggingPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? Script
"logging"              Parser (Maybe LoggingPrecursor)
-> LoggingPrecursor -> Parser LoggingPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> LoggingPrecursor
_logPrec ConfigPrecursor
defaultConfigPrecursor

        MatplotlibPrecursor
_matplotlibPrec      <- Object
v Object -> Script -> Parser (Maybe MatplotlibPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Matplotlib)       Parser (Maybe MatplotlibPrecursor)
-> MatplotlibPrecursor -> Parser MatplotlibPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> MatplotlibPrecursor
_matplotlibPrec ConfigPrecursor
defaultConfigPrecursor
        MatlabPrecursor
_matlabPrec          <- Object
v Object -> Script -> Parser (Maybe MatlabPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Matlab)           Parser (Maybe MatlabPrecursor)
-> MatlabPrecursor -> Parser MatlabPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> MatlabPrecursor
_matlabPrec ConfigPrecursor
defaultConfigPrecursor
        PlotlyPythonPrecursor
_plotlyPythonPrec    <- Object
v Object -> Script -> Parser (Maybe PlotlyPythonPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
PlotlyPython)     Parser (Maybe PlotlyPythonPrecursor)
-> PlotlyPythonPrecursor -> Parser PlotlyPythonPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> PlotlyPythonPrecursor
_plotlyPythonPrec ConfigPrecursor
defaultConfigPrecursor
        PlotlyRPrecursor
_plotlyRPrec         <- Object
v Object -> Script -> Parser (Maybe PlotlyRPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
PlotlyR)          Parser (Maybe PlotlyRPrecursor)
-> PlotlyRPrecursor -> Parser PlotlyRPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> PlotlyRPrecursor
_plotlyRPrec ConfigPrecursor
defaultConfigPrecursor
        MathematicaPrecursor
_mathematicaPrec     <- Object
v Object -> Script -> Parser (Maybe MathematicaPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Mathematica)      Parser (Maybe MathematicaPrecursor)
-> MathematicaPrecursor -> Parser MathematicaPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> MathematicaPrecursor
_mathematicaPrec ConfigPrecursor
defaultConfigPrecursor
        OctavePrecursor
_octavePrec          <- Object
v Object -> Script -> Parser (Maybe OctavePrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Octave)           Parser (Maybe OctavePrecursor)
-> OctavePrecursor -> Parser OctavePrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> OctavePrecursor
_octavePrec ConfigPrecursor
defaultConfigPrecursor
        GGPlot2Precursor
_ggplot2Prec         <- Object
v Object -> Script -> Parser (Maybe GGPlot2Precursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
GGPlot2)          Parser (Maybe GGPlot2Precursor)
-> GGPlot2Precursor -> Parser GGPlot2Precursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> GGPlot2Precursor
_ggplot2Prec ConfigPrecursor
defaultConfigPrecursor
        GNUPlotPrecursor
_gnuplotPrec         <- Object
v Object -> Script -> Parser (Maybe GNUPlotPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
GNUPlot)          Parser (Maybe GNUPlotPrecursor)
-> GNUPlotPrecursor -> Parser GNUPlotPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> GNUPlotPrecursor
_gnuplotPrec ConfigPrecursor
defaultConfigPrecursor
        GraphvizPrecursor
_graphvizPrec        <- Object
v Object -> Script -> Parser (Maybe GraphvizPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Graphviz)         Parser (Maybe GraphvizPrecursor)
-> GraphvizPrecursor -> Parser GraphvizPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> GraphvizPrecursor
_graphvizPrec ConfigPrecursor
defaultConfigPrecursor
        BokehPrecursor
_bokehPrec           <- Object
v Object -> Script -> Parser (Maybe BokehPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Bokeh)            Parser (Maybe BokehPrecursor)
-> BokehPrecursor -> Parser BokehPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> BokehPrecursor
_bokehPrec ConfigPrecursor
defaultConfigPrecursor 
        PlotsjlPrecursor
_plotsjlPrec         <- Object
v Object -> Script -> Parser (Maybe PlotsjlPrecursor)
forall a. FromJSON a => Object -> Script -> Parser (Maybe a)
.:? (Toolkit -> Script
cls Toolkit
Plotsjl)          Parser (Maybe PlotsjlPrecursor)
-> PlotsjlPrecursor -> Parser PlotsjlPrecursor
forall a. Parser (Maybe a) -> a -> Parser a
.!= ConfigPrecursor -> PlotsjlPrecursor
_plotsjlPrec ConfigPrecursor
defaultConfigPrecursor

        ConfigPrecursor -> Parser ConfigPrecursor
forall (m :: * -> *) a. Monad m => a -> m a
return (ConfigPrecursor -> Parser ConfigPrecursor)
-> ConfigPrecursor -> Parser ConfigPrecursor
forall a b. (a -> b) -> a -> b
$ ConfigPrecursor :: FilePath
-> Bool
-> Int
-> SaveFormat
-> [FilePath]
-> Format
-> LoggingPrecursor
-> MatplotlibPrecursor
-> MatlabPrecursor
-> PlotlyPythonPrecursor
-> PlotlyRPrecursor
-> MathematicaPrecursor
-> OctavePrecursor
-> GGPlot2Precursor
-> GNUPlotPrecursor
-> GraphvizPrecursor
-> BokehPrecursor
-> PlotsjlPrecursor
-> ConfigPrecursor
ConfigPrecursor{Bool
Int
FilePath
[FilePath]
Format
SaveFormat
PlotsjlPrecursor
BokehPrecursor
GraphvizPrecursor
GNUPlotPrecursor
GGPlot2Precursor
OctavePrecursor
MathematicaPrecursor
PlotlyRPrecursor
PlotlyPythonPrecursor
MatlabPrecursor
MatplotlibPrecursor
LoggingPrecursor
_plotsjlPrec :: PlotsjlPrecursor
_bokehPrec :: BokehPrecursor
_graphvizPrec :: GraphvizPrecursor
_gnuplotPrec :: GNUPlotPrecursor
_ggplot2Prec :: GGPlot2Precursor
_octavePrec :: OctavePrecursor
_mathematicaPrec :: MathematicaPrecursor
_plotlyRPrec :: PlotlyRPrecursor
_plotlyPythonPrec :: PlotlyPythonPrecursor
_matlabPrec :: MatlabPrecursor
_matplotlibPrec :: MatplotlibPrecursor
_logPrec :: LoggingPrecursor
_captionFormat :: Format
_defaultDependencies :: [FilePath]
_defaultSaveFormat :: SaveFormat
_defaultDPI :: Int
_defaultWithSource :: Bool
_defaultDirectory :: FilePath
_plotsjlPrec :: PlotsjlPrecursor
_bokehPrec :: BokehPrecursor
_graphvizPrec :: GraphvizPrecursor
_gnuplotPrec :: GNUPlotPrecursor
_ggplot2Prec :: GGPlot2Precursor
_octavePrec :: OctavePrecursor
_mathematicaPrec :: MathematicaPrecursor
_plotlyRPrec :: PlotlyRPrecursor
_plotlyPythonPrec :: PlotlyPythonPrecursor
_matlabPrec :: MatlabPrecursor
_matplotlibPrec :: MatplotlibPrecursor
_logPrec :: LoggingPrecursor
_captionFormat :: Format
_defaultDependencies :: [FilePath]
_defaultSaveFormat :: SaveFormat
_defaultDPI :: Int
_defaultWithSource :: Bool
_defaultDirectory :: FilePath
..}
    parseJSON Value
_          = FilePath -> Parser ConfigPrecursor
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
"Could not parse configuration."


renderConfig :: ConfigPrecursor -> IO Configuration
renderConfig :: ConfigPrecursor -> IO Configuration
renderConfig ConfigPrecursor{Bool
Int
FilePath
[FilePath]
Format
SaveFormat
PlotsjlPrecursor
BokehPrecursor
GraphvizPrecursor
GNUPlotPrecursor
GGPlot2Precursor
OctavePrecursor
MathematicaPrecursor
PlotlyRPrecursor
PlotlyPythonPrecursor
MatlabPrecursor
MatplotlibPrecursor
LoggingPrecursor
_plotsjlPrec :: PlotsjlPrecursor
_bokehPrec :: BokehPrecursor
_graphvizPrec :: GraphvizPrecursor
_gnuplotPrec :: GNUPlotPrecursor
_ggplot2Prec :: GGPlot2Precursor
_octavePrec :: OctavePrecursor
_mathematicaPrec :: MathematicaPrecursor
_plotlyRPrec :: PlotlyRPrecursor
_plotlyPythonPrec :: PlotlyPythonPrecursor
_matlabPrec :: MatlabPrecursor
_matplotlibPrec :: MatplotlibPrecursor
_logPrec :: LoggingPrecursor
_captionFormat :: Format
_defaultDependencies :: [FilePath]
_defaultSaveFormat :: SaveFormat
_defaultDPI :: Int
_defaultWithSource :: Bool
_defaultDirectory :: FilePath
_plotsjlPrec :: ConfigPrecursor -> PlotsjlPrecursor
_bokehPrec :: ConfigPrecursor -> BokehPrecursor
_graphvizPrec :: ConfigPrecursor -> GraphvizPrecursor
_gnuplotPrec :: ConfigPrecursor -> GNUPlotPrecursor
_ggplot2Prec :: ConfigPrecursor -> GGPlot2Precursor
_octavePrec :: ConfigPrecursor -> OctavePrecursor
_mathematicaPrec :: ConfigPrecursor -> MathematicaPrecursor
_plotlyRPrec :: ConfigPrecursor -> PlotlyRPrecursor
_plotlyPythonPrec :: ConfigPrecursor -> PlotlyPythonPrecursor
_matlabPrec :: ConfigPrecursor -> MatlabPrecursor
_matplotlibPrec :: ConfigPrecursor -> MatplotlibPrecursor
_logPrec :: ConfigPrecursor -> LoggingPrecursor
_captionFormat :: ConfigPrecursor -> Format
_defaultDependencies :: ConfigPrecursor -> [FilePath]
_defaultSaveFormat :: ConfigPrecursor -> SaveFormat
_defaultDPI :: ConfigPrecursor -> Int
_defaultWithSource :: ConfigPrecursor -> Bool
_defaultDirectory :: ConfigPrecursor -> FilePath
..} = do
    let defaultDirectory :: FilePath
defaultDirectory    = FilePath
_defaultDirectory
        defaultWithSource :: Bool
defaultWithSource   = Bool
_defaultWithSource
        defaultDPI :: Int
defaultDPI          = Int
_defaultDPI
        defaultSaveFormat :: SaveFormat
defaultSaveFormat   = SaveFormat
_defaultSaveFormat
        defaultDependencies :: [FilePath]
defaultDependencies = [FilePath]
_defaultDependencies
        captionFormat :: Format
captionFormat       = Format
_captionFormat

        logVerbosity :: Verbosity
logVerbosity        = LoggingPrecursor -> Verbosity
_logVerbosity LoggingPrecursor
_logPrec
        logSink :: LogSink
logSink             = LogSink -> (FilePath -> LogSink) -> Maybe FilePath -> LogSink
forall b a. b -> (a -> b) -> Maybe a -> b
maybe LogSink
StdErr FilePath -> LogSink
LogFile (LoggingPrecursor -> Maybe FilePath
_logFilePath LoggingPrecursor
_logPrec)

        matplotlibTightBBox :: Bool
matplotlibTightBBox   = MatplotlibPrecursor -> Bool
_matplotlibTightBBox MatplotlibPrecursor
_matplotlibPrec
        matplotlibTransparent :: Bool
matplotlibTransparent = MatplotlibPrecursor -> Bool
_matplotlibTransparent MatplotlibPrecursor
_matplotlibPrec

        matplotlibExe :: FilePath
matplotlibExe   = MatplotlibPrecursor -> FilePath
_matplotlibExe MatplotlibPrecursor
_matplotlibPrec
        matlabExe :: FilePath
matlabExe       = MatlabPrecursor -> FilePath
_matlabExe MatlabPrecursor
_matlabPrec
        plotlyPythonExe :: FilePath
plotlyPythonExe = PlotlyPythonPrecursor -> FilePath
_plotlyPythonExe PlotlyPythonPrecursor
_plotlyPythonPrec
        plotlyRExe :: FilePath
plotlyRExe      = PlotlyRPrecursor -> FilePath
_plotlyRExe PlotlyRPrecursor
_plotlyRPrec
        mathematicaExe :: FilePath
mathematicaExe  = MathematicaPrecursor -> FilePath
_mathematicaExe MathematicaPrecursor
_mathematicaPrec
        octaveExe :: FilePath
octaveExe       = OctavePrecursor -> FilePath
_octaveExe OctavePrecursor
_octavePrec
        ggplot2Exe :: FilePath
ggplot2Exe      = GGPlot2Precursor -> FilePath
_ggplot2Exe GGPlot2Precursor
_ggplot2Prec
        gnuplotExe :: FilePath
gnuplotExe      = GNUPlotPrecursor -> FilePath
_gnuplotExe GNUPlotPrecursor
_gnuplotPrec
        graphvizExe :: FilePath
graphvizExe     = GraphvizPrecursor -> FilePath
_graphvizExe GraphvizPrecursor
_graphvizPrec
        bokehExe :: FilePath
bokehExe        = BokehPrecursor -> FilePath
_bokehExe BokehPrecursor
_bokehPrec
        plotsjlExe :: FilePath
plotsjlExe      = PlotsjlPrecursor -> FilePath
_plotsjlExe PlotsjlPrecursor
_plotsjlPrec
    
    Script
matplotlibPreamble   <- Maybe FilePath -> IO Script
readPreamble (MatplotlibPrecursor -> Maybe FilePath
_matplotlibPreamble MatplotlibPrecursor
_matplotlibPrec)
    Script
matlabPreamble       <- Maybe FilePath -> IO Script
readPreamble (MatlabPrecursor -> Maybe FilePath
_matlabPreamble MatlabPrecursor
_matlabPrec)
    Script
plotlyPythonPreamble <- Maybe FilePath -> IO Script
readPreamble (PlotlyPythonPrecursor -> Maybe FilePath
_plotlyPythonPreamble PlotlyPythonPrecursor
_plotlyPythonPrec)
    Script
plotlyRPreamble      <- Maybe FilePath -> IO Script
readPreamble (PlotlyRPrecursor -> Maybe FilePath
_plotlyRPreamble PlotlyRPrecursor
_plotlyRPrec)
    Script
mathematicaPreamble  <- Maybe FilePath -> IO Script
readPreamble (MathematicaPrecursor -> Maybe FilePath
_mathematicaPreamble MathematicaPrecursor
_mathematicaPrec)
    Script
octavePreamble       <- Maybe FilePath -> IO Script
readPreamble (OctavePrecursor -> Maybe FilePath
_octavePreamble OctavePrecursor
_octavePrec)
    Script
ggplot2Preamble      <- Maybe FilePath -> IO Script
readPreamble (GGPlot2Precursor -> Maybe FilePath
_ggplot2Preamble GGPlot2Precursor
_ggplot2Prec)
    Script
gnuplotPreamble      <- Maybe FilePath -> IO Script
readPreamble (GNUPlotPrecursor -> Maybe FilePath
_gnuplotPreamble GNUPlotPrecursor
_gnuplotPrec)
    Script
graphvizPreamble     <- Maybe FilePath -> IO Script
readPreamble (GraphvizPrecursor -> Maybe FilePath
_graphvizPreamble GraphvizPrecursor
_graphvizPrec)
    Script
bokehPreamble        <- Maybe FilePath -> IO Script
readPreamble (BokehPrecursor -> Maybe FilePath
_bokehPreamble BokehPrecursor
_bokehPrec)
    Script
plotsjlPreamble      <- Maybe FilePath -> IO Script
readPreamble (PlotsjlPrecursor -> Maybe FilePath
_plotsjlPreamble PlotsjlPrecursor
_plotsjlPrec)

    Configuration -> IO Configuration
forall (m :: * -> *) a. Monad m => a -> m a
return Configuration :: FilePath
-> Bool
-> Int
-> SaveFormat
-> [FilePath]
-> Format
-> Verbosity
-> LogSink
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> Script
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> Bool
-> Bool
-> Configuration
Configuration{Bool
Int
FilePath
[FilePath]
Script
Format
LogSink
Verbosity
SaveFormat
plotsjlPreamble :: Script
bokehPreamble :: Script
graphvizPreamble :: Script
gnuplotPreamble :: Script
ggplot2Preamble :: Script
octavePreamble :: Script
mathematicaPreamble :: Script
plotlyRPreamble :: Script
plotlyPythonPreamble :: Script
matlabPreamble :: Script
matplotlibPreamble :: Script
plotsjlExe :: FilePath
bokehExe :: FilePath
graphvizExe :: FilePath
gnuplotExe :: FilePath
ggplot2Exe :: FilePath
octaveExe :: FilePath
mathematicaExe :: FilePath
plotlyRExe :: FilePath
plotlyPythonExe :: FilePath
matlabExe :: FilePath
matplotlibExe :: FilePath
matplotlibTransparent :: Bool
matplotlibTightBBox :: Bool
logSink :: LogSink
logVerbosity :: Verbosity
captionFormat :: Format
defaultDependencies :: [FilePath]
defaultSaveFormat :: SaveFormat
defaultDPI :: Int
defaultWithSource :: Bool
defaultDirectory :: FilePath
matplotlibTransparent :: Bool
matplotlibTightBBox :: Bool
plotsjlExe :: FilePath
bokehExe :: FilePath
graphvizExe :: FilePath
gnuplotExe :: FilePath
ggplot2Exe :: FilePath
octaveExe :: FilePath
mathematicaExe :: FilePath
plotlyRExe :: FilePath
plotlyPythonExe :: FilePath
matlabExe :: FilePath
matplotlibExe :: FilePath
plotsjlPreamble :: Script
bokehPreamble :: Script
graphvizPreamble :: Script
gnuplotPreamble :: Script
ggplot2Preamble :: Script
octavePreamble :: Script
mathematicaPreamble :: Script
matlabPreamble :: Script
plotlyRPreamble :: Script
plotlyPythonPreamble :: Script
matplotlibPreamble :: Script
logSink :: LogSink
logVerbosity :: Verbosity
captionFormat :: Format
defaultDependencies :: [FilePath]
defaultSaveFormat :: SaveFormat
defaultDPI :: Int
defaultWithSource :: Bool
defaultDirectory :: FilePath
..}
    where
        readPreamble :: Maybe FilePath -> IO Script
readPreamble Maybe FilePath
fp = IO Script -> Maybe (IO Script) -> IO Script
forall a. a -> Maybe a -> a
fromMaybe IO Script
forall a. Monoid a => a
mempty (Maybe (IO Script) -> IO Script) -> Maybe (IO Script) -> IO Script
forall a b. (a -> b) -> a -> b
$ FilePath -> IO Script
TIO.readFile (FilePath -> IO Script) -> Maybe FilePath -> Maybe (IO Script)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe FilePath
fp


tshow :: Show a => a -> Text
tshow :: a -> Script
tshow = FilePath -> Script
pack (FilePath -> Script) -> (a -> FilePath) -> a -> Script
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> FilePath
forall a. Show a => a -> FilePath
show