on master help sign in
Add pretty printing and require a module declaration and structure comment
commitae5ef9db97972c6f7569a567a834455497b07cc2 authorEvan Czaplicki <info@elm-lang.org> dateThu 5 Sep 2013, 10:48 (13 years ago) parentcaf2d0a
2 files changed+13−7
Elm.cabal+1 compiler/Docs.hs+12−7
Elm.cabal+1
@@ -191,6 +191,7 @@ Executable elm-doc
191191 Parse.Type
192192
193193 Build-depends: aeson,
194+ aeson-pretty,
194195 base >=4.2 && <5,
195196 binary,
196197 bytestring,
compiler/Docs.hs+12−7
@@ -8,6 +8,7 @@ import System.Exit
88
99import Control.Applicative ((<$>), (<*>))
1010import Data.Aeson
11+import Data.Aeson.Encode.Pretty
1112import qualified Data.List as List
1213import qualified Data.Map as Map
1314import qualified Data.ByteString.Lazy as BS
@@ -41,25 +42,29 @@ parseFile path = do
4142 Right json -> do
4243 putStrLn $ "Documenting " ++ path
4344 createDirectoryIfMissing True "docs"
44− BS.writeFile ("docs" </> replaceExtension path ".json") (encode json)
45+ BS.writeFile ("docs" </> replaceExtension path ".json")
46+ (encodePretty' (defConfig { confIndent = 2 }) json)
4547 Left err -> do
4648 putStrLn $ "Parse error in " ++ path ++ " at " ++ show err
4749 exitFailure
4850
4951docs :: IParser Value
5052docs = do
51− optional freshLine
52− (names, exports) <- option (["Main"],[]) moduleDef
53− optional freshLine
54− structure <- option "" docComment
53+ (name, exports, structure) <- moduleDocs
5554 things <- document
56− return $ toJson (List.intercalate "." names) exports structure things
55+ return $ toJson name exports structure things
5756
5857docComment :: IParser String
5958docComment = do
6059 try (string "{-|")
6160 contents <- closeComment
62− return (init (init contents))
61+ return $ dropWhile (==' ') (init (init contents))
62+
63+moduleDocs = do
64+ (names,exports) <- anyThen moduleDef
65+ anyThen (lookAhead (string "{-|"))
66+ structure <- docComment
67+ return (List.intercalate "." names, exports, structure)
6368
6469document :: IParser [(String, Declaration t v, String)]
6570document = go []