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)
30 return (Module.Header names exports imports')
33moduleDecl :: IParser ([String], Var.Listing (A.Located Var.Value))
35 do try (reserved "module")
37 names <- dotSep1 capVar <?> "name of module"
39 exports <- option Var.openListing (listing (addLocation value))
40 whitespace <?> "reserved word 'where'"
42 return (names, exports)
45imports :: IParser [Module.UserImport]
47 many (import' `followedBy` freshLine)
50import' :: IParser Module.UserImport
53 do try (reserved "import")
55 names <- dotSep1 capVar
56 (,) names <$> method (Module.nameToString names)
58 method :: String -> IParser Module.ImportMethod
61 <$> option (Just defaultAlias) (Just <$> as')
62 <*> option Var.closedListing exposing
66 do try (whitespace >> reserved "as")
68 capVar <?> "alias for module"
70 exposing :: IParser (Var.Listing Var.Value)
72 do try (whitespace >> reserved "exposing")
77listing :: IParser a -> IParser (Var.Listing a)
79 do try (whitespace >> char '(')
83 [ const Var.openListing <$> string ".."
84 , Var.Listing <$> commaSep1 item <*> return False
85 ] <?> "listing of values (x,y,z)"
91value :: IParser Var.Value
96 Var.Value <$> (lowVar <|> parens symOp)
100 maybeCtors <- optionMaybe (listing capVar)
102 Nothing -> return (Var.Alias name)
103 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