@@ -4,13 +4,12 @@ module Main where
44import Ast
55import Control.Applicative ((<$>), (<*>))
66import Data.List (intercalate)
7+import Data.Maybe (catMaybes)
78import Parse.Library
89import Parse.Modules (moduleDef)
9−import Parse.Types (typeAnnotation)
1010import Text.Parsec hiding (newline,spaces)
1111import System.Environment
1212import System.Exit
13−import Types.Types
1413
1514
1615main = do
@@ -29,32 +28,34 @@ toModule (name, values) =
2928
3029toValue (name, tipe, desc) =
3130 "{ \"name\" : " ++ show name ++
32− ",\n \"type\" : \"" ++ show tipe ++
33− "\",\n \"desc\" : " ++ show desc ++ "\n }"
31+ ",\n \"type\" : " ++ show tipe ++
32+ ",\n \"desc\" : " ++ show desc ++ "\n }"
3433
35−docParse :: String -> Either String (String, [(String, Type, String)])
34+docParse :: String -> Either String (String, [(String, String, String)])
3635docParse = setupParser $ do
37− optional freshLine
38− (,) <$> option "Main" moduleName <*> types
36+ optional freshLine
37+ (names, exports) <- option (["Main"],[]) (moduleDef `followedBy` freshLine)
38+ info <- many (docs exports <|> try skip <|> end)
39+ return (intercalate "." names, catMaybes info)
3940 where
40− skip = manyTill anyChar simpleNewline >> return []
41− end = many1 anyChar >> return []
42− types = concat <$> many (docs <|> try skip <|> end)
43− getName = intercalate "." . fst
44− moduleName = do optional freshLine
45− getName <$> moduleDef `followedBy` freshLine
46−
47−docs :: IParser [(String, Type, String)]
48−docs = (tipe <$> try typeAnnotation) <|> commentTipe
41+ skip = manyTill anyChar simpleNewline >> return Nothing
42+ end = many1 anyChar >> return Nothing
43+
44+docs :: [String] -> IParser (Maybe (String, String, String))
45+docs exports = export <$> try annotation
4946 where
50− clip str = case str of { ' ':rest -> rest ; _ -> str }
51− tipe stmt = case stmt of { TypeAnnotation n t -> [(n,t,"")] ; _ -> [] }
52− commentTipe = do
53− cs <- map clip <$> many1 lineComment
54− typ <- optionMaybe (try typeAnnotation)
55− return $ case typ of
56− Just (TypeAnnotation n t) -> [(n, t, intercalate "\n" cs)]
57− _ -> []
47+ tipe comment = tuple <$> name <*> tipe
48+ where name = do v <- lowVar <|> parens symOp
49+ whitespace ; hasType ; whitespace ; return v
50+ tipe = manyTill anyChar (try (freshLine >> notFollowedBy (string " ")))
51+ tuple n t = (n,t,comment)
52+
53+ annotation = tipe =<< option "" (concatMap clip <$> many1 lineComment)
54+ where clip str = case str of { ' ':rest -> rest ; _ -> str } ++ "\n"
55+
56+ export info@(name,_,_) =
57+ if null exports || name `elem` exports then Just info else Nothing
58+
5859
5960
6061setupParser p source =