mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 21:10:07 +00:00
parsing works with path expressions
This commit is contained in:
@@ -11,16 +11,25 @@ import Utils.Utils
|
||||
-- |Checks if all the inputs and the output of a function call have valid types, and then checks that the assign-output expression is valid
|
||||
checkFunction :: ([Type], [Symbol]) -> Function -> Either [TypeCheckError] ExplicitFunction
|
||||
checkFunction (definedTypes, symbols) (MakeFunction (MakeFunctionSignature name desc inp out) ex) =
|
||||
let checkedIn = checkAttributes definedTypes inp in
|
||||
if null $ lefts checkedIn
|
||||
then
|
||||
case head $ checkAttributes definedTypes [out] of
|
||||
Left err -> Left [err]
|
||||
Right checkedOut -> case checkExpression (addVariables symbols inp) ex of
|
||||
Left err -> Left [err]
|
||||
Right checkedEx -> case returnCoercion checkedEx `coercionIncluded` createCoercion (attributeType checkedOut, Model.Type.cardinality out) of
|
||||
Left err -> Left [err]
|
||||
Right retCoercion -> Right $ MakeExplicitFunction (MakeFunctionSignature (toLower (head name) : tail name) desc (rights checkedIn) checkedOut) checkedEx
|
||||
--Right _ -> error $ show (returnCoercion checkedEx) ++ " // " ++ show (createCoercion (attributeType checkedOut, Model.Type.cardinality out))
|
||||
Right checkedOut -> case checkAssignment (addVariables symbols (checkedOut : rights checkedIn)) ex of
|
||||
Left err -> Left err
|
||||
Right checkedEx -> Right $ MakeExplicitFunction (MakeFunctionSignature (toLower (head name) : tail name) desc (rights checkedIn) checkedOut) checkedEx
|
||||
else
|
||||
Left $ lefts checkedIn
|
||||
where checkedIn = checkAttributes definedTypes inp
|
||||
|
||||
checkAssignment :: [Symbol] -> [(Expression, Expression)] -> Either [TypeCheckError] [(ExplicitExpression, ExplicitExpression)]
|
||||
checkAssignment _ [] = Right []
|
||||
checkAssignment symbs ((assign, ex): assigns) =
|
||||
case checkExpression (tail symbs) ex of
|
||||
Left err -> Left [err]
|
||||
-- Here we use only tail symbs, beacuse the head of the symbol table is the out variable, and that can't be used in the expression body
|
||||
Right checkedExp -> case checkExpression symbs assign of
|
||||
Left err -> Left [err]
|
||||
Right checkedA -> case checkAssignment symbs assigns of
|
||||
Left err -> Left err
|
||||
Right checked -> Right $ (checkedA, checkedExp) : checked
|
||||
Reference in New Issue
Block a user