{-# LANGUAGE TypeFamilies #-}

-- | The logic to render Python auxiliary files is contained in this module
module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.PythonRenderer (
  PythonProject(..)
) where

import Language.Drasil.Code.Imperative.GOOL.ClassInterface (ReadMeInfo(..),PackageSym(..),
  AuxiliarySym(..))
import qualified
  Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.LanguagePolymorphic as
  G (doxConfig, readMe, sampleInput, makefile, noRunIfLib, doxDocConfig,
  docIfEnabled)
import Language.Drasil.Code.Imperative.GOOL.Data (AuxData(..), ad, PackData(..),
  packD)
import Language.Drasil.Code.Imperative.Build.AST (Runnable, interpMM)
import Language.Drasil.Code.Imperative.Doxygen.Import (yes)

import GOOL.Drasil (onCodeList, pyName, pyVersion)

import Prelude hiding (break,print,sin,cos,tan,floor,(<>))
import Text.PrettyPrint.HughesPJ (Doc)

-- | Holds a Python project.
newtype PythonProject a = PP {forall a. PythonProject a -> a
unPP :: a}

instance Functor PythonProject where
  fmap :: forall a b. (a -> b) -> PythonProject a -> PythonProject b
fmap a -> b
f (PP a
x) = forall a. a -> PythonProject a
PP (a -> b
f a
x)

instance Applicative PythonProject where
  pure :: forall a. a -> PythonProject a
pure = forall a. a -> PythonProject a
PP
  (PP a -> b
f) <*> :: forall a b.
PythonProject (a -> b) -> PythonProject a -> PythonProject b
<*> (PP a
x) = forall a. a -> PythonProject a
PP (a -> b
f a
x)

instance Monad PythonProject where
  PP a
x >>= :: forall a b.
PythonProject a -> (a -> PythonProject b) -> PythonProject b
>>= a -> PythonProject b
f = a -> PythonProject b
f a
x

instance PackageSym PythonProject where
  type Package PythonProject = PackData
  package :: ProgData
-> [PythonProject (Auxiliary PythonProject)]
-> PythonProject (Package PythonProject)
package ProgData
p = forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList (ProgData -> [AuxData] -> PackData
packD ProgData
p)

instance AuxiliarySym PythonProject where
  type Auxiliary PythonProject = AuxData
  type AuxHelper PythonProject = Doc
  doxConfig :: String
-> GOOLState
-> Verbosity
-> PythonProject (Auxiliary PythonProject)
doxConfig = forall (r :: * -> *).
AuxiliarySym r =>
r (AuxHelper r)
-> String -> GOOLState -> Verbosity -> r (Auxiliary r)
G.doxConfig forall (r :: * -> *). AuxiliarySym r => r (AuxHelper r)
optimizeDox
  readMe :: ReadMeInfo -> PythonProject (Auxiliary PythonProject)
readMe ReadMeInfo
rmi =
    forall (r :: * -> *).
AuxiliarySym r =>
ReadMeInfo -> r (Auxiliary r)
G.readMe ReadMeInfo
rmi {
        langName :: String
langName = String
pyName,
        langVersion :: String
langVersion = String
pyVersion}
  sampleInput :: ChunkDB
-> DataDesc -> [Expr] -> PythonProject (Auxiliary PythonProject)
sampleInput = forall (r :: * -> *).
AuxiliarySym r =>
ChunkDB -> DataDesc -> [Expr] -> r (Auxiliary r)
G.sampleInput

  optimizeDox :: PythonProject (AuxHelper PythonProject)
optimizeDox = forall (f :: * -> *) a. Applicative f => a -> f a
pure Doc
yes

  makefile :: [String]
-> ImplementationType
-> [Comments]
-> GOOLState
-> ProgData
-> PythonProject (Auxiliary PythonProject)
makefile [String]
_ ImplementationType
it [Comments]
cms = forall (r :: * -> *).
AuxiliarySym r =>
Maybe BuildConfig
-> Maybe Runnable
-> Maybe DocConfig
-> GOOLState
-> ProgData
-> r (Auxiliary r)
G.makefile forall a. Maybe a
Nothing (ImplementationType -> Maybe Runnable -> Maybe Runnable
G.noRunIfLib ImplementationType
it Maybe Runnable
pyRunnable)
    ([Comments] -> DocConfig -> Maybe DocConfig
G.docIfEnabled [Comments]
cms DocConfig
G.doxDocConfig)

  auxHelperDoc :: PythonProject (AuxHelper PythonProject) -> Doc
auxHelperDoc = forall a. PythonProject a -> a
unPP
  auxFromData :: String -> Doc -> PythonProject (Auxiliary PythonProject)
auxFromData String
fp Doc
d = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ String -> Doc -> AuxData
ad String
fp Doc
d

-- | Default runnable information for Python files.
pyRunnable :: Maybe Runnable
pyRunnable :: Maybe Runnable
pyRunnable = String -> Maybe Runnable
interpMM String
"python3"