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 SourceSyntax.Declaration as D
13declaration :: IParser D.ParseDeclaration
14declaration = alias <|> datatype <|> infixDecl <|> port <|> definition
16definition :: IParser D.ParseDeclaration
17definition = D.Definition <$> Expr.def
19alias :: IParser D.ParseDeclaration
21 reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
24 args <- spacePrefix lowVar
27 json <- option [] $ do
28 try $ padded (reserved "deriving")
31 return (D.TypeAlias name args tipe json)
33datatype :: IParser D.ParseDeclaration
35 reserved "data" <?> "datatype definition (data T = A | B | ...)"
37 name <- capVar <?> "name of data-type"
38 args <- spacePrefix lowVar
40 tcs <- pipeSep1 Type.constructor
41 return $ D.Datatype name args tcs []
44infixDecl :: IParser D.ParseDeclaration
46 assoc <- choice [ reserved "infixl" >> return D.L
47 , reserved "infix" >> return D.N
48 , reserved "infixr" >> return D.R ]
52 D.Fixity assoc (read [n]) <$> anyOp
55port :: IParser D.ParseDeclaration
57 do try (reserved "port")
61 let port' op ctor expr = do { try op ; whitespace ; ctor name <$> expr }
62 D.Port <$> choice [ port' hasType D.PPAnnotation Type.expr
63 , 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