mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 21:10:07 +00:00
refactored type to add supertype
changed typechecker to have multiple errors and lower types can be used as super types
This commit is contained in:
@@ -12,18 +12,18 @@ enumParser :: Parser EnumType
|
||||
enumParser =
|
||||
do
|
||||
eName <- enumNameParser
|
||||
eDescription <- descriptionParser
|
||||
eDescription <- optional descriptionParser
|
||||
values <- many enumValueParser
|
||||
return (MakeEnum eName (Just eDescription) values)
|
||||
return (MakeEnum eName eDescription values)
|
||||
|
||||
--parseTest enumValueParser "D displayName \"day\" <\"Day\">"
|
||||
enumValueParser :: Parser EnumValue
|
||||
enumValueParser =
|
||||
do
|
||||
vName <- nameParser
|
||||
dName <- enumValueDisplayNameParser
|
||||
vDescription <- descriptionParser
|
||||
return (MakeEnumValue vName (Just vDescription) (Just dName))
|
||||
dName <- optional enumValueDisplayNameParser
|
||||
vDescription <- optional descriptionParser
|
||||
return (MakeEnumValue vName vDescription dName)
|
||||
|
||||
enumValueDisplayNameParser :: Parser String
|
||||
enumValueDisplayNameParser =
|
||||
|
||||
@@ -16,11 +16,11 @@ functionParser =
|
||||
_ <- lexeme $ string "func"
|
||||
fName <- pascalNameParser
|
||||
_ <- lexeme $ char ':'
|
||||
fDescription <- descriptionParser
|
||||
fDescription <- optional descriptionParser
|
||||
fInput <- inputAttributesParser
|
||||
fOutput <- outputAttributeParser
|
||||
fAssignments <- many assignmentParser
|
||||
return (MakeFunction fName (Just fDescription) fInput fOutput fAssignments)
|
||||
return (MakeFunction fName fDescription fInput fOutput fAssignments)
|
||||
|
||||
assignmentParser :: Parser (Expression, Expression)
|
||||
assignmentParser =
|
||||
@@ -50,5 +50,5 @@ attributeParser =
|
||||
typ <- pascalNameParser <|> camelNameParser
|
||||
crd <- cardinalityParser
|
||||
desc <- optional descriptionParser
|
||||
return $ MakeTypeAttribute nam typ crd desc
|
||||
return $ MakeTypeAttribute nam (MakeType typ Nothing Nothing []) crd desc
|
||||
|
||||
@@ -12,9 +12,18 @@ typeParser :: Parser Type
|
||||
typeParser =
|
||||
do
|
||||
tName <- typeNameParser
|
||||
tDescription <- descriptionParser
|
||||
tSuper <- optional superTypeParser
|
||||
_ <- lexeme $ char ':'
|
||||
tDescription <- optional descriptionParser
|
||||
tAttributes <- many $ try typeAttributeParser
|
||||
return (MakeType tName (Just tDescription) tAttributes)
|
||||
return (MakeType tName tSuper tDescription tAttributes)
|
||||
|
||||
superTypeParser :: Parser Type
|
||||
superTypeParser =
|
||||
do
|
||||
_ <- lexeme $ string "extending"
|
||||
name <- pascalNameParser
|
||||
return $ MakeType name Nothing Nothing []
|
||||
|
||||
typeAttributeParser :: Parser TypeAttribute
|
||||
typeAttributeParser =
|
||||
@@ -23,7 +32,7 @@ typeAttributeParser =
|
||||
aType <- nameParser
|
||||
card <- cardinalityParser
|
||||
desc <- optional descriptionParser
|
||||
return (MakeTypeAttribute aName aType card desc)
|
||||
return (MakeTypeAttribute aName (MakeType aType Nothing Nothing []) card desc)
|
||||
|
||||
cardinalityParser :: Parser Cardinality
|
||||
cardinalityParser =
|
||||
@@ -61,23 +70,22 @@ typeNameParser :: Parser String
|
||||
typeNameParser =
|
||||
do
|
||||
_ <- lexeme $ string "type"
|
||||
name <- pascalNameParser
|
||||
_ <- lexeme $ char ':'
|
||||
return name
|
||||
|
||||
pascalNameParser
|
||||
|
||||
periodType :: Type
|
||||
periodType = MakeType
|
||||
"Period"
|
||||
Nothing
|
||||
(Just "A class to define recurring periods or time offsets")
|
||||
[MakeTypeAttribute
|
||||
"periodMultiplier"
|
||||
"Integer"
|
||||
(BasicType "Integer")
|
||||
ExactlyOne
|
||||
(Just "A time period multiplier"),
|
||||
|
||||
MakeTypeAttribute
|
||||
"period"
|
||||
"periodEnum"
|
||||
(MakeType "PeriodEnum" Nothing Nothing [])
|
||||
ExactlyOne
|
||||
(Just "A time period")
|
||||
]
|
||||
Reference in New Issue
Block a user