@@ -5,6 +5,8 @@ import Ast
55import Control.Applicative ((<$>), (<*>))
66import Data.List (intercalate)
77import Data.Maybe (catMaybes)
8+import Types.Types ((==>), Type ( ADT, VarT ) )
9+import Parse.Types (datatype)
810import Parse.Library
911import Parse.Modules (moduleDef)
1012import Text.Parsec hiding (newline,spaces)
@@ -35,15 +37,19 @@ docParse :: String -> Either String (String, [(String, String, String)])
3537docParse = setupParser $ do
3638 optional freshLine
3739 (names, exports) <- option (["Main"],[]) moduleDef
38− info <- many (annotation exports <|> try skip <|> end)
39− return (intercalate "." names, catMaybes info)
40+ info <- many (try (annotation exports) <|> try skip <|> end)
41+ return (intercalate "." names, concat info)
4042 where
41− skip = manyTill anyChar simpleNewline >> return Nothing
42− end = many1 anyChar >> return Nothing
43+ skip = manyTill anyChar simpleNewline >> return []
44+ end = many1 anyChar >> return []
4345
44−annotation :: [String] -> IParser (Maybe (String, String, String))
46+annotation :: [String] -> IParser [(String, String, String)]
4547annotation exports =
46− try ((\c n t -> export (n,t,c)) <$> comment <*> (try adt <|> name) <*> tipe)
48+ do description <- comment
49+ extras <- option [] (lookAhead adt)
50+ varName <- try typeDef <|> name
51+ varType <- tipe
52+ return $ extras ++ export varName varType description
4753 where
4854 comment = concatMap clip <$> many lineComment
4955 clip str = case str of { ' ':rest -> rest ; _ -> str } ++ "\n"
@@ -53,11 +59,16 @@ annotation exports =
5359
5460 tipe = manyTill anyChar (try (simpleNewline >> notFollowedBy (string " ")))
5561
56− export info@(name,_,_) =
57− if null exports || name `elem` exports then Just info else Nothing
62+ export name tipe desc =
63+ if null exports || name `elem` exports then [(name,tipe,desc)] else []
5864
59− adt = lookAhead ((string "data" <|> string "type") >> whitespace >> capVar)
65+ typeDef = lookAhead ((string "data" <|> string "type") >> whitespace >> capVar)
6066
67+ adt = do
68+ (Datatype name tvs constructors) <- datatype
69+ let toType (cName, typeArgs) =
70+ (cName, show $ foldr (==>) (ADT name $ map VarT tvs) typeArgs, "")
71+ return $ map toType constructors
6172
6273setupParser p source =
6374 case iParse p "" source of