@@ -1,5 +1,5 @@
1{-# LANGUAGE PatternGuards #-}
1{-# LANGUAGE PatternGuards #-}
2−module Idris.Delaborate (bugaddr, delab, delab', delabMV, delabTy, delabTy', fancifyAnnots, pprintErr) where
2+module Idris.Delaborate (bugaddr, delab, delab', delabMV, delabTy, delabTy', fancifyAnnots, pprintDelab, pprintDelabTy, pprintErr) where
4-- Convert core TT back into high level syntax, primarily for display
4-- Convert core TT back into high level syntax, primarily for display
5-- purposes.
5-- purposes.
@@ -135,6 +135,20 @@ errorIndent = 8
135indented :: Doc a -> Doc a
135indented :: Doc a -> Doc a
136indented = nest errorIndent . (line <>)
136indented = nest errorIndent . (line <>)
138+-- | Pretty-print a core term using delaboration
139+pprintDelab :: IState -> Term -> Doc OutputAnnotation
140+pprintDelab ist tm = annotate (AnnTerm [] tm)
141+ (prettyIst ist (delab ist tm))
143+-- | Pretty-print the type of some name
144+pprintDelabTy :: IState -> Name -> Doc OutputAnnotation
146+ = case lookupTy n (tt_ctxt i) of
147+ (ty:_) -> annotate (AnnTerm [] ty) . prettyIst i $
148+ case lookupCtxt n (idris_implicits i) of
149+ (imps:_) -> delabTy' i imps ty False False
150+ _ -> delabTy' i [] ty False False
138pprintTerm :: IState -> PTerm -> Doc OutputAnnotation
152pprintTerm :: IState -> PTerm -> Doc OutputAnnotation
139pprintTerm ist = pprintTerm' ist []
153pprintTerm ist = pprintTerm' ist []
@@ -151,8 +165,8 @@ pprintErr' i (InternalMsg s) =
151 text ("Please consider reporting at " ++ bugaddr)
165 text ("Please consider reporting at " ++ bugaddr)
153pprintErr' i (CantUnify _ x y e sc s) =
167pprintErr' i (CantUnify _ x y e sc s) =
154− text "Can't unify" <> indented (pprintTerm' i (map (\ (n, b) -> (n, False)) sc) (delab i x)) <$>
168+ text "Can't unify" <> indented (annTm x (pprintTerm' i (map (\ (n, b) -> (n, False)) sc) (delab i x))) <$>
155− text "with" <> indented (pprintTerm' i (map (\ (n, b) -> (n, False)) sc) (delab i y)) <>
169+ text "with" <> indented (annTm y (pprintTerm' i (map (\ (n, b) -> (n, False)) sc) (delab i y))) <>
156 case e of
170 case e of
157 Msg "" -> empty
171 Msg "" -> empty
158 _ -> line <> line <> text "Specifically:" <>
172 _ -> line <> line <> text "Specifically:" <>
@@ -160,46 +174,46 @@ pprintErr' i (CantUnify _ x y e sc s) =
160 if (opt_errContext (idris_options i)) then showSc i sc else empty
174 if (opt_errContext (idris_options i)) then showSc i sc else empty
161pprintErr' i (CantConvert x y env) =
175pprintErr' i (CantConvert x y env) =
162 text "Can't convert" <>
176 text "Can't convert" <>
163− indented (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i x)) <$>
177+ indented (annTm x (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i x))) <$>
164 text "with" <>
178 text "with" <>
165− indented (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i y)) <>
179+ indented (annTm y (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i y))) <>
166 if (opt_errContext (idris_options i)) then line <> showSc i env else empty
180 if (opt_errContext (idris_options i)) then line <> showSc i env else empty
167pprintErr' i (CantSolveGoal x env) =
181pprintErr' i (CantSolveGoal x env) =
168 text "Can't solve goal " <>
182 text "Can't solve goal " <>
169− indented (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i x)) <>
183+ indented (annTm x (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i x))) <>
170 if (opt_errContext (idris_options i)) then line <> showSc i env else empty
184 if (opt_errContext (idris_options i)) then line <> showSc i env else empty
171pprintErr' i (UnifyScope n out tm env) =
185pprintErr' i (UnifyScope n out tm env) =
172 text "Can't unify" <> indented (annName n) <+>
186 text "Can't unify" <> indented (annName n) <+>
173− text "with" <> indented (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i tm)) <+>
187+ text "with" <> indented (annTm tm (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i tm))) <+>
174− text "as" <> indented (annName out) <> text "is not in scope" <>
188+ text "as" <> indented (annName out) <> text "is not in scope" <>
175 if (opt_errContext (idris_options i)) then line <> showSc i env else empty
189 if (opt_errContext (idris_options i)) then line <> showSc i env else empty
176pprintErr' i (CantInferType t) = text "Can't infer type for" <+> text t
190pprintErr' i (CantInferType t) = text "Can't infer type for" <+> text t
177pprintErr' i (NonFunctionType f ty) =
191pprintErr' i (NonFunctionType f ty) =
178− pprintTerm i (delab i f) <+>
192+ annTm f (pprintTerm i (delab i f)) <+>
179 text "does not have a function type" <+>
193 text "does not have a function type" <+>
180 parens (pprintTerm i (delab i ty))
194 parens (pprintTerm i (delab i ty))
181pprintErr' i (NotEquality tm ty) =
195pprintErr' i (NotEquality tm ty) =
182− pprintTerm i (delab i tm) <+>
196+ annTm tm (pprintTerm i (delab i tm)) <+>
183 text "does not have an equality type" <+>
197 text "does not have an equality type" <+>
184− parens (pprintTerm i (delab i ty))
198+ annTm ty (parens (pprintTerm i (delab i ty)))
185pprintErr' i (TooManyArguments f) = text "Too many arguments for" <+> annName f
199pprintErr' i (TooManyArguments f) = text "Too many arguments for" <+> annName f
186pprintErr' i (CantIntroduce ty) =
200pprintErr' i (CantIntroduce ty) =
187− text "Can't use lambda here: type is" <+> pprintTerm i (delab i ty)
201+ text "Can't use lambda here: type is" <+> annTm ty (pprintTerm i (delab i ty))
188pprintErr' i (InfiniteUnify x tm env) =
202pprintErr' i (InfiniteUnify x tm env) =
189 text "Unifying" <+> annName' x (showbasic x) <+> text "and" <+>
203 text "Unifying" <+> annName' x (showbasic x) <+> text "and" <+>
190− pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i tm) <+>
204+ annTm tm (pprintTerm' i (map (\ (n, b) -> (n, False)) env) (delab i tm)) <+>
191 text "would lead to infinite value" <>
205 text "would lead to infinite value" <>
192 if (opt_errContext (idris_options i)) then line <> showSc i env else empty
206 if (opt_errContext (idris_options i)) then line <> showSc i env else empty
193pprintErr' i (NotInjective p x y) =
207pprintErr' i (NotInjective p x y) =
194− text "Can't verify injectivity of" <+> pprintTerm i (delab i p) <+>
208+ text "Can't verify injectivity of" <+> annTm p (pprintTerm i (delab i p)) <+>
195− text " when unifying" <+> pprintTerm i (delab i x) <+> text "and" <+>
209+ text " when unifying" <+> annTm x (pprintTerm i (delab i x)) <+> text "and" <+>
196− pprintTerm i (delab i y)
210+ annTm y (pprintTerm i (delab i y))
197pprintErr' i (CantResolve c) = text "Can't resolve type class" <+> pprintTerm i (delab i c)
211pprintErr' i (CantResolve c) = text "Can't resolve type class" <+> pprintTerm i (delab i c)
198pprintErr' i (CantResolveAlts as) = text "Can't disambiguate name:" <+>
212pprintErr' i (CantResolveAlts as) = text "Can't disambiguate name:" <+>
199 align (cat (punctuate (comma <> space) (map (fmap (fancifyAnnots i) . annName) as)))
213 align (cat (punctuate (comma <> space) (map (fmap (fancifyAnnots i) . annName) as)))
200pprintErr' i (NoTypeDecl n) = text "No type declaration for" <+> annName n
214pprintErr' i (NoTypeDecl n) = text "No type declaration for" <+> annName n
201pprintErr' i (NoSuchVariable n) = text "No such variable" <+> annName n
215pprintErr' i (NoSuchVariable n) = text "No such variable" <+> annName n
202−pprintErr' i (IncompleteTerm t) = text "Incomplete term" <+> pprintTerm i (delab i t)
216+pprintErr' i (IncompleteTerm t) = text "Incomplete term" <+> annTm t (pprintTerm i (delab i t))
203pprintErr' i UniverseError = text "Universe inconsistency"
217pprintErr' i UniverseError = text "Universe inconsistency"
204pprintErr' i ProgramLineComment = text "Program line next to comment"
218pprintErr' i ProgramLineComment = text "Program line next to comment"
205pprintErr' i (Inaccessible n) = annName n <+> text "is not an accessible pattern variable"
219pprintErr' i (Inaccessible n) = annName n <+> text "is not an accessible pattern variable"
@@ -208,7 +222,7 @@ pprintErr' i (NonCollapsiblePostulate n) = text "The return type of postulate" <
208pprintErr' i (AlreadyDefined n) = annName n<+>
222pprintErr' i (AlreadyDefined n) = annName n<+>
209 text "is already defined"
223 text "is already defined"
210pprintErr' i (ProofSearchFail e) = pprintErr' i e
224pprintErr' i (ProofSearchFail e) = pprintErr' i e
211−pprintErr' i (NoRewriting tm) = text "rewrite did not change type" <+> pprintTerm i (delab i tm)
225+pprintErr' i (NoRewriting tm) = text "rewrite did not change type" <+> annTm tm (pprintTerm i (delab i tm))
212pprintErr' i (At f e) = annotate (AnnFC f) (text (show f)) <> colon <> pprintErr' i e
226pprintErr' i (At f e) = annotate (AnnFC f) (text (show f)) <> colon <> pprintErr' i e
213pprintErr' i (Elaborating s n e) = text "When elaborating" <+> text s <>
227pprintErr' i (Elaborating s n e) = text "When elaborating" <+> text s <>
214 annName' n (showqual i n) <> colon <$>
228 annName' n (showqual i n) <> colon <$>
@@ -259,6 +273,9 @@ annName n = annName' n (showbasic n)
259annName' :: Name -> String -> Doc OutputAnnotation
273annName' :: Name -> String -> Doc OutputAnnotation
260annName' n str = annotate (AnnName n Nothing Nothing Nothing) (text str)
274annName' n str = annotate (AnnName n Nothing Nothing Nothing) (text str)
276+annTm :: Term -> Doc OutputAnnotation -> Doc OutputAnnotation
277+annTm tm = annotate (AnnTerm [] tm)
262fancifyAnnots :: IState -> OutputAnnotation -> OutputAnnotation
279fancifyAnnots :: IState -> OutputAnnotation -> OutputAnnotation
263fancifyAnnots ist annot@(AnnName n _ _ _) =
280fancifyAnnots ist annot@(AnnName n _ _ _) =
264 do let ctxt = tt_ctxt ist
281 do let ctxt = tt_ctxt ist