1module Parse.Module (header, headerAndImports, getModuleName) where
3import Control.Applicative ((<$>), (<*>))
4import Data.List (intercalate)
5import Text.Parsec hiding (newline, spaces)
8import qualified AST.Module as Module
9import qualified AST.Variable as Var
12getModuleName :: String -> Maybe String
14 case iParse getModuleName source of
15 Right name -> Just name
21 return (intercalate "." names)
24headerAndImports :: IParser Module.HeaderAndImports
28 option (["Main"], Var.openListing) (header `followedBy` freshLine)
30 return $ Module.HeaderAndImports names exports imports'
33header :: IParser ([String], Var.Listing Var.Value)
35 do try (reserved "module")
37 names <- dotSep1 capVar <?> "name of module"
39 exports <- option Var.openListing (listing value)
40 whitespace <?> "reserved word 'where'"
42 return (names, exports)
45imports :: IParser [(Module.Name, Module.ImportMethod)]
47 many (import' `followedBy` freshLine)
50import' :: IParser (Module.Name, Module.ImportMethod)
52 do try (reserved "import")
54 names <- dotSep1 capVar
55 (,) names <$> option (Module.As (intercalate "." names)) method
57 method :: IParser Module.ImportMethod
58 method = as' <|> importing'
60 as' :: IParser Module.ImportMethod
62 try (whitespace >> reserved "as")
64 Module.As <$> capVar <?> "alias for module"
66 importing' :: IParser Module.ImportMethod
67 importing' = Module.Open <$> listing value
70listing :: IParser a -> IParser (Var.Listing a)
72 do try (whitespace >> char '(')
76 [ const Var.openListing <$> string ".."
77 , Var.Listing <$> commaSep1 item <*> return False
78 ] <?> "listing of values (x,y,z)"
84value :: IParser Var.Value
89 Var.Value <$> (lowVar <|> parens symOp)
93 maybeCtors <- optionMaybe (listing capVar)
95 Nothing -> return (Var.Alias name)
96 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