1module Parse.Module (moduleDecl, header, getModuleName) where
3import Text.Parsec hiding (newline, spaces)
6import qualified AST.Module as Module
7import qualified AST.Module.Name as ModuleName
8import qualified AST.Variable as Var
9import Reporting.Annotation as A
12getModuleName :: String -> Maybe String
14 case iParse getModuleName source of
23 (names, _) <- moduleDecl
24 return (ModuleName.toString names)
27header :: IParser (Module.Header [Module.UserImport])
31 option (["Main"], Var.openListing) (moduleDecl `followedBy` freshLine)
34 [ addLocation (Just <$> docComment) `followedBy` freshLine
35 , addLocation (return Nothing)
38 return (Module.Header names docs exports imports')
41moduleDecl :: IParser ([String], Var.Listing (A.Located Var.Value))
43 expecting "a module declaration" $
44 do try (reserved "module")
46 names <- dotSep1 capVar <?> "the name of this module"
48 exports <- option Var.openListing (listing (addLocation value))
51 return (names, exports)
54imports :: IParser [Module.UserImport]
56 many (import' `followedBy` freshLine)
59import' :: IParser Module.UserImport
61 expecting "an import" $
63 do try (reserved "import")
65 names <- dotSep1 capVar
66 (,) names <$> method (ModuleName.toString names)
68 method :: String -> IParser Module.ImportMethod
71 <$> option (Just defaultAlias) (Just <$> as' defaultAlias)
72 <*> option Var.closedListing exposing
74 as' :: String -> IParser String
76 do try (whitespace >> reserved "as")
78 capVar <?> ("an alias for module `" ++ moduleName ++ "`")
80 exposing :: IParser (Var.Listing Var.Value)
82 do try (whitespace >> reserved "exposing")
87listing :: IParser a -> IParser (Var.Listing a)
89 expecting "a listing of values and types to expose, like (..)" $
90 do try (whitespace >> char '(')
94 [ const Var.openListing <$> string ".."
95 , Var.Listing <$> commaSep1 item <*> return False
102value :: IParser Var.Value
104 val <|> tipe <?> "a value or type to expose"
107 Var.Value <$> (lowVar <|> parens symOp)
111 maybeCtors <- optionMaybe (listing capVar)
113 Nothing -> return (Var.Alias name)
114 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