1module Parse.Module (header, headerAndImports, 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
20 return (Module.nameToString names)
23headerAndImports :: IParser Module.HeaderAndImports
27 option (["Main"], Var.openListing) (header `followedBy` freshLine)
29 return $ Module.HeaderAndImports names exports imports'
32header :: 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.Name, Module.ImportMethod)]
46 many (import' `followedBy` freshLine)
49import' :: IParser (Module.Name, Module.ImportMethod)
51 do try (reserved "import")
53 names <- dotSep1 capVar
54 (,) names <$> method (Module.nameToString names)
56 method :: String -> IParser Module.ImportMethod
59 <$> option (Just defaultAlias) (Just <$> as')
60 <*> option Var.closedListing exposing
64 do try (whitespace >> reserved "as")
66 capVar <?> "alias for module"
68 exposing :: IParser (Var.Listing Var.Value)
70 do try (whitespace >> reserved "exposing")
75listing :: IParser a -> IParser (Var.Listing a)
77 do try (whitespace >> char '(')
81 [ const Var.openListing <$> string ".."
82 , Var.Listing <$> commaSep1 item <*> return False
83 ] <?> "listing of values (x,y,z)"
89value :: IParser Var.Value
94 Var.Value <$> (lowVar <|> parens symOp)
98 maybeCtors <- optionMaybe (listing capVar)
100 Nothing -> return (Var.Alias name)
101 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