on master help sign in
Allow elm-doc to handle type aliases and ADTs.
commitee91bd91fc98e7e1e31965c5f97fa1e2b9a07170 authorevancz <info@elm-lang.org> dateFri 17 May 2013, 12:50 (13 years ago) parent5044724
2 files changed+10−5
compiler/Docs.hs+2−1 compiler/Types/Hints.hs+8−4
compiler/Docs.hs+2−1
@@ -43,7 +43,7 @@ docParse = setupParser $ do
4343
4444annotation :: [String] -> IParser (Maybe (String, String, String))
4545annotation 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)
4747 where
4848 comment = concatMap clip <$> many lineComment
4949 clip str = case str of { ' ':rest -> rest ; _ -> str } ++ "\n"
@@ -56,6 +56,7 @@ annotation exports =
5656 export info@(name,_,_) =
5757 if null exports || name `elem` exports then Just info else Nothing
5858
59+ adt = lookAhead ((string "data" <|> string "type") >> whitespace >> capVar)
5960
6061
6162setupParser p source =
compiler/Types/Hints.hs+8−4
@@ -1,6 +1,8 @@
11module Types.Hints (hints) where
22
33import Control.Arrow (first)
4+import Control.Monad (liftM)
5+import Data.Maybe (catMaybes)
46import qualified Data.Map as Map
57import Guid
68import qualified Libraries as Libs
@@ -10,7 +12,7 @@ import qualified Types.Substitutions as Subs
1012import Types.Types
1113
1214hints :: GuidCounter [(String, Scheme)]
13−hints = mapM toScheme values
15+hints = liftM catMaybes (mapM toScheme values)
1416 where
1517 values :: [(String, String)]
1618 values = addPrefixes (Map.toList (Map.map Map.toList Libs.libraries))
@@ -18,10 +20,12 @@ hints = mapM toScheme values
1820 addPrefixes :: [(String,[(String, String)])] -> [(String, String)]
1921 addPrefixes = concatMap (\(m,vs) -> map (first (\n -> m ++ "." ++ n)) vs)
2022
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
2226 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
2428 case iParse (fmap toType typeExpr) err tipeString of
2529 Left err -> error (show err)
2630 Right tipe -> do scheme <- Subs.generalize [] =<< Subs.superize name tipe
27− return (name, scheme)
31+ return (Just (name, scheme))