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