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 return (D.TypeAlias name args tipe)
29datatype :: IParser D.ParseDeclaration
31 reserved "data" <?> "datatype definition (data T = A | B | ...)"
33 name <- capVar <?> "name of data-type"
34 args <- spacePrefix lowVar
36 tcs <- pipeSep1 Type.constructor
37 return $ D.Datatype name args tcs
40infixDecl :: IParser D.ParseDeclaration
42 assoc <- choice [ reserved "infixl" >> return D.L
43 , reserved "infix" >> return D.N
44 , reserved "infixr" >> return D.R ]
48 D.Fixity assoc (read [n]) <$> anyOp
51port :: IParser D.ParseDeclaration
53 do try (reserved "port")
57 let port' op ctor expr = do { try op ; whitespace ; ctor name <$> expr }
58 D.Port <$> choice [ port' hasType D.PPAnnotation Type.expr
59 , 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