@@ -892,60 +892,412 @@ expandNS syn n = case syn_namespace syn of
892 xs -> sNS n xs
892 xs -> sNS n xs
895+-- For inferring types of things
897+bi = fileFC "builtin"
899+inferTy = sMN 0 "__Infer"
900+inferCon = sMN 0 "__infer"
901+inferDecl = PDatadecl inferTy
903+ [("", inferCon, PPi impl (sMN 0 "iType") PType (
904+ PPi expl (sMN 0 "ival") (PRef bi (sMN 0 "iType"))
905+ (PRef bi inferTy)), bi, [])]
908+infTerm t = PApp bi (PRef bi inferCon) [pimp (sMN 0 "iType") Placeholder True, pexp t]
909+infP = P (TCon 6 0) inferTy (TType (UVal 0))
911+getInferTerm, getInferType :: Term -> Term
912+getInferTerm (Bind n b sc) = Bind n b $ getInferTerm sc
913+getInferTerm (App (App _ _) tm) = tm
914+getInferTerm tm = tm -- error ("getInferTerm " ++ show tm)
916+getInferType (Bind n b sc) = Bind n b $ getInferType sc
917+getInferType (App (App _ ty) _) = ty
921+-- Handy primitives: Unit, False, Pair, MkPair, =, mkForeign, Elim type class
923+primNames = [unitTy, unitCon,
924+ falseTy, pairTy, pairCon,
925+ eqTy, eqCon, inferTy, inferCon]
927+unitTy = sMN 0 "__Unit"
928+unitCon = sMN 0 "__II"
929+unitDecl = PDatadecl unitTy PType
930+ [("", unitCon, PRef bi unitTy, bi, [])]
931+unitOpts = [DefaultEliminator]
933+falseTy = sMN 0 "__False"
934+falseDecl = PDatadecl falseTy PType []
937+pairTy = sMN 0 "__Pair"
938+pairCon = sMN 0 "__MkPair"
939+pairDecl = PDatadecl pairTy (piBind [(n "A", PType), (n "B", PType)] PType)
940+ [("", pairCon, PPi impl (n "A") PType (
941+ PPi impl (n "B") PType (
942+ PPi expl (n "a") (PRef bi (n "A")) (
943+ PPi expl (n "b") (PRef bi (n "B"))
944+ (PApp bi (PRef bi pairTy) [pexp (PRef bi (n "A")),
945+ pexp (PRef bi (n "B"))])))), bi, [])]
951+eqDecl = PDatadecl eqTy (piBind [(n "A", PType), (n "B", PType),
952+ (n "x", PRef bi (n "A")), (n "y", PRef bi (n "B"))]
954+ [("", eqCon, PPi impl (n "A") PType (
955+ PPi impl (n "x") (PRef bi (n "A"))
956+ (PApp bi (PRef bi eqTy) [pimp (n "A") Placeholder False,
957+ pimp (n "B") Placeholder False,
958+ pexp (PRef bi (n "x")),
959+ pexp (PRef bi (n "x"))])), bi, [])]
963+elimName = sUN "__Elim"
964+elimMethElimTy = sUN "__elimTy"
965+elimMethElim = sUN "elim"
966+elimDecl = PClass "Type class for eliminators" defaultSyntax bi [] elimName [(sUN "scrutineeType", PType)]
967+ [PTy "" defaultSyntax bi [TotalFn] elimMethElimTy PType,
968+ PTy "" defaultSyntax bi [TotalFn] elimMethElim (PRef bi elimMethElimTy)]
970+-- Defined in builtins.idr
971+sigmaTy = sUN "Exists"
972+existsCon = sUN "Ex_intro"
974+piBind :: [(Name, PTerm)] -> PTerm -> PTerm
975+piBind = piBindp expl
977+piBindp :: Plicity -> [(Name, PTerm)] -> PTerm -> PTerm
979+piBindp p ((n, ty):ns) t = PPi p n ty (piBindp p ns t)
895−--- Pretty printing declarations and terms
982+-- Pretty-printing declarations and terms
897instance Show PTerm where
984instance Show PTerm where
898− show tm = showImp Nothing False False tm
985+ showsPrec _ tm = (displayS . renderCompact . prettyImp False) tm
901instance Show PDecl where
987instance Show PDecl where
902− show d = showDeclImp False d
988+ showsPrec _ d = (displayS . renderCompact . showDeclImp False) d
904instance Show PClause where
990instance Show PClause where
905− show c = showCImp True c
991+ showsPrec _ c = (displayS . renderCompact . showCImp True) c
907instance Show PData where
993instance Show PData where
908− show d = showDImp False d
994+ showsPrec _ d = (displayS . renderCompact . showDImp False) d
996+instance Pretty PTerm OutputAnnotation where
997+ pretty = prettyImp False
999+-- | Colourise annotations according to an Idris state. It ignores the names
1000+-- in the annotation, as there's no good way to show extended information on a
1002+consoleDecorate :: IState -> OutputAnnotation -> String -> String
1003+consoleDecorate ist _ | not (idris_colourRepl ist) = id
1004+consoleDecorate ist AnnConstData = let theme = idris_colourTheme ist
1005+ in colouriseData theme
1006+consoleDecorate ist AnnConstType = let theme = idris_colourTheme ist
1007+ in colouriseType theme
1008+consoleDecorate ist (AnnBoundName _ True) = colouriseImplicit (idris_colourTheme ist)
1009+consoleDecorate ist (AnnBoundName _ False) = colouriseBound (idris_colourTheme ist)
1010+consoleDecorate ist (AnnName n _ _) = let ctxt = tt_ctxt ist
1011+ theme = idris_colourTheme ist
1013+ _ | isDConName n ctxt -> colouriseData theme
1014+ _ | isFnName n ctxt -> colouriseFun theme
1015+ _ | isTConName n ctxt -> colouriseType theme
1016+ _ | otherwise -> id -- don't colourise unknown names
1018+-- | Pretty-print a high-level closed Idris term
1019+prettyImp :: Bool -- ^^ whether to show implicits
1020+ -> PTerm -- ^^ the term to pretty-print
1021+ -> Doc OutputAnnotation
1022+prettyImp impl = pprintPTerm impl []
1024+-- | Pretty-print a high-level Idris term in some bindings context
1025+pprintPTerm :: Bool -- ^^ whether to show implicits
1026+ -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
1027+ -> PTerm -- ^^ the term to pretty-print
1028+ -> Doc OutputAnnotation
1029+pprintPTerm impl bnd = prettySe 10 bnd
1031+ prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
1032+ prettySe p bnd (PQuote r) =
1033+ if size r > breakingSize then
1034+ text "![" <> line <> pretty r <> text "]"
1036+ text "![" <> pretty r <> text "]"
1037+ prettySe p bnd (PPatvar fc n) = pretty n
1039+ | Just str <- slist p bnd e = str
1040+ | Just n <- snat p e = annotate AnnConstData (text (show n))
1041+ prettySe p bnd (PRef fc n) = prettyName impl bnd n
1042+ prettySe p bnd (PLam n ty sc) =
1044+ if size sc > breakingSize then
1045+ text "\\" <> bindingOf n False <+> text "=>" <> line <> prettySe 10 ((n, False):bnd) sc
1047+ text "\\" <> bindingOf n False <+> text "=>" <+> prettySe 10 ((n, False):bnd) sc
1048+ prettySe p bnd (PLet n ty v sc) =
1050+ if size sc > breakingSize then
1051+ text "let" <+> bindingOf n False <+> text "=" <+> prettySe 10 bnd v <+> text "in" <>
1052+ nest nestingSize (prettySe 10 ((n, False):bnd) sc)
1054+ text "let" <+> bindingOf n False <+> text "=" <+> prettySe 10 bnd v <+> text "in" <+>
1055+ prettySe 10 ((n, False):bnd) sc
1056+ prettySe p bnd (PPi (Exp l s _ _) n ty sc)
1057+ | n `elem` allNamesIn sc || impl =
1058+ let open = (if l then text "|" else empty) <> lparen in
1060+ if size sc > breakingSize then
1061+ enclose open rparen (bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1062+ st <> text "->" <> line <> prettySe 10 ((n, False):bnd) sc
1064+ enclose open rparen (bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1065+ st <> text "->" <+> prettySe 10 ((n, False):bnd) sc
1068+ if size sc > breakingSize then
1069+ prettySe 0 bnd ty <+> st <> text "->" <> line <> prettySe 10 ((n, False):bnd) sc
1071+ prettySe 0 bnd ty <+> st <> text "->" <+> prettySe 10 ((n, False):bnd) sc
1075+ Static -> text "[static]" <> space
1077+ prettySe p bnd (PPi (Imp l s _ _) n ty sc)
1079+ let open = if l then text "|" <> lbrace else lbrace in
1081+ if size sc > breakingSize then
1082+ open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1083+ st <> text "->" <+> prettySe 10 ((n, True):bnd) sc
1085+ open <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1086+ st <> text "->" <+> prettySe 10 ((n, True):bnd) sc
1087+ | otherwise = prettySe 10 ((n, True):bnd) sc
1091+ Static -> text "[static]" <> space
1093+ prettySe p bnd (PPi (Constraint _ _ _) n ty sc) =
1095+ if size sc > breakingSize then
1096+ prettySe 10 bnd ty <+> text "=>" <+> prettySe 10 ((n, True):bnd) sc
1098+ prettySe 10 bnd ty <+> text "=>" <> line <> prettySe 10 ((n, True):bnd) sc
1099+ prettySe p bnd (PPi (TacImp _ _ s _) n ty sc) =
1101+ if size sc > breakingSize then
1102+ lbrace <> text "tacimp" <+> bindingOf n True <+> colon <+> prettySe 10 bnd ty <>
1103+ rbrace <+> text "->" <> line <> prettySe 10 ((n, True):bnd) sc
1105+ lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 bnd ty <>
1106+ rbrace <+> text "->" <+> prettySe 10 ((n, True):bnd) sc
1107+ prettySe p bnd (PApp _ (PRef _ f) [])
1108+ | not impl = prettyName impl bnd f
1109+ prettySe p bnd (PAppBind _ (PRef _ f) [])
1110+ | not impl = text "!" <> prettyName impl bnd f
1111+ prettySe p bnd (PApp _ (PRef _ op@(UN nm)) args)
1112+ | not (tnull nm) &&
1113+ length (getExps args) == 2 && (not impl) && (not $ isAlpha (thead nm)) =
1114+ let [l, r] = getExps args in
1116+ if size r > breakingSize then
1117+ prettySe 1 bnd l <+> prettyName impl bnd op <> line <> prettySe 0 bnd r
1119+ prettySe 1 bnd l <+> prettyName impl bnd op <+> prettySe 0 bnd r
1120+ prettySe p bnd (PApp _ f as) =
1121+ let args = getExps as
1122+ fp = prettySe 1 bnd f
1126+ then fp : map (prettyArgS bnd) as
1127+ else fp : map (prettyArgSe bnd) args)
1128+ prettySe p bnd (PCase _ scr opts) =
1129+ text "case" <+> prettySe 10 bnd scr <+> text "of" <> prettyBody
1131+ prettyBody = foldr (<>) empty $ intersperse (text "|") $ map sc opts
1133+ sc (l, r) = nest nestingSize $ prettySe 10 bnd l <+> text "=>" <+> prettySe 10 bnd r
1134+ prettySe p bnd (PHidden tm) = text "." <> prettySe 0 bnd tm
1135+ prettySe p bnd (PRefl _ _) = annotate (AnnName eqCon Nothing Nothing) $ text "refl"
1136+ prettySe p bnd (PResolveTC _) = text "resolvetc"
1137+ prettySe p bnd (PTrue _) = annotate (AnnName unitTy Nothing Nothing) $ text "()"
1138+ prettySe p bnd (PFalse _) = annotate (AnnName falseTy Nothing Nothing) $ text "_|_"
1139+ prettySe p bnd (PEq _ l r) =
1141+ if size r > breakingSize then
1142+ prettySe 10 bnd l <+> eq <$> nest nestingSize (prettySe 10 bnd r)
1144+ prettySe 10 bnd l <+> eq <+> prettySe 10 bnd r
1145+ where eq = annotate (AnnName eqTy Nothing Nothing) (text "=")
1146+ prettySe p bnd (PRewrite _ l r _) =
1148+ if size r > breakingSize then
1149+ text "rewrite" <+> prettySe 10 bnd l <+> text "in" <> nest nestingSize (prettySe 10 bnd r)
1151+ text "rewrite" <+> prettySe 10 bnd l <+> text "in" <+> prettySe 10 bnd r
1152+ prettySe p bnd (PTyped l r) =
1153+ lparen <> prettySe 10 bnd l <+> colon <+> prettySe 10 bnd r <> rparen
1154+ prettySe p bnd (PPair _ l r) =
1155+ if size r > breakingSize then
1156+ lparen <> prettySe 10 bnd l <> text "," <>
1157+ line <> prettySe 10 bnd r <> rparen
1159+ lparen <> prettySe 10 bnd l <> text "," <+> prettySe 10 bnd r <> rparen
1160+ prettySe p bnd (PDPair _ l t r) =
1161+ if size r > breakingSize then
1162+ lparen <> prettySe 10 bnd l <+> text "**" <>
1163+ line <> prettySe 10 bnd r <> rparen
1165+ lparen <> prettySe 10 bnd l <+> text "**" <+> prettySe 10 bnd r <> rparen
1166+ prettySe p bnd (PAlternative a as) =
1167+ lparen <> text "|" <> prettyAs <> text "|" <> rparen
1170+ foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10 bnd) as
1171+ prettySe p bnd PType = text "Type"
1172+ prettySe p bnd (PConstant c) = annotate (annot c) (text (show c))
1173+ where annot (AType _) = AnnConstType
1174+ annot StrType = AnnConstType
1175+ annot PtrType = AnnConstType
1176+ annot VoidType = AnnConstType
1177+ annot _ = AnnConstData
1178+ -- XXX: add pretty for tactics
1179+ prettySe p bnd (PProof ts) =
1180+ text "proof" <+> lbrace <> nest nestingSize (text . show $ ts) <> rbrace
1181+ prettySe p bnd (PTactics ts) =
1182+ text "tactics" <+> lbrace <> nest nestingSize (text . show $ ts) <> rbrace
1183+ prettySe p bnd (PMetavar n) = text "?" <> pretty n
1184+ prettySe p bnd (PReturn f) = text "return"
1185+ prettySe p bnd PImpossible = text "impossible"
1186+ prettySe p bnd Placeholder = text "_"
1187+ prettySe p bnd (PDoBlock _) = text "do block pretty not implemented"
1188+ prettySe p bnd (PElabError s) = pretty s
1190+ prettySe p bnd _ = text "test"
1192+ prettyArgS bnd (PImp _ _ _ n tm _) = prettyArgSi bnd (n, tm)
1193+ prettyArgS bnd (PExp _ _ tm _) = prettyArgSe bnd tm
1194+ prettyArgS bnd (PConstraint _ _ tm _) = prettyArgSc bnd tm
1195+ prettyArgS bnd (PTacImplicit _ _ n _ tm _) = prettyArgSti bnd (n, tm)
1197+ prettyArgSe bnd arg = prettySe 0 bnd arg
1198+ prettyArgSi bnd (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1199+ prettyArgSc bnd val = lbrace <> lbrace <> prettySe 10 bnd val <> rbrace <> rbrace
1200+ prettyArgSti bnd (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
910−showDecls :: Bool -> [PDecl] -> String
912−showDecls i (d:ds) = showDeclImp i d ++ "\n" ++ showDecls i ds
914−showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
1203+ slist' p bnd (PApp _ (PRef _ nil) _)
915−showDeclImp i (PTy _ _ _ _ n t) = "tydecl " ++ showCG n ++ " : " ++ showImp Nothing i False t
1204+ | not impl && nsroot nil == sUN "Nil" = Just []
916−showDeclImp i (PClauses _ _ n cs) = "pat " ++ showCG n ++ "\t" ++ showSep "\n\t" (map (showCImp i) cs)
1205+ slist' p bnd (PApp _ (PRef _ cons) args)
917−showDeclImp _ (PData _ _ _ _ d) = showDImp True d
1206+ | nsroot cons == sUN "::",
918−showDeclImp i (PParams _ ns ps) = "params {" ++ show ns ++ "\n" ++ showDecls i ps ++ "}\n"
1207+ (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
919−showDeclImp i (PNamespace n ps) = "namespace {" ++ n ++ "\n" ++ showDecls i ps ++ "}\n"
1208+ all isImp imps,
920−showDeclImp _ (PSyntax _ syn) = "syntax " ++ show syn
1209+ Just tl' <- slist' p bnd tl
921−showDeclImp i (PClass _ _ _ cs n ps ds)
1210+ = Just (hd:tl')
922− = "class " ++ show cs ++ " " ++ show n ++ " " ++ show ps ++ "\n" ++ showDecls i ds
1211+ where
923−showDeclImp i (PInstance _ _ cs n _ t _ ds)
1212+ isImp (PImp {}) = True
924− = "instance " ++ show cs ++ " " ++ show n ++ " " ++ show t ++ "\n" ++ showDecls i ds
1213+ isImp _ = False
925−showDeclImp _ _ = "..."
1214+ slist' _ _ _ = Nothing
926−-- showDeclImp (PImport i) = "import " ++ i
1215+
1216+ slist p bnd e | Just es <- slist' p bnd e = Just $
1217+ case es of [] -> annotate AnnConstData $ text "[]"
1218+ [x] -> enclose left
1221+ xs -> (enclose left right . hsep . punctuate comma . map (prettySe p bnd)) xs
1222+ where left = (annotate AnnConstData (text "["))
1223+ right = (annotate AnnConstData (text "]"))
1224+ comma = (annotate AnnConstData (text ","))
1225+ slist _ _ _ = Nothing
1227+ natns = "Prelude.Nat."
1230+ | show z == (natns++"Z") || show z == "Z" = Just 0
1231+ snat p (PApp _ s [PExp {getTm=n}])
1232+ | show s == (natns++"S") || show s == "S",
1233+ Just n' <- snat p n
1237+ bracket outer inner doc
1238+ | inner > outer = lparen <> doc <> rparen
1241+-- | Pretty-printer helper for the binding site of a name
1242+bindingOf :: Name -- ^^ the bound name
1243+ -> Bool -- ^^ whether the name is implicit
1244+ -> Doc OutputAnnotation
1245+bindingOf n imp = annotate (AnnBoundName n imp) (text (show n))
1247+-- | Pretty-printer helper for names that attaches the correct annotations
1248+prettyName :: Bool -- ^^ whether to show namespaces
1249+ -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1250+ -> Name -- ^^ the name to pprint
1251+ -> Doc OutputAnnotation
1252+prettyName showNS bnd n | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) (text (strName n))
1253+ | otherwise = annotate (AnnName n Nothing Nothing) (text (strName n))
1254+ where strName (UN n) = T.unpack n
1255+ strName (NS n ns) | showNS = (concatMap (++ ".") . map T.unpack . reverse) ns ++ strName n
1256+ | otherwise = strName n
1257+ strName (MN i s) = T.unpack s
1258+ strName other = show other
929−showCImp :: Bool -> PClause -> String
1261+showCImp :: Bool -> PClause -> Doc OutputAnnotation
930showCImp impl (PClause _ n l ws r w)
1262showCImp impl (PClause _ n l ws r w)
931− = showImp Nothing impl False l ++ showWs ws ++ " = " ++ showImp Nothing impl False r
1263+ = prettyImp impl l <+> showWs ws <+> text "=" <+> prettyImp impl r
932− ++ " where " ++ show w
1264+ <+> text "where" <+> text (show w)
934− showWs [] = ""
1266+ showWs [] = empty
935− showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
1267+ showWs (x : xs) = text "|" <+> prettyImp impl x <+> showWs xs
936showCImp impl (PWith _ n l ws r w)
1268showCImp impl (PWith _ n l ws r w)
937− = showImp Nothing impl False l ++ showWs ws ++ " with " ++ showImp Nothing impl False r
1269+ = prettyImp impl l <+> showWs ws <+> text "with" <+> prettyImp impl r
938− ++ " { " ++ show w ++ " } "
1270+ <+> braces (text (show w))
940− showWs [] = ""
1272+ showWs [] = empty
941− showWs (x : xs) = " | " ++ showImp Nothing impl False x ++ showWs xs
1273+ showWs (x : xs) = text "|" <+> prettyImp impl x <+> showWs xs
944−showDImp :: Bool -> PData -> String
1276+showDImp :: Bool -> PData -> Doc OutputAnnotation
945showDImp impl (PDatadecl n ty cons)
1277showDImp impl (PDatadecl n ty cons)
946− = "data " ++ show n ++ " : " ++ showImp Nothing impl False ty ++ " where\n\t"
1278+ = text "data" <+> text (show n) <+> colon <+> prettyImp impl ty <+> text "where" <$>
947− ++ showSep "\n\t| "
1279+ (indent 2 $ vsep (map (\ (_, n, t, _, _) -> pipe <+> prettyName False [] n <+> colon <+> prettyImp impl t) cons))
948− (map (\ (_, n, t, _, _) -> show n ++ " : " ++ showImp Nothing impl False t) cons)
1280+
1281+showDecls :: Bool -> [PDecl] -> Doc OutputAnnotation
1282+showDecls i ds = vsep (map (showDeclImp i) ds)
1284+showDeclImp _ (PFix _ f ops) = text (show f) <+> cat (punctuate (text ",") (map text ops))
1285+showDeclImp i (PTy _ _ _ _ n t) = text "tydecl" <+> text (showCG n) <+> colon <+> prettyImp i t
1286+showDeclImp i (PClauses _ _ n cs) = text "pat" <+> text (showCG n) <+> text "\t" <+>
1287+ indent 2 (vsep (map (showCImp i) cs))
1288+showDeclImp _ (PData _ _ _ _ d) = showDImp True d
1289+showDeclImp i (PParams _ ns ps) = text "params" <+> braces (text (show ns) <> line <> showDecls i ps <> line)
1290+showDeclImp i (PNamespace n ps) = text "namespace" <+> text n <> braces (line <> showDecls i ps <> line)
1291+showDeclImp _ (PSyntax _ syn) = text "syntax" <+> text (show syn)
1292+showDeclImp i (PClass _ _ _ cs n ps ds)
1293+ = text "class" <+> text (show cs) <+> text (show n) <+> text (show ps) <> line <> showDecls i ds
1294+showDeclImp i (PInstance _ _ cs n _ t _ ds)
1295+ = text "instance" <+> text (show cs) <+> text (show n) <+> prettyImp i t <> line <> showDecls i ds
1296+showDeclImp _ _ = text "..."
1297+-- showDeclImp (PImport i) = "import " ++ i
1299+instance Show (Doc OutputAnnotation) where
1300+ show = flip (displayS . renderCompact) ""
950getImps :: [PArg] -> [(Name, PTerm)]
1302getImps :: [PArg] -> [(Name, PTerm)]
951getImps [] = []
1303getImps [] = []
@@ -995,168 +1347,14 @@ showName ist bnd impl colour n = case ist of
995 -- (like error messages). Thus, unknown vars are colourised as implicits.
1347 -- (like error messages). Thus, unknown vars are colourised as implicits.
996 | otherwise -> colouriseImplicit t name
1348 | otherwise -> colouriseImplicit t name
999−showImp :: Maybe IState -- ^^ the Idris state, for information about identifiers and colours
1350+showTm :: IState -- ^^ the Idris state, for information about identifiers and colours
1000− -> Bool -- ^^ whether to show implicits
1001− -> Bool -- ^^ whether to colourise
1002− -> PTerm -- ^^ the term to show
1351+ -> PTerm -- ^^ the term to show
1003− -> String
1352+ -> String
1004−showImp ist impl colour tm = se 10 [] tm where
1353+showTm ist = displayDecorated (consoleDecorate ist) . renderCompact . prettyImp (opt_showimp (idris_options ist))
1005− perhapsColourise :: (ColourTheme -> String -> String) -> String -> String
1006− perhapsColourise col str = case ist of
1007− Just i -> if colour then col (idris_colourTheme i) str else str
1010− se :: Int -> [(Name, Bool)] -> PTerm -> String
1011− se p bnd (PQuote r) = "![" ++ show r ++ "]"
1012− se p bnd (PPatvar fc n) = if impl then show n ++ "[p]" else show n
1013− se p bnd (PInferRef fc n) = "!" ++ show n -- ++ "[" ++ show fc ++ "]"
1015− | Just str <- slist p bnd e = str
1016− | Just num <- snat p e = perhapsColourise colouriseData (show num)
1017− se p bnd (PRef fc n) = showName ist bnd impl colour n
1018− se p bnd (PLam n ty sc) = bracket p 2 $ "\\ " ++ perhapsColourise colouriseBound (show n) ++
1019− (if impl then " : " ++ se 10 bnd ty else "") ++ " => "
1020− ++ se 10 ((n, False):bnd) sc
1021− se p bnd (PLet n ty v sc) = bracket p 2 $ "let " ++ perhapsColourise colouriseBound (show n) ++
1022− " = " ++ se 10 bnd v ++
1023− " in " ++ se 10 ((n, False):bnd) sc
1024− se p bnd (PPi (Exp l s _ param) n ty sc)
1025− | n `elem` allNamesIn sc || impl
1027− (if l then "|(" else "(") ++
1028− perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1030− (if (impl && param) then "P" else "") ++
1032− "-> " ++ se 10 ((n, False):bnd) sc
1033− | otherwise = bracket p 2 $ se 0 bnd ty ++ " " ++ st ++ "-> " ++ se 10 bnd sc
1034− where st = case s of
1035− Static -> "[static] "
1037− se p bnd (PPi (Imp l s _ _) n ty sc)
1038− | impl = bracket p 2 $ (if l then "|{" else "{") ++
1039− perhapsColourise colouriseBound (show n) ++ " : " ++ se 10 bnd ty ++
1040− "} " ++ st ++ "-> " ++ se 10 ((n, True):bnd) sc
1041− | otherwise = se 10 ((n, True):bnd) sc
1042− where st = case s of
1043− Static -> "[static] "
1045− se p bnd (PPi (Constraint _ _ _) n ty sc)
1046− = bracket p 2 $ se 10 bnd ty ++ " => " ++ se 10 bnd sc
1047− se p bnd (PPi (TacImp _ _ s _) n ty sc)
1049− "{tacimp " ++ (perhapsColourise colouriseBound (show n)) ++ " : " ++ se 10 bnd ty ++ "} -> " ++
1050− se 10 ((n, False):bnd) sc
1051− se p bnd (PMatchApp _ f) = "match " ++ show f
1052− se p bnd (PApp _ hd@(PRef _ f) [])
1053− | not impl = se p bnd hd
1054− se p bnd (PAppBind _ hd@(PRef _ f) [])
1055− | not impl = "!" ++ se p bnd hd
1056− se p bnd (PApp _ op@(PRef _ (UN nm)) args)
1057− | not (tnull nm) &&
1058− length (getExps args) == 2 && not impl && not (isAlpha (thead nm))
1059− = let [l, r] = getExps args in
1060− bracket p 1 $ se 1 bnd l ++ " " ++ se p bnd op ++ " " ++ se 0 bnd r
1061− se p bnd (PApp _ f as)
1062− = -- let args = getExps as in
1063− bracket p 1 $ se 1 bnd f ++
1064− if impl then concatMap (sArg bnd) as
1065− else concatMap (suiArg impl bnd) as
1066− se p bnd (PAppBind _ f as)
1067− = let args = getExps as in
1068− "!" ++ (bracket p 1 $ se 1 bnd f ++ if impl then concatMap (sArg bnd) as
1069− else concatMap (seArg bnd) args)
1070− se p bnd (PCase _ scr opts) = "case " ++ se 10 bnd scr ++ " of " ++ showSep " | " (map sc opts)
1071− where sc (l, r) = se 10 bnd l ++ " => " ++ se 10 bnd r
1072− se p bnd (PHidden tm) = "." ++ se 0 bnd tm
1073− se p bnd (PRefl _ t)
1074− | not impl = perhapsColourise colouriseData "refl"
1075− | otherwise = perhapsColourise colouriseData $ "refl {" ++ se 10 bnd t ++ "}"
1076− se p bnd (PResolveTC _) = "resolvetc"
1077− se p bnd (PTrue _) = perhapsColourise colouriseType "()"
1078− se p bnd (PFalse _) = perhapsColourise colouriseType "_|_"
1079− se p bnd (PEq _ l r) = bracket p 2 $ se 10 bnd l ++ perhapsColourise colouriseType " = " ++ se 10 bnd r
1080− se p bnd (PRewrite _ l r _) = bracket p 2 $ "rewrite " ++ se 10 bnd l ++ " in " ++ se 10 bnd r
1081− se p bnd (PTyped l r) = "(" ++ se 10 bnd l ++ " : " ++ se 10 bnd r ++ ")"
1082− se p bnd (PPair _ l r) = "(" ++ se 10 bnd l ++ ", " ++ se 10 bnd r ++ ")"
1083− se p bnd (PDPair _ l t r) = "(" ++ se 10 bnd l ++ " ** " ++ se 10 bnd r ++ ")"
1084− se p bnd (PAlternative a as) = "(|" ++ showSep " , " (map (se 10 bnd) as) ++ "|)"
1085− se p bnd PType = perhapsColourise colouriseType "Type"
1086− se p bnd (PConstant c) = perhapsColourise (cfun c) (show c)
1087− where cfun (AType _) = colouriseType
1088− cfun StrType = colouriseType
1089− cfun PtrType = colouriseType
1090− cfun VoidType = colouriseType
1091− cfun _ = colouriseData
1092− se p bnd (PProof ts) = "proof { " ++ show ts ++ "}"
1093− se p bnd (PTactics ts) = "tactics { " ++ show ts ++ "}"
1094− se p bnd (PMetavar n) = "?" ++ show n
1095− se p bnd (PReturn f) = "return"
1096− se p bnd PImpossible = "impossible"
1097− se p bnd Placeholder = "_"
1098− se p bnd (PDoBlock _) = "do block show not implemented"
1099− se p bnd (PElabError s) = show s
1100− se p bnd (PCoerced t) = se p bnd t
1101− se p bnd (PUnifyLog t) = "%unifyLog " ++ se p bnd t
1102− se p bnd (PDisamb ns t) = "%disamb " ++ show ns ++ se p bnd t
1103− se p bnd (PNoImplicits t) = "%noimplicit " ++ se p bnd t
1104−-- se p bnd x = "Not implemented"
1106− slist' p bnd (PApp _ (PRef _ nil) _)
1107− | not impl && nsroot nil == sUN "Nil" = Just []
1108− slist' p bnd (PApp _ (PRef _ cons) args)
1109− | nsroot cons == sUN "::",
1110− (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
1112− Just tl' <- slist' p bnd tl
1115− isImp (PImp {}) = True
1117− slist' _ _ _ = Nothing
1119− slist p bnd e | Just es <- slist' p bnd e = Just $
1120− case es of [] -> "[]"
1121− [x] -> "[" ++ se p bnd x ++ "]"
1122− xs -> "[" ++ intercalate "," (map (se p bnd ) xs) ++ "]"
1123− slist _ _ _ = Nothing
1125− -- since Prelude is always imported, S & Z are unqualified iff they're the
1128− | show o == (natns++"Z") || show o == "Z" = Just 0
1129− snat p (PApp _ s [PExp {getTm=n}])
1130− | show s == (natns++"S") || show s == "S",
1131− Just n' <- snat p n
1135− natns = "Prelude.Nat."
1137− sArg bnd (PImp _ _ _ n tm _) = siArg bnd (n, tm)
1355+-- | Show a term with implicits, no colours
1138− sArg bnd (PExp _ _ tm _) = seArg bnd tm
1356+showTmImpls :: PTerm -> String
1139− sArg bnd (PConstraint _ _ tm _) = scArg bnd tm
1357+showTmImpls = flip (displayS . renderCompact . prettyImp True) ""
1140− sArg bnd (PTacImplicit _ _ n _ tm _) = stiArg bnd (n, tm)
1142− -- show argument, implicits given by the user also shown
1143− suiArg impl bnd (PImp _ mi _ n tm _)
1144− | impl || not mi = siArg bnd (n, tm)
1145− suiArg impl bnd (PExp _ _ tm _) = seArg bnd tm
1146− suiArg impl bnd _ = ""
1148− seArg bnd arg = " " ++ se 0 bnd arg
1149− siArg bnd (n, val) =
1151− val' = se 10 bnd val in
1153− then " {" ++ n' ++ "}"
1154− else " {" ++ n' ++ " = " ++ val' ++ "}"
1155− scArg bnd val = " {{" ++ se 10 bnd val ++ "}}"
1156− stiArg bnd (n, val) = " {auto " ++ show n ++ " = " ++ se 10 bnd val ++ "}"
1158− bracket outer inner str | inner > outer = "(" ++ str ++ ")"
1162instance Sized PTerm where
1360instance Sized PTerm where