{-# LANGUAGE TypeFamilies #-}
module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.PythonRenderer (
PythonProject(..)
) where
import Language.Drasil.Code.Imperative.GOOL.ClassInterface (PackageSym(..), AuxiliarySym(..))
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))
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 Drasil.GOOL (onCodeList, pyName, pyVersion)
import Prelude hiding (break,print,sin,cos,tan,floor,(<>))
import Text.PrettyPrint.HughesPJ (Doc)
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) = b -> PythonProject b
forall a. a -> PythonProject a
PP (a -> b
f a
x)
instance Applicative PythonProject where
pure :: forall a. a -> PythonProject a
pure = a -> PythonProject a
forall a. a -> PythonProject a
PP
(PP a -> b
f) <*> :: forall a b.
PythonProject (a -> b) -> PythonProject a -> PythonProject b
<*> (PP a
x) = b -> PythonProject b
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 = ([AuxData] -> PackData)
-> [PythonProject AuxData] -> PythonProject PackData
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 = PythonProject (AuxHelper PythonProject)
-> String
-> GOOLState
-> Verbosity
-> PythonProject (Auxiliary PythonProject)
forall (r :: * -> *).
AuxiliarySym r =>
r (AuxHelper r)
-> String -> GOOLState -> Verbosity -> r (Auxiliary r)
G.doxConfig PythonProject (AuxHelper PythonProject)
forall (r :: * -> *). AuxiliarySym r => r (AuxHelper r)
optimizeDox
readMe :: ReadMeInfo -> PythonProject (Auxiliary PythonProject)
readMe ReadMeInfo
rmi =
ReadMeInfo -> PythonProject (Auxiliary PythonProject)
forall (r :: * -> *).
AuxiliarySym r =>
ReadMeInfo -> r (Auxiliary r)
G.readMe ReadMeInfo
rmi {
langName = pyName,
langVersion = pyVersion}
sampleInput :: ChunkDB
-> DataDesc -> [Expr] -> PythonProject (Auxiliary PythonProject)
sampleInput = ChunkDB
-> DataDesc -> [Expr] -> PythonProject (Auxiliary PythonProject)
forall (r :: * -> *).
AuxiliarySym r =>
ChunkDB -> DataDesc -> [Expr] -> r (Auxiliary r)
G.sampleInput
optimizeDox :: PythonProject (AuxHelper PythonProject)
optimizeDox = Doc -> PythonProject Doc
forall a. a -> PythonProject a
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 = Maybe BuildConfig
-> Maybe Runnable
-> Maybe DocConfig
-> GOOLState
-> ProgData
-> PythonProject (Auxiliary PythonProject)
forall (r :: * -> *).
AuxiliarySym r =>
Maybe BuildConfig
-> Maybe Runnable
-> Maybe DocConfig
-> GOOLState
-> ProgData
-> r (Auxiliary r)
G.makefile Maybe BuildConfig
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 = PythonProject Doc -> Doc
PythonProject (AuxHelper PythonProject) -> Doc
forall a. PythonProject a -> a
unPP
auxFromData :: String -> Doc -> PythonProject (Auxiliary PythonProject)
auxFromData String
fp Doc
d = AuxData -> PythonProject AuxData
forall a. a -> PythonProject a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AuxData -> PythonProject AuxData)
-> AuxData -> PythonProject AuxData
forall a b. (a -> b) -> a -> b
$ String -> Doc -> AuxData
ad String
fp Doc
d
pyRunnable :: Maybe Runnable
pyRunnable :: Maybe Runnable
pyRunnable = String -> Maybe Runnable
interpMM String
"python3"