@@ -95,6 +95,24 @@ defaultOpts = IOption { opt_logLevel = 0
95 , opt_autoSolve = True
95 , opt_autoSolve = True
98+data PPOption = PPOption {
99+ ppopt_impl :: Bool -- ^^ whether to show implicits
102+-- | Pretty printing options with default verbosity.
103+defaultPPOption :: PPOption
104+defaultPPOption = PPOption { ppopt_impl = False }
106+-- | Pretty printing options with the most verbosity.
107+verbosePPOption :: PPOption
108+verbosePPOption = PPOption { ppopt_impl = True }
110+-- | Get pretty printing options from the big options record.
111+ppOption :: IOption -> PPOption
112+ppOption opt = PPOption {
113+ ppopt_impl = opt_showimp opt
98data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord)
116data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord)
100-- | The output mode in use
118-- | The output mode in use
@@ -1089,19 +1107,19 @@ piBindp p ((n, ty):ns) t = PPi p n ty (piBindp p ns t)
1089-- could interfere with interactive editing, which calls "show".
1107-- could interfere with interactive editing, which calls "show".
1091instance Show PTerm where
1109instance Show PTerm where
1092− showsPrec _ tm = (displayS . renderPretty 1.0 10000000 . prettyImp False) tm
1110+ showsPrec _ tm = (displayS . renderPretty 1.0 10000000 . prettyImp defaultPPOption) tm
1094instance Show PDecl where
1112instance Show PDecl where
1095− showsPrec _ d = (displayS . renderPretty 1.0 10000000 . showDeclImp False) d
1113+ showsPrec _ d = (displayS . renderPretty 1.0 10000000 . showDeclImp defaultPPOption) d
1097instance Show PClause where
1115instance Show PClause where
1098− showsPrec _ c = (displayS . renderPretty 1.0 10000000 . showCImp True) c
1116+ showsPrec _ c = (displayS . renderPretty 1.0 10000000 . showCImp verbosePPOption) c
1100instance Show PData where
1118instance Show PData where
1101− showsPrec _ d = (displayS . renderPretty 1.0 10000000 . showDImp False) d
1119+ showsPrec _ d = (displayS . renderPretty 1.0 10000000 . showDImp defaultPPOption) d
1103instance Pretty PTerm OutputAnnotation where
1121instance Pretty PTerm OutputAnnotation where
1104− pretty = prettyImp False
1122+ pretty = prettyImp defaultPPOption
1106-- | Colourise annotations according to an Idris state. It ignores the names
1124-- | Colourise annotations according to an Idris state. It ignores the names
1107-- in the annotation, as there's no good way to show extended information on a
1125-- in the annotation, as there's no good way to show extended information on a
@@ -1129,23 +1147,23 @@ consoleDecorate ist (AnnTextFmt fmt) = Idris.Colours.colourise (colour fmt)
1129 colour ItalicText = IdrisColour Nothing True False False True
1147 colour ItalicText = IdrisColour Nothing True False False True
1131-- | Pretty-print a high-level closed Idris term with no information about precedence/associativity
1149-- | Pretty-print a high-level closed Idris term with no information about precedence/associativity
1132−prettyImp :: Bool -- ^^ whether to show implicits
1150+prettyImp :: PPOption -- ^^ pretty printing options
1133 -> PTerm -- ^^ the term to pretty-print
1151 -> PTerm -- ^^ the term to pretty-print
1134 -> Doc OutputAnnotation
1152 -> Doc OutputAnnotation
1135prettyImp impl = pprintPTerm impl [] [] []
1153prettyImp impl = pprintPTerm impl [] [] []
1137-- | Do the right thing for rendering a term in an IState
1155-- | Do the right thing for rendering a term in an IState
1138prettyIst :: IState -> PTerm -> Doc OutputAnnotation
1156prettyIst :: IState -> PTerm -> Doc OutputAnnotation
1139−prettyIst ist = pprintPTerm (opt_showimp (idris_options ist)) [] [] (idris_infixes ist)
1157+prettyIst ist = pprintPTerm (ppOption (idris_options ist)) [] [] (idris_infixes ist)
1141-- | Pretty-print a high-level Idris term in some bindings context with infix info
1159-- | Pretty-print a high-level Idris term in some bindings context with infix info
1142−pprintPTerm :: Bool -- ^^ whether to show implicits
1160+pprintPTerm :: PPOption -- ^^ pretty printing options
1143 -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
1161 -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
1144 -> [Name] -- ^^ names to always show in pi, even if not used
1162 -> [Name] -- ^^ names to always show in pi, even if not used
1145 -> [FixDecl] -- ^^ Fixity declarations
1163 -> [FixDecl] -- ^^ Fixity declarations
1146 -> PTerm -- ^^ the term to pretty-print
1164 -> PTerm -- ^^ the term to pretty-print
1147 -> Doc OutputAnnotation
1165 -> Doc OutputAnnotation
1148−pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1166+pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1150 prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
1168 prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
1151 prettySe p bnd (PQuote r) =
1169 prettySe p bnd (PQuote r) =
@@ -1154,7 +1172,7 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1154 prettySe p bnd e
1172 prettySe p bnd e
1155 | Just str <- slist p bnd e = str
1173 | Just str <- slist p bnd e = str
1156 | Just n <- snat p e = annotate AnnConstData (text (show n))
1174 | Just n <- snat p e = annotate AnnConstData (text (show n))
1157− prettySe p bnd (PRef fc n) = prettyName impl bnd n
1175+ prettySe p bnd (PRef fc n) = prettyName (ppopt_impl ppo) bnd n
1158 prettySe p bnd (PLam n ty sc) =
1176 prettySe p bnd (PLam n ty sc) =
1159 bracket p 2 . group . align . hang 2 $
1177 bracket p 2 . group . align . hang 2 $
1160 text "\\" <> bindingOf n False <+> text "=>" <$>
1178 text "\\" <> bindingOf n False <+> text "=>" <$>
@@ -1165,7 +1183,7 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1165 prettySe 10 bnd v <+> kwd "in" </>
1183 prettySe 10 bnd v <+> kwd "in" </>
1166 prettySe 10 ((n, False):bnd) sc
1184 prettySe 10 ((n, False):bnd) sc
1167 prettySe p bnd (PPi (Exp l s _) n ty sc)
1185 prettySe p bnd (PPi (Exp l s _) n ty sc)
1168− | n `elem` allNamesIn sc || impl || n `elem` docArgs =
1186+ | n `elem` allNamesIn sc || ppopt_impl ppo || n `elem` docArgs =
1169 bracket p 2 . group $
1187 bracket p 2 . group $
1170 enclose lparen rparen (group . align $ bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1188 enclose lparen rparen (group . align $ bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1171 st <> text "->" <$> prettySe 10 ((n, False):bnd) sc
1189 st <> text "->" <$> prettySe 10 ((n, False):bnd) sc
@@ -1178,7 +1196,7 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1178 Static -> text "[static]" <> space
1196 Static -> text "[static]" <> space
1179 _ -> empty
1197 _ -> empty
1180 prettySe p bnd (PPi (Imp l s _) n ty sc)
1198 prettySe p bnd (PPi (Imp l s _) n ty sc)
1181− | impl =
1199+ | ppopt_impl ppo =
1182 bracket p 2 $
1200 bracket p 2 $
1183 lbrace <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1201 lbrace <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1184 st <> text "->" </> prettySe 10 ((n, True):bnd) sc
1202 st <> text "->" </> prettySe 10 ((n, True):bnd) sc
@@ -1197,16 +1215,16 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1197 rbrace <+> text "->" </> prettySe 10 ((n, True):bnd) sc
1215 rbrace <+> text "->" </> prettySe 10 ((n, True):bnd) sc
1198 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
1216 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
1199 | UN nm <- basename f
1217 | UN nm <- basename f
1218+ , not (ppopt_impl ppo) && null (getExps args) =
1200− , not impl && null (getExps args) = if isAlpha (thead nm)
1219+ if isAlpha (thead nm)
1201− then prettyName impl bnd f
1220+ then prettyName (ppopt_impl ppo) bnd f
1202− else enclose lparen rparen $
1221+ else enclose lparen rparen $ prettyName (ppopt_impl ppo) bnd f
1203− prettyName impl bnd f
1204 prettySe p bnd (PAppBind _ (PRef _ f) [])
1222 prettySe p bnd (PAppBind _ (PRef _ f) [])
1205− | not impl = text "!" <> prettyName impl bnd f
1223+ | not (ppopt_impl ppo) = text "!" <> prettyName (ppopt_impl ppo) bnd f
1206 prettySe p bnd (PApp _ (PRef _ op) args)
1224 prettySe p bnd (PApp _ (PRef _ op) args)
1207 | UN nm <- basename op
1225 | UN nm <- basename op
1208 , not (tnull nm) &&
1226 , not (tnull nm) &&
1209− (not impl) && (not $ isAlpha (thead nm)) =
1227+ (not (ppopt_impl ppo)) && (not $ isAlpha (thead nm)) =
1210 case getExps args of
1228 case getExps args of
1211 [] -> enclose lparen rparen opName
1229 [] -> enclose lparen rparen opName
1212 [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
1230 [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
@@ -1215,7 +1233,7 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1215 (l:r:rest) -> bracket p 1 $
1233 (l:r:rest) -> bracket p 1 $
1216 enclose lparen rparen (inFix l r) <+>
1234 enclose lparen rparen (inFix l r) <+>
1217 align (group (vsep (map (prettyArgSe bnd) rest)))
1235 align (group (vsep (map (prettyArgSe bnd) rest)))
1218− where opName = prettyName impl bnd op
1236+ where opName = prettyName (ppopt_impl ppo) bnd op
1219 f = getFixity (opStr op)
1237 f = getFixity (opStr op)
1220 left l = case f of
1238 left l = case f of
1221 Nothing -> prettySe (-1) bnd l
1239 Nothing -> prettySe (-1) bnd l
@@ -1235,7 +1253,7 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1235 fp = prettySe 1 bnd f
1253 fp = prettySe 1 bnd f
1237 bracket p 1 . group $
1255 bracket p 1 . group $
1238− if impl
1256+ if ppopt_impl ppo
1239 then if null as
1257 then if null as
1241 else fp <+> align (vsep (map (prettyArgS bnd) as))
1259 else fp <+> align (vsep (map (prettyArgS bnd) as))
@@ -1340,9 +1358,9 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1340 basename n = n
1358 basename n = n
1342 slist' p bnd (PApp _ (PRef _ nil) _)
1360 slist' p bnd (PApp _ (PRef _ nil) _)
1343− | not impl && nsroot nil == sUN "Nil" = Just []
1361+ | not (ppopt_impl ppo) && nsroot nil == sUN "Nil" = Just []
1344 slist' p bnd (PRef _ nil)
1362 slist' p bnd (PRef _ nil)
1345− | not impl && nsroot nil == sUN "Nil" = Just []
1363+ | not (ppopt_impl ppo) && nsroot nil == sUN "Nil" = Just []
1346 slist' p bnd (PApp _ (PRef _ cons) args)
1364 slist' p bnd (PApp _ (PRef _ cons) args)
1347 | nsroot cons == sUN "::",
1365 | nsroot cons == sUN "::",
1348 (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
1366 (PExp {getTm=tl}):(PExp {getTm=hd}):imps <- reverse args,
@@ -1415,43 +1433,43 @@ prettyName showNS bnd n | Just imp <- lookup n bnd = annotate (AnnBoundName n im
1415 strName other = show other
1433 strName other = show other
1418−showCImp :: Bool -> PClause -> Doc OutputAnnotation
1436+showCImp :: PPOption -> PClause -> Doc OutputAnnotation
1419−showCImp impl (PClause _ n l ws r w)
1437+showCImp ppo (PClause _ n l ws r w)
1420− = prettyImp impl l <+> showWs ws <+> text "=" <+> prettyImp impl r
1438+ = prettyImp ppo l <+> showWs ws <+> text "=" <+> prettyImp ppo r
1421 <+> text "where" <+> text (show w)
1439 <+> text "where" <+> text (show w)
1423 showWs [] = empty
1441 showWs [] = empty
1424− showWs (x : xs) = text "|" <+> prettyImp impl x <+> showWs xs
1442+ showWs (x : xs) = text "|" <+> prettyImp ppo x <+> showWs xs
1425−showCImp impl (PWith _ n l ws r w)
1443+showCImp ppo (PWith _ n l ws r w)
1426− = prettyImp impl l <+> showWs ws <+> text "with" <+> prettyImp impl r
1444+ = prettyImp ppo l <+> showWs ws <+> text "with" <+> prettyImp ppo r
1427 <+> braces (text (show w))
1445 <+> braces (text (show w))
1429 showWs [] = empty
1447 showWs [] = empty
1430− showWs (x : xs) = text "|" <+> prettyImp impl x <+> showWs xs
1448+ showWs (x : xs) = text "|" <+> prettyImp ppo x <+> showWs xs
1433−showDImp :: Bool -> PData -> Doc OutputAnnotation
1451+showDImp :: PPOption -> PData -> Doc OutputAnnotation
1434−showDImp impl (PDatadecl n ty cons)
1452+showDImp ppo (PDatadecl n ty cons)
1435− = text "data" <+> text (show n) <+> colon <+> prettyImp impl ty <+> text "where" <$>
1453+ = text "data" <+> text (show n) <+> colon <+> prettyImp ppo ty <+> text "where" <$>
1436− (indent 2 $ vsep (map (\ (_, _, n, t, _, _) -> pipe <+> prettyName False [] n <+> colon <+> prettyImp impl t) cons))
1454+ (indent 2 $ vsep (map (\ (_, _, n, t, _, _) -> pipe <+> prettyName False [] n <+> colon <+> prettyImp ppo t) cons))
1438−showDecls :: Bool -> [PDecl] -> Doc OutputAnnotation
1456+showDecls :: PPOption -> [PDecl] -> Doc OutputAnnotation
1439−showDecls i ds = vsep (map (showDeclImp i) ds)
1457+showDecls o ds = vsep (map (showDeclImp o) ds)
1441showDeclImp _ (PFix _ f ops) = text (show f) <+> cat (punctuate (text ",") (map text ops))
1459showDeclImp _ (PFix _ f ops) = text (show f) <+> cat (punctuate (text ",") (map text ops))
1442−showDeclImp i (PTy _ _ _ _ _ n t) = text "tydecl" <+> text (showCG n) <+> colon <+> prettyImp i t
1460+showDeclImp o (PTy _ _ _ _ _ n t) = text "tydecl" <+> text (showCG n) <+> colon <+> prettyImp o t
1443−showDeclImp i (PClauses _ _ n cs) = text "pat" <+> text (showCG n) <+> text "\t" <+>
1461+showDeclImp o (PClauses _ _ n cs) = text "pat" <+> text (showCG n) <+> text "\t" <+>
1444− indent 2 (vsep (map (showCImp i) cs))
1462+ indent 2 (vsep (map (showCImp o) cs))
1445−showDeclImp _ (PData _ _ _ _ _ d) = showDImp True d
1463+showDeclImp o (PData _ _ _ _ _ d) = showDImp o { ppopt_impl = True } d
1446−showDeclImp i (PParams _ ns ps) = text "params" <+> braces (text (show ns) <> line <> showDecls i ps <> line)
1464+showDeclImp o (PParams _ ns ps) = text "params" <+> braces (text (show ns) <> line <> showDecls o ps <> line)
1447−showDeclImp i (PNamespace n ps) = text "namespace" <+> text n <> braces (line <> showDecls i ps <> line)
1465+showDeclImp o (PNamespace n ps) = text "namespace" <+> text n <> braces (line <> showDecls o ps <> line)
1448showDeclImp _ (PSyntax _ syn) = text "syntax" <+> text (show syn)
1466showDeclImp _ (PSyntax _ syn) = text "syntax" <+> text (show syn)
1449−showDeclImp i (PClass _ _ _ cs n ps _ ds)
1467+showDeclImp o (PClass _ _ _ cs n ps _ ds)
1450− = text "class" <+> text (show cs) <+> text (show n) <+> text (show ps) <> line <> showDecls i ds
1468+ = text "class" <+> text (show cs) <+> text (show n) <+> text (show ps) <> line <> showDecls o ds
1451−showDeclImp i (PInstance _ _ cs n _ t _ ds)
1469+showDeclImp o (PInstance _ _ cs n _ t _ ds)
1452− = text "instance" <+> text (show cs) <+> text (show n) <+> prettyImp i t <> line <> showDecls i ds
1470+ = text "instance" <+> text (show cs) <+> text (show n) <+> prettyImp o t <> line <> showDecls o ds
1453showDeclImp _ _ = text "..."
1471showDeclImp _ _ = text "..."
1454−-- showDeclImp (PImport i) = "import " ++ i
1472+-- showDeclImp (PImport o) = "import " ++ o
1456instance Show (Doc OutputAnnotation) where
1474instance Show (Doc OutputAnnotation) where
1457 show = flip (displayS . renderCompact) ""
1475 show = flip (displayS . renderCompact) ""
@@ -1478,14 +1496,14 @@ getAll = map getTm
1478-- | Show Idris name
1496-- | Show Idris name
1479showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
1497showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
1480 -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
1498 -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
1481− -> Bool -- ^^ whether to show implicits
1499+ -> PPOption -- ^^ pretty printing options
1482 -> Bool -- ^^ whether to colourise
1500 -> Bool -- ^^ whether to colourise
1483 -> Name -- ^^ the term to show
1501 -> Name -- ^^ the term to show
1484 -> String
1502 -> String
1485−showName ist bnd impl colour n = case ist of
1503+showName ist bnd ppo colour n = case ist of
1486 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
1504 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
1487 Nothing -> showbasic n
1505 Nothing -> showbasic n
1488− where name = if impl then show n else showbasic n
1506+ where name = if ppopt_impl ppo then show n else showbasic n
1489 showbasic n@(UN _) = showCG n
1507 showbasic n@(UN _) = showCG n
1490 showbasic (MN _ s) = str s
1508 showbasic (MN _ s) = str s
1491 showbasic (NS n s) = showSep "." (map str (reverse s)) ++ "." ++ showbasic n
1509 showbasic (NS n s) = showSep "." (map str (reverse s)) ++ "." ++ showbasic n
@@ -1509,11 +1527,11 @@ showTm :: IState -- ^^ the Idris state, for information about identifiers and co
1509 -> String
1527 -> String
1510showTm ist = displayDecorated (consoleDecorate ist) .
1528showTm ist = displayDecorated (consoleDecorate ist) .
1511 renderPretty 0.8 100000 .
1529 renderPretty 0.8 100000 .
1512− prettyImp (opt_showimp (idris_options ist))
1530+ prettyImp (ppOption (idris_options ist))
1514-- | Show a term with implicits, no colours
1532-- | Show a term with implicits, no colours
1515showTmImpls :: PTerm -> String
1533showTmImpls :: PTerm -> String
1516−showTmImpls = flip (displayS . renderCompact . prettyImp True) ""
1534+showTmImpls = flip (displayS . renderCompact . prettyImp verbosePPOption) ""
1519instance Sized PTerm where
1537instance Sized PTerm where