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
11getModuleName :: String -> Maybe String
13 case iParse getModuleName source of
14 Right name -> Just name
20 return (intercalate "." names)
22headerAndImports :: IParser Module.HeaderAndImports
26 option (["Main"], Var.openListing) (header `followedBy` freshLine)
27 imports' <- commitToImports <|> return []
28 return $ Module.HeaderAndImports names exports imports'
31 do try (lookAhead $ reserved "import")
32 imports `followedBy` freshLine
34header :: IParser ([String], Var.Listing Var.Value)
36 try (reserved "module")
38 names <- dotSep1 capVar <?> "name of module"
40 exports <- option Var.openListing (listing value)
41 whitespace <?> "reserved word 'where'"
43 return (names, exports)
45imports :: IParser [(Module.Name, Module.ImportMethod)]
46imports = option [] ((:) <$> import' <*> many (try (freshLine >> import')))
48import' :: IParser (Module.Name, Module.ImportMethod)
52 names <- dotSep1 capVar
53 (,) names <$> option (Module.As (intercalate "." names)) method
55 method :: IParser Module.ImportMethod
56 method = as' <|> importing'
58 as' :: IParser Module.ImportMethod
60 try (whitespace >> reserved "as")
62 Module.As <$> capVar <?> "alias for module"
64 importing' :: IParser Module.ImportMethod
65 importing' = Module.Open <$> listing value
67listing :: IParser a -> IParser (Var.Listing a)
69 do try (whitespace >> char '(')
71 listing <- choice [ const Var.openListing <$> string ".."
72 , Var.Listing <$> commaSep1 item <*> return False
73 ] <?> "listing of values (x,y,z)"
78value :: IParser Var.Value
81 val = Var.Value <$> (lowVar <|> parens symOp)
85 maybeCtors <- optionMaybe (listing capVar)
87 Nothing -> return (Var.Alias name)
88 Just ctors -> return (Var.ADT 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