module Language.Drasil.Code.Code (
Code(..),
spaceToCodeType
) where
import qualified Language.Drasil as S (Space(..))
import GOOL.Drasil (CodeType(..))
import Text.PrettyPrint.HughesPJ (Doc)
import Data.List.NonEmpty (toList)
newtype Code = Code { Code -> [(FilePath, Doc)]
unCode :: [(FilePath, Doc)]}
spaceToCodeType :: S.Space -> [CodeType]
spaceToCodeType :: Space -> [CodeType]
spaceToCodeType Space
S.Integer = [CodeType
Integer]
spaceToCodeType Space
S.Natural = [CodeType
Integer]
spaceToCodeType Space
S.Real = [CodeType
Double, CodeType
Float]
spaceToCodeType Space
S.Rational = [CodeType
Double, CodeType
Float]
spaceToCodeType Space
S.Boolean = [CodeType
Boolean]
spaceToCodeType Space
S.Char = [CodeType
Char]
spaceToCodeType Space
S.String = [CodeType
String]
spaceToCodeType (S.Vect Space
s) = forall a b. (a -> b) -> [a] -> [b]
map CodeType -> CodeType
List (Space -> [CodeType]
spaceToCodeType Space
s)
spaceToCodeType (S.Matrix Int
_ Int
_ Space
s) = forall a b. (a -> b) -> [a] -> [b]
map (CodeType -> CodeType
List forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeType -> CodeType
List) (Space -> [CodeType]
spaceToCodeType Space
s)
spaceToCodeType (S.Array Space
s) = forall a b. (a -> b) -> [a] -> [b]
map CodeType -> CodeType
Array (Space -> [CodeType]
spaceToCodeType Space
s)
spaceToCodeType (S.Actor FilePath
s) = [FilePath -> CodeType
Object FilePath
s]
spaceToCodeType (S.DiscreteD [Double]
_) = forall a b. (a -> b) -> [a] -> [b]
map CodeType -> CodeType
List (Space -> [CodeType]
spaceToCodeType Space
S.Rational)
spaceToCodeType (S.DiscreteS [FilePath]
_) = forall a b. (a -> b) -> [a] -> [b]
map CodeType -> CodeType
List (Space -> [CodeType]
spaceToCodeType Space
S.String)
spaceToCodeType Space
S.Void = [CodeType
Void]
spaceToCodeType (S.Function NonEmpty Space
i Space
t) = [[CodeType] -> CodeType -> CodeType
Func [CodeType]
is CodeType
ts | [CodeType]
is <- [[CodeType]]
ins, CodeType
ts <- [CodeType]
trgs]
where trgs :: [CodeType]
trgs = Space -> [CodeType]
spaceToCodeType Space
t
ins :: [[CodeType]]
ins = forall a b. (a -> b) -> [a] -> [b]
map Space -> [CodeType]
spaceToCodeType (forall a. NonEmpty a -> [a]
toList NonEmpty Space
i)