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:
@@ -10,7 +10,7 @@ import Model.Enum
|
||||
enumParser :: Parser EnumType
|
||||
enumParser =
|
||||
do
|
||||
eName <- enumNameParser
|
||||
eName <- try enumNameParser
|
||||
eDescription <- optional descriptionParser
|
||||
values <- some enumValueParser
|
||||
return (MakeEnum eName eDescription values)
|
||||
@@ -18,7 +18,7 @@ enumParser =
|
||||
enumValueParser :: Parser EnumValue
|
||||
enumValueParser =
|
||||
do
|
||||
vName <- nameParser
|
||||
vName <- try nameParser
|
||||
dName <- optional enumValueDisplayNameParser
|
||||
vDescription <- optional descriptionParser
|
||||
return (MakeEnumValue vName vDescription dName)
|
||||
|
||||
@@ -193,7 +193,7 @@ reverseExpression e = e
|
||||
|
||||
precedence :: String -> Int
|
||||
precedence "or" = 1
|
||||
precedence "and" = 1
|
||||
precedence "and" = 10
|
||||
precedence "+" = 2
|
||||
precedence "-" = 2
|
||||
precedence "*" = 3
|
||||
|
||||
@@ -14,22 +14,19 @@ functionParser :: Parser Function
|
||||
functionParser =
|
||||
do
|
||||
_ <- lexeme $ string "func"
|
||||
fName <- pascalNameParser
|
||||
fName <- try pascalNameParser
|
||||
_ <- lexeme $ char ':'
|
||||
fDescription <- optional descriptionParser
|
||||
fInput <- inputAttributesParser
|
||||
fOutput <- outputAttributeParser
|
||||
fAssignments <- many assignmentParser
|
||||
return (MakeFunction fName fDescription fInput fOutput fAssignments)
|
||||
MakeFunction fName fDescription fInput fOutput <$> assignmentParser
|
||||
|
||||
assignmentParser :: Parser (Expression, Expression)
|
||||
assignmentParser :: Parser Expression
|
||||
assignmentParser =
|
||||
do
|
||||
_ <- lexeme $ string "assign-output"
|
||||
name <- expressionParser
|
||||
_ <- lexeme $ char ':'
|
||||
expr <- expressionParser
|
||||
return (name, expr)
|
||||
expressionParser
|
||||
|
||||
inputAttributesParser :: Parser [TypeAttribute]
|
||||
inputAttributesParser =
|
||||
@@ -46,8 +43,8 @@ outputAttributeParser =
|
||||
attributeParser :: Parser TypeAttribute
|
||||
attributeParser =
|
||||
do
|
||||
nam <- camelNameParser
|
||||
typ <- pascalNameParser <|> camelNameParser
|
||||
nam <- try camelNameParser
|
||||
typ <- try (pascalNameParser <|> camelNameParser)
|
||||
crd <- cardinalityParser
|
||||
desc <- optional descriptionParser
|
||||
return $ MakeTypeAttribute nam (MakeType typ Nothing Nothing []) crd desc
|
||||
|
||||
@@ -27,19 +27,33 @@ pascalNameParser :: Parser String
|
||||
pascalNameParser =
|
||||
do
|
||||
first <- upperChar
|
||||
rest <- lexeme $ many (letterChar <|> digitChar <|> char '_')
|
||||
return (first : rest)
|
||||
rest <- lexeme $ many allowedChars
|
||||
if first:rest `notElem` restrictedNames then return (first:rest) else fail ((first:rest) ++ " is a restricted name")
|
||||
|
||||
camelNameParser :: Parser String
|
||||
camelNameParser =
|
||||
do
|
||||
first <- lowerChar
|
||||
rest <- lexeme $ many (letterChar <|> digitChar <|> char '_')
|
||||
return (first : rest)
|
||||
rest <- lexeme $ many allowedChars
|
||||
if first:rest `notElem` restrictedNames then return (first:rest) else fail ((first:rest) ++ " is a restricted name")
|
||||
|
||||
nameParser :: Parser String
|
||||
nameParser =
|
||||
do
|
||||
first <- letterChar <|> char '_'
|
||||
rest <- lexeme $ many (letterChar <|> digitChar <|> char '_')
|
||||
return (first:rest)
|
||||
rest <- lexeme $ many allowedChars
|
||||
if first:rest `notElem` restrictedNames then return (first:rest) else fail ((first:rest) ++ " is a restricted name")
|
||||
|
||||
allowedChars :: Parser Char
|
||||
allowedChars = letterChar <|> digitChar <|> char '_'
|
||||
|
||||
restrictedNames :: [String]
|
||||
restrictedNames = [
|
||||
"displayName",
|
||||
"enum",
|
||||
"func",
|
||||
"type",
|
||||
"extends",
|
||||
"inputs",
|
||||
"output"
|
||||
]
|
||||
@@ -10,7 +10,7 @@ import Parser.General
|
||||
typeParser :: Parser Type
|
||||
typeParser =
|
||||
do
|
||||
tName <- typeNameParser
|
||||
tName <- try typeNameParser
|
||||
tSuper <- optional superTypeParser
|
||||
_ <- lexeme $ char ':'
|
||||
tDescription <- optional descriptionParser
|
||||
@@ -27,8 +27,8 @@ superTypeParser =
|
||||
typeAttributeParser :: Parser TypeAttribute
|
||||
typeAttributeParser =
|
||||
do
|
||||
aName <- camelNameParser
|
||||
aType <- nameParser
|
||||
aName <- try camelNameParser
|
||||
aType <- try nameParser
|
||||
card <- cardinalityParser
|
||||
desc <- optional descriptionParser
|
||||
return (MakeTypeAttribute aName (MakeType aType Nothing Nothing []) card desc)
|
||||
|
||||
Reference in New Issue
Block a user