module Language.Drasil.Code.Code (
Code(..),
spaceToCodeType
) where
import qualified Language.Drasil as S (Space(..))
import Drasil.GOOL (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) = (CodeType -> CodeType) -> [CodeType] -> [CodeType]
forall a b. (a -> b) -> [a] -> [b]
map CodeType -> CodeType
List (Space -> [CodeType]
spaceToCodeType Space
s)
spaceToCodeType (S.Matrix Int
_ Int
_ Space
s) = (CodeType -> CodeType) -> [CodeType] -> [CodeType]
forall a b. (a -> b) -> [a] -> [b]
map (CodeType -> CodeType
List (CodeType -> CodeType)
-> (CodeType -> CodeType) -> CodeType -> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeType -> CodeType
List) (Space -> [CodeType]
spaceToCodeType Space
s)
spaceToCodeType (S.Set Space
s) = (CodeType -> CodeType) -> [CodeType] -> [CodeType]
forall a b. (a -> b) -> [a] -> [b]
map CodeType -> CodeType
List (Space -> [CodeType]
spaceToCodeType Space
s)
spaceToCodeType (S.Array Space
s) = (CodeType -> CodeType) -> [CodeType] -> [CodeType]
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 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 = (Space -> [CodeType]) -> [Space] -> [[CodeType]]
forall a b. (a -> b) -> [a] -> [b]
map Space -> [CodeType]
spaceToCodeType (NonEmpty Space -> [Space]
forall a. NonEmpty a -> [a]
toList NonEmpty Space
i)