@@ -1,100 +0,0 @@
1−module Docs.Centralize (centralize) where
2−
3−import Control.Arrow (second)
4−import qualified Data.Map as Map
5−import qualified Data.Maybe as Maybe
6−import Data.Text (Text)
7−
8−import qualified AST.Declaration as Decl
9−import qualified AST.Expression.Canonical as Canonical
10−import qualified AST.Helpers as Help
11−import qualified AST.Pattern as Pattern
12−import qualified AST.Type as Type
13−import qualified Docs.AST as Docs
14−import qualified Elm.Compiler.Type.Extract as Extract
15−import qualified Reporting.Annotation as A
16−import qualified Reporting.Region as R
17−
18−
19−
20−-- CENTRALIZE
21−
22−
23−centralize :: Decl.Canonical -> Text -> Docs.Centralized
24−centralize (Decl.Decls defs unions aliases infixes) overview =
25− let
26− infixDict =
27− Map.fromList (map toInfixPair infixes)
28− in
29− Docs.Docs
30− overview
31− (Map.fromList (map unionToEntry unions))
32− (Map.fromList (map aliasToEntry aliases))
33− (Map.fromList (Maybe.mapMaybe (defToEntry infixDict) defs))
34−
35−
36−
37−-- ENTRY
38−
39−
40−type Entry a =
41− (Text, Docs.Raw a)
42−
43−
44−makeEntry :: Text -> (R.Region, Maybe Text) -> details -> Entry details
45−makeEntry name (region, maybeComment) details =
46− ( name, A.A region (Docs.Entry maybeComment details) )
47−
48−
49−
50−-- UNIONS
51−
52−
53−unionToEntry :: A.Commented (Decl.Union Type.Canonical) -> Entry Docs.Union
54−unionToEntry (A.A ann (Decl.Type name args ctors)) =
55− makeEntry name ann $ Docs.Union args $
56− map (second (map Extract.extract)) ctors
57−
58−
59−
60−-- ALIASES
61−
62−
63−aliasToEntry :: A.Commented (Decl.Alias Type.Canonical) -> Entry Docs.Alias
64−aliasToEntry (A.A ann (Decl.Type name args tipe)) =
65− makeEntry name ann $ Docs.Alias args $ Extract.extract tipe
66−
67−
68−
69−-- VALUES
70−
71−
72−defToEntry :: Map.Map Text (Decl.Assoc, Int) -> A.Commented Canonical.Def -> Maybe (Entry Docs.RawValue)
73−defToEntry infixDict (A.A (_, maybeComment) definition) =
74− let
75− (Canonical.Def _ (A.A region pattern) _ maybeType) =
76− definition
77−
78− tipe =
79− fmap (Extract.extract . A.drop) maybeType
80− in
81− case pattern of
82− Pattern.Var name ->
83− Just $ makeEntry name (region, maybeComment) $
84− case Map.lookup name infixDict of
85− Just (assoc, prec) ->
86− Docs.Infix tipe assoc prec
87−
88− Nothing ->
89− if Help.isOp name then
90− Docs.Infix tipe Decl.defaultAssociativity Decl.defaultPrecedence
91− else
92− Docs.Value tipe
93−
94− _ ->
95− Nothing
96−
97−
98−toInfixPair :: Decl.Infix -> ( Text, (Decl.Assoc, Int) )
99−toInfixPair (Decl.Infix name assoc precedence) =
100− ( name, (assoc, precedence) )