finished generator for basic types, enums and functions.

Functions still need to print a body
This commit is contained in:
macocianradu
2021-11-12 03:05:34 +01:00
parent 045ae7049e
commit 40f6fb24b7
20 changed files with 224 additions and 63 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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"
]

View File

@@ -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)