@@ -10,30 +10,30 @@ import qualified Parse.Type as Type
10import qualified AST.Declaration as D
10import qualified AST.Declaration as D
12declaration :: IParser D.SourceDecl
12declaration :: IParser D.SourceDecl
13−declaration = alias <|> datatype <|> infixDecl <|> port <|> definition
13+declaration = typeDecl <|> infixDecl <|> port <|> definition
15definition :: IParser D.SourceDecl
15definition :: IParser D.SourceDecl
16definition = D.Definition <$> Expr.def
16definition = D.Definition <$> Expr.def
18−alias :: IParser D.SourceDecl
18+typeDecl :: IParser D.SourceDecl
19−alias = do
19+typeDecl =
20− reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
20+ do reserved "type" <?> "type declaration"
22+ isAlias <- optionMaybe (string "alias" >> forcedWS)
22− name <- capVar
25+ do name <- capVar
23− args <- spacePrefix lowVar
26+ args <- spacePrefix lowVar
24− padded equals
27+ padded equals
25− tipe <- Type.expr
28+ tipe <- Type.expr
26− return (D.TypeAlias name args tipe)
29+ return (D.TypeAlias name args tipe)
28−datatype :: IParser D.SourceDecl
31+ Nothing ->
30− reserved "data" <?> "datatype definition (data T = A | B | ...)"
32− name <- capVar <?> "name of data-type"
32+ do name <- capVar <?> "name of data-type"
33− args <- spacePrefix lowVar
33+ args <- spacePrefix lowVar
34− padded equals
34+ padded equals
35− tcs <- pipeSep1 Type.constructor
35+ tcs <- pipeSep1 Type.constructor
36− return $ D.Datatype name args tcs
36+ return $ D.Datatype name args tcs
39infixDecl :: IParser D.SourceDecl
39infixDecl :: IParser D.SourceDecl