1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2module Parse.Declaration where
4import Control.Applicative ((<$>))
5import Text.Parsec ((<|>), (<?>), choice, digit, optionMaybe, string, try)
7import qualified AST.Declaration as D
8import qualified Parse.Expression as Expr
10import qualified Parse.Type as Type
13declaration :: IParser D.SourceDecl
15 typeDecl <|> infixDecl <|> port <|> definition
18definition :: IParser D.SourceDecl
19definition = D.Definition <$> Expr.def
22typeDecl :: IParser D.SourceDecl
24 do reserved "type" <?> "type declaration"
26 isAlias <- optionMaybe (string "alias" >> forcedWS)
30 args <- spacePrefix lowVar
33 return (D.TypeAlias name args tipe)
36 do name <- capVar <?> "name of data-type"
37 args <- spacePrefix lowVar
39 tcs <- pipeSep1 Type.constructor
40 return $ D.Datatype name args tcs
43infixDecl :: IParser D.SourceDecl
45 assoc <- choice [ reserved "infixl" >> return D.L
46 , reserved "infix" >> return D.N
47 , reserved "infixr" >> return D.R ]
51 D.Fixity assoc (read [n]) <$> anyOp
54port :: IParser D.SourceDecl
56 do try (reserved "port")
60 let port' op ctor expr = do { try op ; whitespace ; ctor name <$> expr }
61 D.Port <$> choice [ port' hasType D.PPAnnotation Type.expr
62 , 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