@@ -1,5 +1,5 @@
1{-# LANGUAGE PatternGuards #-}
1{-# LANGUAGE PatternGuards #-}
2−module Idris.Docs where
2+module Idris.Docs (pprintDocs, getDocs, FunDoc(..), Docs (..)) where
4import Idris.AbsSyntax
4import Idris.AbsSyntax
5import Idris.AbsSyntaxTree
5import Idris.AbsSyntaxTree
@@ -34,11 +34,11 @@ data Docs = FunDoc FunDoc
34showDoc d | nullDocstring d = empty
34showDoc d | nullDocstring d = empty
35 | otherwise = text " -- " <> renderDocstring d
35 | otherwise = text " -- " <> renderDocstring d
37−pprintFD :: Bool -> FunDoc -> Doc OutputAnnotation
37+pprintFD :: IState -> FunDoc -> Doc OutputAnnotation
38−pprintFD imp (FD n doc args ty f)
38+pprintFD ist (FD n doc args ty f)
39 = nest 4 (prettyName imp [] n <+> colon <+>
39 = nest 4 (prettyName imp [] n <+> colon <+>
40 pprintPTerm imp [] [ n | (n@(UN n'),_,_,_) <- args
40 pprintPTerm imp [] [ n | (n@(UN n'),_,_,_) <- args
41− , not (T.isPrefixOf (T.pack "__") n') ] ty <$>
41+ , not (T.isPrefixOf (T.pack "__") n') ] infixes ty <$>
42 renderDocstring doc <$>
42 renderDocstring doc <$>
43 maybe empty (\f -> text (show f) <> line) f <>
43 maybe empty (\f -> text (show f) <> line) f <>
44 let argshow = showArgs args [] in
44 let argshow = showArgs args [] in
@@ -46,21 +46,23 @@ pprintFD imp (FD n doc args ty f)
46 then nest 4 $ text "Arguments:" <$> vsep argshow
46 then nest 4 $ text "Arguments:" <$> vsep argshow
47 else empty)
47 else empty)
49+ where imp = opt_showimp (idris_options ist)
50+ infixes = idris_infixes ist
49− where showArgs ((n, ty, Exp {}, Just d):args) bnd
51+ showArgs ((n, ty, Exp {}, Just d):args) bnd
50 = bindingOf n False <+> colon <+>
52 = bindingOf n False <+> colon <+>
51− pprintPTerm imp bnd [] ty <>
53+ pprintPTerm imp bnd [] infixes ty <>
52 showDoc d <> line
54 showDoc d <> line
54 showArgs args ((n, False):bnd)
56 showArgs args ((n, False):bnd)
55 showArgs ((n, ty, Constraint {}, Just d):args) bnd
57 showArgs ((n, ty, Constraint {}, Just d):args) bnd
56 = text "Class constraint" <+>
58 = text "Class constraint" <+>
57− pprintPTerm imp bnd [] ty <> showDoc d <> line
59+ pprintPTerm imp bnd [] infixes ty <> showDoc d <> line
59 showArgs args ((n, True):bnd)
61 showArgs args ((n, True):bnd)
60 showArgs ((n, ty, Imp {}, Just d):args) bnd
62 showArgs ((n, ty, Imp {}, Just d):args) bnd
61 = text "(implicit)" <+>
63 = text "(implicit)" <+>
62 bindingOf n True <+> colon <+>
64 bindingOf n True <+> colon <+>
63− pprintPTerm imp bnd [] ty <>
65+ pprintPTerm imp bnd [] infixes ty <>
64 showDoc d <> line
66 showDoc d <> line
66 showArgs args ((n, True):bnd)
68 showArgs args ((n, True):bnd)
@@ -68,20 +70,20 @@ pprintFD imp (FD n doc args ty f)
68 showArgs [] _ = []
70 showArgs [] _ = []
71−pprintDocs :: Bool -> Docs -> Doc OutputAnnotation
73+pprintDocs :: IState -> Docs -> Doc OutputAnnotation
72−pprintDocs imp (FunDoc d) = pprintFD imp d
74+pprintDocs ist (FunDoc d) = pprintFD ist d
73−pprintDocs imp (DataDoc t args)
75+pprintDocs ist (DataDoc t args)
74− = text "Data type" <+> pprintFD imp t <$>
76+ = text "Data type" <+> pprintFD ist t <$>
75 nest 4 (text "Constructors:" <> line <>
77 nest 4 (text "Constructors:" <> line <>
76− vsep (map (pprintFD imp) args))
78+ vsep (map (pprintFD ist) args))
77−pprintDocs imp (ClassDoc n doc meths params instances)
79+pprintDocs ist (ClassDoc n doc meths params instances)
78 = nest 4 (text "Type class" <+> prettyName imp [] n <>
80 = nest 4 (text "Type class" <+> prettyName imp [] n <>
79 if nullDocstring doc then empty else line <> renderDocstring doc)
81 if nullDocstring doc then empty else line <> renderDocstring doc)
80 <> line <$>
82 <> line <$>
81 nest 4 (text "Parameters:" <$> prettyParameters)
83 nest 4 (text "Parameters:" <$> prettyParameters)
82 <> line <$>
84 <> line <$>
83 nest 4 (text "Methods:" <$>
85 nest 4 (text "Methods:" <$>
84− vsep (map (pprintFD imp) meths))
86+ vsep (map (pprintFD ist) meths))
86 nest 4 (text "Instances:" <$>
88 nest 4 (text "Instances:" <$>
87 vsep (if null instances' then [text "<no instances>"]
89 vsep (if null instances' then [text "<no instances>"]
@@ -94,9 +96,12 @@ pprintDocs imp (ClassDoc n doc meths params instances)
94 params' = zip pNames (repeat False)
96 params' = zip pNames (repeat False)
96 pNames = map fst params
98 pNames = map fst params
100+ imp = opt_showimp (idris_options ist)
101+ infixes = idris_infixes ist
98 dumpInstance :: PTerm -> Doc OutputAnnotation
103 dumpInstance :: PTerm -> Doc OutputAnnotation
99− dumpInstance = pprintPTerm imp params' []
104+ dumpInstance = pprintPTerm imp params' [] infixes
101 prettifySubclasses (PPi (Constraint _ _) _ tm _) = prettifySubclasses tm
106 prettifySubclasses (PPi (Constraint _ _) _ tm _) = prettifySubclasses tm
102 prettifySubclasses (PPi plcity nm t1 t2) = PPi plcity (safeHead nm pNames) (prettifySubclasses t1) (prettifySubclasses t2)
107 prettifySubclasses (PPi plcity nm t1 t2) = PPi plcity (safeHead nm pNames) (prettifySubclasses t1) (prettifySubclasses t2)