@@ -1197,7 +1197,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1197 prettySe p bnd e
1197 prettySe p bnd e
1198 | Just str <- slist p bnd e = str
1198 | Just str <- slist p bnd e = str
1199 | Just n <- snat p e = annotate (AnnData "Nat" "") (text (show n))
1199 | Just n <- snat p e = annotate (AnnData "Nat" "") (text (show n))
1200− prettySe p bnd (PRef fc n) = prettyName (ppopt_impl ppo) bnd n
1200+ prettySe p bnd (PRef fc n) = prettyName True (ppopt_impl ppo) bnd n
1201 prettySe p bnd (PLam n ty sc) =
1201 prettySe p bnd (PLam n ty sc) =
1202 bracket p 2 . group . align . hang 2 $
1202 bracket p 2 . group . align . hang 2 $
1203 text "\\" <> bindingOf n False <+> text "=>" <$>
1203 text "\\" <> bindingOf n False <+> text "=>" <$>
@@ -1241,24 +1241,22 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1241 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
1241 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
1242 | UN nm <- basename f
1242 | UN nm <- basename f
1243 , not (ppopt_impl ppo) && null (getExps args) =
1243 , not (ppopt_impl ppo) && null (getExps args) =
1244− if isAlpha (thead nm)
1245− then prettyName (ppopt_impl ppo) bnd f
1246− else enclose lparen rparen $ prettyName (ppopt_impl ppo) bnd f
1244+ prettyName True (ppopt_impl ppo) bnd f
1247 prettySe p bnd (PAppBind _ (PRef _ f) [])
1245 prettySe p bnd (PAppBind _ (PRef _ f) [])
1248− | not (ppopt_impl ppo) = text "!" <> prettyName (ppopt_impl ppo) bnd f
1246+ | not (ppopt_impl ppo) = text "!" <> prettyName True (ppopt_impl ppo) bnd f
1249 prettySe p bnd (PApp _ (PRef _ op) args) -- infix operators
1247 prettySe p bnd (PApp _ (PRef _ op) args) -- infix operators
1250 | UN nm <- basename op
1248 | UN nm <- basename op
1251 , not (tnull nm) &&
1249 , not (tnull nm) &&
1252 (not (ppopt_impl ppo)) && (not $ isAlpha (thead nm)) =
1250 (not (ppopt_impl ppo)) && (not $ isAlpha (thead nm)) =
1253 case getExps args of
1251 case getExps args of
1254− [] -> enclose lparen rparen opName
1252+ [] -> opName True
1255− [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
1253+ [x] -> group (opName True <$> group (prettySe 0 bnd x))
1256 [l,r] -> let precedence = fromMaybe 20 (fmap prec f)
1254 [l,r] -> let precedence = fromMaybe 20 (fmap prec f)
1257 in bracket p precedence $ inFix l r
1255 in bracket p precedence $ inFix l r
1258 (l:r:rest) -> bracket p 1 $
1256 (l:r:rest) -> bracket p 1 $
1259 enclose lparen rparen (inFix l r) <+>
1257 enclose lparen rparen (inFix l r) <+>
1260 align (group (vsep (map (prettyArgSe bnd) rest)))
1258 align (group (vsep (map (prettyArgSe bnd) rest)))
1261− where opName = prettyName (ppopt_impl ppo) bnd op
1259+ where opName isPrefix = prettyName isPrefix (ppopt_impl ppo) bnd op
1262 f = getFixity (opStr op)
1260 f = getFixity (opStr op)
1263 left l = case f of
1261 left l = case f of
1264 Nothing -> prettySe (-1) bnd l
1262 Nothing -> prettySe (-1) bnd l
@@ -1269,7 +1267,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1269 Just (Infixr p') -> prettySe p' bnd r
1267 Just (Infixr p') -> prettySe p' bnd r
1270 Just f' -> prettySe (prec f'-1) bnd r
1268 Just f' -> prettySe (prec f'-1) bnd r
1271 inFix l r = align . group $
1269 inFix l r = align . group $
1272− (left l <+> opName) <$> group (right r)
1270+ (left l <+> opName False) <$> group (right r)
1273 prettySe p bnd (PApp _ hd@(PRef fc f) [tm]) -- symbols, like 'foo
1271 prettySe p bnd (PApp _ hd@(PRef fc f) [tm]) -- symbols, like 'foo
1274 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1272 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1275 f == sUN "Symbol_" = annotate (AnnType ("'" ++ str) ("The symbol " ++ str)) $
1273 f == sUN "Symbol_" = annotate (AnnType ("'" ++ str) ("The symbol " ++ str)) $
@@ -1436,7 +1434,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1437prettyDocumentedIst :: IState -> (Name, PTerm, Maybe Docstring) -> Doc OutputAnnotation
1435prettyDocumentedIst :: IState -> (Name, PTerm, Maybe Docstring) -> Doc OutputAnnotation
1438prettyDocumentedIst ist (name, ty, docs) =
1436prettyDocumentedIst ist (name, ty, docs) =
1439− prettyName True [] name <+> colon <+> align (prettyIst ist ty) <$>
1437+ prettyName True True [] name <+> colon <+> align (prettyIst ist ty) <$>
1440 fromMaybe empty (fmap (\d -> renderDocstring d <> line) docs)
1438 fromMaybe empty (fmap (\d -> renderDocstring d <> line) docs)
1442-- | Pretty-printer helper for the binding site of a name
1440-- | Pretty-printer helper for the binding site of a name
@@ -1446,18 +1444,28 @@ bindingOf :: Name -- ^^ the bound name
1446bindingOf n imp = annotate (AnnBoundName n imp) (text (show n))
1444bindingOf n imp = annotate (AnnBoundName n imp) (text (show n))
1448-- | Pretty-printer helper for names that attaches the correct annotations
1446-- | Pretty-printer helper for names that attaches the correct annotations
1448+ :: Bool -- ^^ whether the name should be parenthasized if it is an infix operator
1449−prettyName :: Bool -- ^^ whether to show namespaces
1449+ -> Bool -- ^^ whether to show namespaces
1450− -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1450+ -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1451− -> Name -- ^^ the name to pprint
1451+ -> Name -- ^^ the name to pprint
1452− -> Doc OutputAnnotation
1452+ -> Doc OutputAnnotation
1453+prettyName infixParen showNS bnd n
1453−prettyName showNS bnd n | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) (text (strName n))
1454+ | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) fullName
1454− | otherwise = annotate (AnnName n Nothing Nothing Nothing) (text (strName n))
1455+ | otherwise = annotate (AnnName n Nothing Nothing Nothing) fullName
1456+ where fullName = text nameSpace <> parenthasize (text (baseName n))
1455− where strName (UN n) = T.unpack n
1457+ baseName (UN n) = T.unpack n
1458+ baseName (NS n ns) = baseName n
1459+ baseName (MN i s) = T.unpack s
1460+ baseName n | n == falseTy = "_|_"
1461+ baseName other = show other
1462+ nameSpace = case n of
1456− strName (NS n ns) | showNS = (concatMap (++ ".") . map T.unpack . reverse) ns ++ strName n
1463+ (NS n' ns) -> if showNS then (concatMap (++ ".") . map T.unpack . reverse) ns else ""
1457− | otherwise = strName n
1464+ _ -> ""
1458− strName n | n == falseTy = "_|_"
1465+ isInfix = case baseName n of
1459− strName (MN i s) = T.unpack s
1466+ "" -> False
1460− strName other = show other
1467+ (c : _) -> not (isAlpha c)
1468+ parenthasize = if isInfix && infixParen then enclose lparen rparen else id
1463showCImp :: PPOption -> PClause -> Doc OutputAnnotation
1471showCImp :: PPOption -> PClause -> Doc OutputAnnotation
@@ -1478,7 +1486,7 @@ showCImp ppo (PWith _ n l ws r w)
1478showDImp :: PPOption -> PData -> Doc OutputAnnotation
1486showDImp :: PPOption -> PData -> Doc OutputAnnotation
1479showDImp ppo (PDatadecl n ty cons)
1487showDImp ppo (PDatadecl n ty cons)
1480 = text "data" <+> text (show n) <+> colon <+> prettyImp ppo ty <+> text "where" <$>
1488 = text "data" <+> text (show n) <+> colon <+> prettyImp ppo ty <+> text "where" <$>
1481− (indent 2 $ vsep (map (\ (_, _, n, t, _, _) -> pipe <+> prettyName False [] n <+> colon <+> prettyImp ppo t) cons))
1489+ (indent 2 $ vsep (map (\ (_, _, n, t, _, _) -> pipe <+> prettyName True False [] n <+> colon <+> prettyImp ppo t) cons))
1483showDecls :: PPOption -> [PDecl] -> Doc OutputAnnotation
1491showDecls :: PPOption -> [PDecl] -> Doc OutputAnnotation
1484showDecls o ds = vsep (map (showDeclImp o) ds)
1492showDecls o ds = vsep (map (showDeclImp o) ds)