on master help sign in
Carve declaration parser into chunks
0cb7175Evan Czaplicki
src/Parse/Declaration.hs+8
@@ -15,11 +15,15 @@ declaration =
15 typeDecl <|> infixDecl <|> port <|> definition
15 typeDecl <|> infixDecl <|> port <|> definition
16
16
17
17
18+-- TYPE ANNOTATIONS and DEFINITIONS
19+
18definition :: IParser D.SourceDecl
20definition :: IParser D.SourceDecl
19definition =
21definition =
20 D.Definition <$> (Expr.typeAnnotation <|> Expr.definition)
22 D.Definition <$> (Expr.typeAnnotation <|> Expr.definition)
21
23
22
24
25+-- TYPE ALIAS and UNION TYPES
26+
23typeDecl :: IParser D.SourceDecl
27typeDecl :: IParser D.SourceDecl
24typeDecl =
28typeDecl =
25 do try (reserved "type") <?> "type declaration"
29 do try (reserved "type") <?> "type declaration"
@@ -40,6 +44,8 @@ typeDecl =
40 return $ D.Datatype name args tcs
44 return $ D.Datatype name args tcs
41
45
42
46
47+-- INFIX
48+
43infixDecl :: IParser D.SourceDecl
49infixDecl :: IParser D.SourceDecl
44infixDecl =
50infixDecl =
45 do assoc <-
51 do assoc <-
@@ -54,6 +60,8 @@ infixDecl =
54 D.Fixity assoc (read [n]) <$> anyOp
60 D.Fixity assoc (read [n]) <$> anyOp
55
61
56
62
63+-- PORT
64+
57port :: IParser D.SourceDecl
65port :: IParser D.SourceDecl
58port =
66port =
59 do try (reserved "port")
67 do try (reserved "port")