@@ -2,6 +2,7 @@
22module Main where
33
44import System.Console.CmdArgs
5+import System.Directory
56import System.FilePath
67import System.Exit
78
@@ -39,6 +40,7 @@ parseFile path = do
3940 case iParse docs "" source of
4041 Right json -> do
4142 putStrLn $ "Documenting " ++ path
43+ createDirectoryIfMissing True "docs"
4244 BS.writeFile ("docs" </> replaceExtension path ".json") (encode json)
4345 Left err -> do
4446 putStrLn $ "Parse error in " ++ path ++ " at " ++ show err
@@ -48,8 +50,8 @@ docs :: IParser Value
4850docs = do
4951 optional freshLine
5052 (names, exports) <- option (["Main"],[]) moduleDef
51− chompUntilFreshLine
52− structure <- docComment
53+ optional freshLine
54+ structure <- option "" docComment
5355 things <- document
5456 return $ toJson (List.intercalate "." names) exports structure things
5557
@@ -80,15 +82,18 @@ chompUntilFreshLine =
8082 , eof >> return True ]
8183
8284docThing :: IParser (String, Declaration t v, String)
83−docThing = uncommented <|> commented
85+docThing = uncommentable <|> commented <|> uncommented ""
8486 where
85− uncommented = do
87+ uncommentable = do
8688 ifx <- infixDecl
8789 return ("", ifx, "")
8890
8991 commented = do
90− comment <- option "" docComment
92+ comment <- docComment
9193 freshLine
94+ uncommented comment
95+
96+ uncommented comment = do
9297 (src,def) <- withSource $ choice [ alias, datatype, Definition <$> typeAnnotation ]
9398 return (comment, def, src)
9499