1module Parse.Module (moduleDecl, header, getModuleName) where
3import Control.Applicative ((<$>), (<*>))
4import Text.Parsec hiding (newline, spaces)
7import qualified AST.Module as Module
8import qualified AST.Variable as Var
9import Reporting.Annotation as A
12getModuleName :: String -> Maybe String
14 case iParse getModuleName source of
15 Right name -> Just name
20 (names, _) <- moduleDecl
21 return (Module.nameToString names)
24header :: IParser (Module.Header [Module.UserImport])
28 option (["Main"], Var.openListing) (moduleDecl `followedBy` freshLine)
31 [ addLocation (Just <$> docComment) `followedBy` freshLine
32 , addLocation (return Nothing)
35 return (Module.Header names docs exports imports')
38moduleDecl :: IParser ([String], Var.Listing (A.Located Var.Value))
40 expecting "a module declaration" $
41 do try (reserved "module")
43 names <- dotSep1 capVar <?> "the name of this module"
45 exports <- option Var.openListing (listing (addLocation value))
48 return (names, exports)
51imports :: IParser [Module.UserImport]
53 many (import' `followedBy` freshLine)
56import' :: IParser Module.UserImport
58 expecting "an import" $
60 do try (reserved "import")
62 names <- dotSep1 capVar
63 (,) names <$> method (Module.nameToString names)
65 method :: String -> IParser Module.ImportMethod
68 <$> option (Just defaultAlias) (Just <$> as' defaultAlias)
69 <*> option Var.closedListing exposing
71 as' :: String -> IParser String
73 do try (whitespace >> reserved "as")
75 capVar <?> ("an alias for module `" ++ moduleName ++ "`")
77 exposing :: IParser (Var.Listing Var.Value)
79 do try (whitespace >> reserved "exposing")
84listing :: IParser a -> IParser (Var.Listing a)
86 expecting "a listing of values and types to expose, like (..)" $
87 do try (whitespace >> char '(')
91 [ const Var.openListing <$> string ".."
92 , Var.Listing <$> commaSep1 item <*> return False
99value :: IParser Var.Value
101 val <|> tipe <?> "a value or type to expose"
104 Var.Value <$> (lowVar <|> parens symOp)
108 maybeCtors <- optionMaybe (listing capVar)
110 Nothing -> return (Var.Alias name)
111 Just ctors -> return (Var.Union name ctors)
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