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.Module.Name as ModuleName
9import qualified AST.Variable as Var
10import Reporting.Annotation as A
13getModuleName :: String -> Maybe String
15 case iParse getModuleName source of
24 (names, _) <- moduleDecl
25 return (ModuleName.toString names)
28header :: IParser (Module.Header [Module.UserImport])
32 option (["Main"], Var.openListing) (moduleDecl `followedBy` freshLine)
35 [ addLocation (Just <$> docComment) `followedBy` freshLine
36 , addLocation (return Nothing)
39 return (Module.Header names docs exports imports')
42moduleDecl :: IParser ([String], Var.Listing (A.Located Var.Value))
44 expecting "a module declaration" $
45 do try (reserved "module")
47 names <- dotSep1 capVar <?> "the name of this module"
49 exports <- option Var.openListing (listing (addLocation value))
52 return (names, exports)
55imports :: IParser [Module.UserImport]
57 many (import' `followedBy` freshLine)
60import' :: IParser Module.UserImport
62 expecting "an import" $
64 do try (reserved "import")
66 names <- dotSep1 capVar
67 (,) names <$> method (ModuleName.toString names)
69 method :: String -> IParser Module.ImportMethod
72 <$> option (Just defaultAlias) (Just <$> as' defaultAlias)
73 <*> option Var.closedListing exposing
75 as' :: String -> IParser String
77 do try (whitespace >> reserved "as")
79 capVar <?> ("an alias for module `" ++ moduleName ++ "`")
81 exposing :: IParser (Var.Listing Var.Value)
83 do try (whitespace >> reserved "exposing")
88listing :: IParser a -> IParser (Var.Listing a)
90 expecting "a listing of values and types to expose, like (..)" $
91 do try (whitespace >> char '(')
95 [ const Var.openListing <$> string ".."
96 , Var.Listing <$> commaSep1 item <*> return False
103value :: IParser Var.Value
105 val <|> tipe <?> "a value or type to expose"
108 Var.Value <$> (lowVar <|> parens symOp)
112 maybeCtors <- optionMaybe (listing capVar)
114 Nothing -> return (Var.Alias name)
115 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