mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 21:10:07 +00:00
finished generator for basic types, enums and functions.
Functions still need to print a body
This commit is contained in:
@@ -7,15 +7,24 @@ import PrettyPrinter.General
|
||||
import Model.Type
|
||||
|
||||
printType :: Type -> String
|
||||
printType (MakeType name _ description attributes) =
|
||||
show $ printDescription description (vcat [nest 4 $ vcat ("data" <+> pretty name <+> "=" <+> "Make" <> pretty name <+> "{": map printAttribute attributes), "}", ""])
|
||||
printType (MakeType name (Just (MakeType super _ _ _)) description attributes) = printType (MakeType name Nothing description (superToAttribute super:attributes))
|
||||
printType (MakeType _ (Just (BasicType _)) _ _) = error "Can't extend basic types"
|
||||
printType (MakeType name Nothing description attributes) =
|
||||
show $ printDescription description (vcat [nest 4 $ vcat ("data" <+> pretty name <+> "=" <+> "Make" <> pretty name <+> "{": printAttributes attributes), "}", ""])
|
||||
printType (BasicType name) = show $ pretty name
|
||||
|
||||
--printSuperType :: Maybe Type -> Doc a
|
||||
--printSuperType (Just (MakeType name _ _ _)) = "super" <+> "::" <+> pretty name
|
||||
--printSuperType (Just (BasicType _)) = error "Can't extend basic types"
|
||||
--printSuperType Nothing = emptyDoc
|
||||
|
||||
superToAttribute :: String -> TypeAttribute
|
||||
superToAttribute name = MakeTypeAttribute "super" (MakeType name Nothing Nothing []) (Bounds (1, 1)) (Just "Pointer to super class")
|
||||
|
||||
printAttributes :: [TypeAttribute] -> [Doc a]
|
||||
printAttributes [] = []
|
||||
printAttributes [at] = [printAttribute at]
|
||||
printAttributes (at : ats) = (printAttribute at <> ",") : printAttributes ats
|
||||
|
||||
|
||||
printAttribute :: TypeAttribute -> Doc a
|
||||
printAttribute (MakeTypeAttribute name typ crd description) =
|
||||
|
||||
Reference in New Issue
Block a user