1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2module Parse.Declaration where
4import Text.Parsec ( (<?>), choice, digit, optionMaybe, string, try )
6import qualified AST.Declaration as Decl
7import qualified Parse.Expression as Expr
8import Parse.Helpers as Help
9import qualified Parse.Type as Type
13declaration :: IParser Decl.Source
15 commentOr $ addLocation $
24commentOr :: IParser a -> IParser (Decl.CommentOr a)
27 [ Decl.Comment <$> addLocation Help.docComment
28 , Decl.Whatever <$> parser
33-- TYPE ANNOTATIONS and DEFINITIONS
36definition :: IParser Decl.Raw
38 do def <- Expr.def <?> "a value definition"
43-- TYPE ALIAS and UNION TYPES
46typeDecl :: IParser Decl.Raw
48 do try (reserved "type") <?> "a type declaration"
50 isAlias <- optionMaybe (string "alias" >> forcedWS)
53 args <- spacePrefix lowVar
58 do tipe <- Type.expr <?> "a type"
59 return $ Decl.Alias (Decl.Type name args tipe)
62 do tcs <- pipeSep1 Type.constructor <?> "a constructor for a union type"
63 return $ Decl.Union (Decl.Type name args tcs)
70infixDecl :: IParser Decl.Raw
72 expecting "an infix declaration" $
75 [ try (reserved "infixl") >> return Decl.L
76 , try (reserved "infixr") >> return Decl.R
77 , try (reserved "infix") >> return Decl.N
83 return $ Decl.Fixity (Decl.Infix op assoc (read [n]))
90portDecl :: IParser Decl.Raw
92 expecting "a port declaration" $
93 do try (reserved "port")
98 return $ Decl.Port name tipe
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list