on master help sign in
Add type annotations
25e88a2Evan Czaplicki
compiler/Docs.hs+8−2
@@ -31,20 +31,24 @@ data Flags = Flags
31 { files :: [FilePath] }
31 { files :: [FilePath] }
32 deriving (Data,Typeable,Show,Eq)
32 deriving (Data,Typeable,Show,Eq)
33
33
34+defaultFlags :: Flags
34defaultFlags = Flags
35defaultFlags = Flags
35 { files = def &= args &= typ "FILES"
36 { files = def &= args &= typ "FILES"
36 } &= help "Generate documentation for Elm"
37 } &= help "Generate documentation for Elm"
37 &= summary ("Generate documentation for Elm, (c) Evan Czaplicki")
38 &= summary ("Generate documentation for Elm, (c) Evan Czaplicki")
38
39
40+main :: IO ()
39main = do
41main = do
40 flags <- cmdArgs defaultFlags
42 flags <- cmdArgs defaultFlags
41− mapM parseFile (files flags)
43+ mapM_ parseFile (files flags)
42
44
45+config :: Config
43config = Config { confIndent = 2, confCompare = keyOrder keys }
46config = Config { confIndent = 2, confCompare = keyOrder keys }
44 where
47 where
45 keys = ["tag","name","document","comment","raw","aliases","datatypes"
48 keys = ["tag","name","document","comment","raw","aliases","datatypes"
46 ,"values","typeVariables","type","constructors"]
49 ,"values","typeVariables","type","constructors"]
47
50
51+parseFile :: FilePath -> IO ()
48parseFile path = do
52parseFile path = do
49 source <- readFile path
53 source <- readFile path
50 case iParse docs source of
54 case iParse docs source of
@@ -70,6 +74,7 @@ docComment = do
70 let reversed = dropWhile (`elem` " \n\r") . drop 2 $ reverse contents
74 let reversed = dropWhile (`elem` " \n\r") . drop 2 $ reverse contents
71 return $ dropWhile (==' ') (reverse reversed)
75 return $ dropWhile (==' ') (reverse reversed)
72
76
77+moduleDocs :: IParser (String, [String], String)
73moduleDocs = do
78moduleDocs = do
74 optional freshLine
79 optional freshLine
75 (names,exports) <- moduleDef
80 (names,exports) <- moduleDef
@@ -152,7 +157,7 @@ instance ToJSON T.Type where
152 toJSON tipe =
157 toJSON tipe =
153 object $
158 object $
154 case tipe of
159 case tipe of
155− T.Lambda t1 t2 ->
160+ T.Lambda _ _ ->
156 let tipes = T.collectLambdas tipe in
161 let tipes = T.collectLambdas tipe in
157 [ "tag" .= ("function" :: Text.Text)
162 [ "tag" .= ("function" :: Text.Text)
158 , "args" .= toJSON (init tipes)
163 , "args" .= toJSON (init tipes)
@@ -176,6 +181,7 @@ instance ToJSON T.Type where
176 , "extension" .= toJSON ext
181 , "extension" .= toJSON ext
177 ]
182 ]
178
183
184+ctorToJson :: T.Type -> (String, [T.Type]) -> Value
179ctorToJson tipe (ctor, tipes) =
185ctorToJson tipe (ctor, tipes) =
180 object [ "name" .= ctor
186 object [ "name" .= ctor
181 , "type" .= foldr T.Lambda tipe tipes ]
187 , "type" .= foldr T.Lambda tipe tipes ]