1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2module Parse.Module (moduleDecl, header, getModuleName) where
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
18 (_, names, _) <- moduleDecl
19 return (ModuleName.toString names)
21 case iParse minimalParser source of
29header :: IParser (Module.Header [Module.UserImport])
32 (tag, names, exports) <-
34 (Module.None, ["Main"], Var.openListing)
35 (moduleDecl `followedBy` freshLine)
39 [ addLocation (Just <$> docComment) `followedBy` freshLine
40 , addLocation (return Nothing)
45 return (Module.Header tag names docs exports imports')
48moduleDecl :: IParser (Module.Tag, [String], Var.Listing (A.Located Var.Value))
50 expecting "a module declaration" $
54 [ do try (reserved "module")
56 , do try (reserved "effect")
60 , do reserved "foreign"
69 names <- dotSep1 capVar <?> "the name of this module"
72 exports <- option Var.openListing (listing (addLocation value))
77 return (kind, names, exports)
80imports :: IParser [Module.UserImport]
82 many (import' `followedBy` freshLine)
85import' :: IParser Module.UserImport
87 expecting "an import" $
89 do try (reserved "import")
91 names <- dotSep1 capVar
92 (,) names <$> method (ModuleName.toString names)
94 method :: String -> IParser Module.ImportMethod
97 <$> option (Just defaultAlias) (Just <$> as' defaultAlias)
98 <*> option Var.closedListing exposing
100 as' :: String -> IParser String
102 do try (whitespace >> reserved "as")
104 capVar <?> ("an alias for module `" ++ moduleName ++ "`")
106 exposing :: IParser (Var.Listing Var.Value)
108 do try (whitespace >> reserved "exposing")
113listing :: IParser a -> IParser (Var.Listing a)
115 expecting "a listing of values and types to expose, like (..)" $
116 do try (whitespace >> char '(')
120 [ const Var.openListing <$> string ".."
121 , Var.Listing <$> commaSep1 item <*> return False
128value :: IParser Var.Value
130 val <|> tipe <?> "a value or type to expose"
133 Var.Value <$> (lowVar <|> parens symOp)
137 maybeCtors <- optionMaybe (listing capVar)
139 Nothing -> return (Var.Alias name)
140 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