on master help sign in
Allow elm-doc to handle type aliases and ADTs.
ee91bd9evancz
compiler/Docs.hs+2−1
@@ -43,7 +43,7 @@ docParse = setupParser $ do
43
43
44annotation :: [String] -> IParser (Maybe (String, String, String))
44annotation :: [String] -> IParser (Maybe (String, String, String))
45annotation exports =
45annotation exports =
46− try ((\c n t -> export (n,t,c)) <$> comment <*> name <*> tipe)
46+ try ((\c n t -> export (n,t,c)) <$> comment <*> (try adt <|> name) <*> tipe)
47 where
47 where
48 comment = concatMap clip <$> many lineComment
48 comment = concatMap clip <$> many lineComment
49 clip str = case str of { ' ':rest -> rest ; _ -> str } ++ "\n"
49 clip str = case str of { ' ':rest -> rest ; _ -> str } ++ "\n"
@@ -56,6 +56,7 @@ annotation exports =
56 export info@(name,_,_) =
56 export info@(name,_,_) =
57 if null exports || name `elem` exports then Just info else Nothing
57 if null exports || name `elem` exports then Just info else Nothing
58
58
59+ adt = lookAhead ((string "data" <|> string "type") >> whitespace >> capVar)
59
60
60
61
61setupParser p source =
62setupParser p source =
compiler/Types/Hints.hs+8−4
@@ -1,6 +1,8 @@
1module Types.Hints (hints) where
1module Types.Hints (hints) where
2
2
3import Control.Arrow (first)
3import Control.Arrow (first)
4+import Control.Monad (liftM)
5+import Data.Maybe (catMaybes)
4import qualified Data.Map as Map
6import qualified Data.Map as Map
5import Guid
7import Guid
6import qualified Libraries as Libs
8import qualified Libraries as Libs
@@ -10,7 +12,7 @@ import qualified Types.Substitutions as Subs
10import Types.Types
12import Types.Types
11
13
12hints :: GuidCounter [(String, Scheme)]
14hints :: GuidCounter [(String, Scheme)]
13−hints = mapM toScheme values
15+hints = liftM catMaybes (mapM toScheme values)
14 where
16 where
15 values :: [(String, String)]
17 values :: [(String, String)]
16 values = addPrefixes (Map.toList (Map.map Map.toList Libs.libraries))
18 values = addPrefixes (Map.toList (Map.map Map.toList Libs.libraries))
@@ -18,10 +20,12 @@ hints = mapM toScheme values
18 addPrefixes :: [(String,[(String, String)])] -> [(String, String)]
20 addPrefixes :: [(String,[(String, String)])] -> [(String, String)]
19 addPrefixes = concatMap (\(m,vs) -> map (first (\n -> m ++ "." ++ n)) vs)
21 addPrefixes = concatMap (\(m,vs) -> map (first (\n -> m ++ "." ++ n)) vs)
20
22
21− toScheme :: (String, String) -> GuidCounter (String, Scheme)
23+ toScheme :: (String, String) -> GuidCounter (Maybe (String, Scheme))
24+ toScheme (name, 't':'y':'p':'e':' ':_) = return Nothing
25+ toScheme (name, 'd':'a':'t':'a':' ':_) = return Nothing
22 toScheme (name, tipeString) =
26 toScheme (name, tipeString) =
23− let err = "in docs.json parsing type: " ++ tipeString in
27+ let err = "compiler error parsing type of " ++ name ++ ":\n" ++ tipeString in
24 case iParse (fmap toType typeExpr) err tipeString of
28 case iParse (fmap toType typeExpr) err tipeString of
25 Left err -> error (show err)
29 Left err -> error (show err)
26 Right tipe -> do scheme <- Subs.generalize [] =<< Subs.superize name tipe
30 Right tipe -> do scheme <- Subs.generalize [] =<< Subs.superize name tipe
27− return (name, scheme)
31+ return (Just (name, scheme))