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.Binop as Binop
8import qualified Parse.Expression as Expr
9import Parse.Helpers as Help
10import qualified Parse.Type as Type
14declaration :: IParser Decl.Source
16 commentOr $ addLocation $
25commentOr :: IParser a -> IParser (Decl.CommentOr a)
28 [ Decl.Comment <$> addLocation Help.docComment
29 , Decl.Whatever <$> parser
34-- TYPE ANNOTATIONS and DEFINITIONS
37definition :: IParser Decl.Raw
39 do def <- Expr.def <?> "a value definition"
44-- TYPE ALIAS and UNION TYPES
47typeDecl :: IParser Decl.Raw
49 do try (reserved "type") <?> "a type declaration"
51 isAlias <- optionMaybe (string "alias" >> forcedWS)
54 args <- spacePrefix lowVar
59 do tipe <- Type.expr <?> "a type"
60 return $ Decl.Alias (Decl.Type name args tipe)
63 do tcs <- pipeSep1 Type.constructor <?> "a constructor for a union type"
64 return $ Decl.Union (Decl.Type name args tcs)
71infixDecl :: IParser Decl.Raw
73 expecting "an infix declaration" $
76 [ try (reserved "infixl") >> return Decl.L
77 , try (reserved "infixr") >> return Decl.R
78 , try (reserved "infix") >> return Decl.N
84 return $ Decl.Fixity (Decl.Infix op assoc (read [n]))
91portDecl :: IParser Decl.Raw
93 expecting "a port declaration" $
94 do try (reserved "port")
99 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