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
11getModuleName :: String -> Maybe String
13 case iParse getModuleName source of
14 Right name -> Just name
19 (names, _) <- moduleDecl
20 return (Module.nameToString names)
23header :: IParser (Module.Header [Module.UserImport])
27 option (["Main"], Var.openListing) (moduleDecl `followedBy` freshLine)
29 return (Module.Header names exports imports')
32moduleDecl :: IParser ([String], Var.Listing Var.Value)
34 do try (reserved "module")
36 names <- dotSep1 capVar <?> "name of module"
38 exports <- option Var.openListing (listing value)
39 whitespace <?> "reserved word 'where'"
41 return (names, exports)
44imports :: IParser [Module.UserImport]
46 many (import' `followedBy` freshLine)
49import' :: IParser Module.UserImport
52 do try (reserved "import")
54 names <- dotSep1 capVar
55 (,) names <$> method (Module.nameToString names)
57 method :: String -> IParser Module.ImportMethod
60 <$> option (Just defaultAlias) (Just <$> as')
61 <*> option Var.closedListing exposing
65 do try (whitespace >> reserved "as")
67 capVar <?> "alias for module"
69 exposing :: IParser (Var.Listing Var.Value)
71 do try (whitespace >> reserved "exposing")
76listing :: IParser a -> IParser (Var.Listing a)
78 do try (whitespace >> char '(')
82 [ const Var.openListing <$> string ".."
83 , Var.Listing <$> commaSep1 item <*> return False
84 ] <?> "listing of values (x,y,z)"
90value :: IParser Var.Value
95 Var.Value <$> (lowVar <|> parens symOp)
99 maybeCtors <- optionMaybe (listing capVar)
101 Nothing -> return (Var.Alias name)
102 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