1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2module Parse.Declaration where
4import Control.Applicative ((<$>))
5import Text.Parsec hiding (newline,spaces)
8import qualified Parse.Expression as Expr
9import qualified Parse.Type as Type
10import qualified AST.Declaration as D
12declaration :: IParser D.SourceDecl
13declaration = alias <|> datatype <|> infixDecl <|> port <|> definition
15definition :: IParser D.SourceDecl
16definition = D.Definition <$> Expr.def
18alias :: IParser D.SourceDecl
20 reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
23 args <- spacePrefix lowVar
26 return (D.TypeAlias name args tipe)
28datatype :: IParser D.SourceDecl
30 reserved "data" <?> "datatype definition (data T = A | B | ...)"
32 name <- capVar <?> "name of data-type"
33 args <- spacePrefix lowVar
35 tcs <- pipeSep1 Type.constructor
36 return $ D.Datatype name args tcs
39infixDecl :: IParser D.SourceDecl
41 assoc <- choice [ reserved "infixl" >> return D.L
42 , reserved "infix" >> return D.N
43 , reserved "infixr" >> return D.R ]
47 D.Fixity assoc (read [n]) <$> anyOp
50port :: IParser D.SourceDecl
52 do try (reserved "port")
56 let port' op ctor expr = do { try op ; whitespace ; ctor name <$> expr }
57 D.Port <$> choice [ port' hasType D.PPAnnotation Type.expr
58 , port' equals D.PPDef Expr.expr ]
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