1module Parse.Module (moduleDef, getModuleName, imports) where
3import Control.Applicative ((<$>), (<*>))
4import Data.List (intercalate)
5import Text.Parsec hiding (newline,spaces)
8import AST.Module (ImportMethod(..))
9import AST.Variable (Listing(..), Value(..), openListing)
11getModuleName :: String -> Maybe String
13 case iParse getModuleName source of
14 Right name -> Just name
19 (names, _) <- moduleDef
20 return (intercalate "." names)
22moduleDef :: IParser ([String], Listing Value)
24 try (reserved "module")
26 names <- dotSep1 capVar <?> "name of module"
28 exports <- option (Listing [] True) (listing value)
29 whitespace <?> "reserved word 'where'"
31 return (names, exports)
33imports :: IParser [(String, ImportMethod)]
34imports = option [] ((:) <$> import' <*> many (try (freshLine >> import')))
36import' :: IParser (String, ImportMethod)
40 name <- intercalate "." <$> dotSep1 capVar
41 (,) name <$> option (As name) method
43 method :: IParser ImportMethod
44 method = as' <|> importing'
46 as' :: IParser ImportMethod
48 try (whitespace >> reserved "as")
50 As <$> capVar <?> "alias for module"
52 importing' :: IParser ImportMethod
53 importing' = Open <$> listing value
55listing :: IParser a -> IParser (Listing a)
57 do try (whitespace >> char '(')
59 listing <- choice [ const openListing <$> string ".."
60 , Listing <$> commaSep1 item <*> return False
61 ] <?> "listing of values (x,y,z)"
69 val = Value <$> (lowVar <|> parens symOp)
73 maybeCtors <- optionMaybe (listing capVar)
75 Nothing -> return (Alias name)
76 Just ctors -> return (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