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 addLocation (typeDecl <|> infixDecl <|> port <|> definition)
18-- TYPE ANNOTATIONS and DEFINITIONS
20definition :: IParser D.SourceDecl'
22 D.Definition <$> (Expr.typeAnnotation <|> Expr.definition)
25-- TYPE ALIAS and UNION TYPES
27typeDecl :: IParser D.SourceDecl'
29 do try (reserved "type") <?> "type declaration"
31 isAlias <- optionMaybe (string "alias" >> forcedWS)
34 args <- spacePrefix lowVar
39 do tipe <- Type.expr <?> "a type"
40 return (D.TypeAlias name args tipe)
43 do tcs <- pipeSep1 Type.constructor <?> "a constructor for a union type"
44 return $ D.Datatype name args tcs
49infixDecl :: IParser D.SourceDecl'
53 [ try (reserved "infixl") >> return D.L
54 , try (reserved "infixr") >> return D.R
55 , try (reserved "infix") >> return D.N
60 D.Fixity assoc (read [n]) <$> anyOp
65port :: IParser D.SourceDecl'
67 do try (reserved "port")
71 choice [ portAnnotation name, portDefinition name ]
76 tipe <- Type.expr <?> "a type"
77 return (D.Port (D.PortAnnotation name tipe))
83 return (D.Port (D.PortDefinition name 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