@@ -9,32 +9,35 @@ import qualified Parse.Expression as Expr
99import Parse.Helpers
1010import qualified Parse.Type as Type
1111
12+
1213declaration :: IParser D.SourceDecl
1314declaration =
14− alias <|> datatype <|> infixDecl <|> port <|> definition
15+ typeDecl <|> infixDecl <|> port <|> definition
16+
1517
1618definition :: IParser D.SourceDecl
1719definition = D.Definition <$> Expr.def
1820
19−alias :: IParser D.SourceDecl
20−alias = do
21− reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
22− forcedWS
23− name <- capVar
24− args <- spacePrefix lowVar
25− padded equals
26− tipe <- Type.expr
27− return (D.TypeAlias name args tipe)
28−
29−datatype :: IParser D.SourceDecl
30−datatype = do
31− reserved "data" <?> "datatype definition (data T = A | B | ...)"
32− forcedWS
33− name <- capVar <?> "name of data-type"
34− args <- spacePrefix lowVar
35− padded equals
36− tcs <- pipeSep1 Type.constructor
37− return $ D.Datatype name args tcs
21+
22+typeDecl :: IParser D.SourceDecl
23+typeDecl =
24+ do reserved "type" <?> "type declaration"
25+ forcedWS
26+ isAlias <- optionMaybe (string "alias" >> forcedWS)
27+ case isAlias of
28+ Just _ ->
29+ do name <- capVar
30+ args <- spacePrefix lowVar
31+ padded equals
32+ tipe <- Type.expr
33+ return (D.TypeAlias name args tipe)
34+
35+ Nothing ->
36+ do name <- capVar <?> "name of data-type"
37+ args <- spacePrefix lowVar
38+ padded equals
39+ tcs <- pipeSep1 Type.constructor
40+ return $ D.Datatype name args tcs
3841
3942
4043infixDecl :: IParser D.SourceDecl