@@ -1197,7 +1197,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
11971197 prettySe p bnd e
11981198 | Just str <- slist p bnd e = str
11991199 | 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
12011201 prettySe p bnd (PLam n ty sc) =
12021202 bracket p 2 . group . align . hang 2 $
12031203 text "\\" <> bindingOf n False <+> text "=>" <$>
@@ -1241,24 +1241,22 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
12411241 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
12421242 | UN nm <- basename f
12431243 , 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
12471245 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
12491247 prettySe p bnd (PApp _ (PRef _ op) args) -- infix operators
12501248 | UN nm <- basename op
12511249 , not (tnull nm) &&
12521250 (not (ppopt_impl ppo)) && (not $ isAlpha (thead nm)) =
12531251 case getExps args of
1254− [] -> enclose lparen rparen opName
1255− [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
1252+ [] -> opName True
1253+ [x] -> group (opName True <$> group (prettySe 0 bnd x))
12561254 [l,r] -> let precedence = fromMaybe 20 (fmap prec f)
12571255 in bracket p precedence $ inFix l r
12581256 (l:r:rest) -> bracket p 1 $
12591257 enclose lparen rparen (inFix l r) <+>
12601258 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
12621260 f = getFixity (opStr op)
12631261 left l = case f of
12641262 Nothing -> prettySe (-1) bnd l
@@ -1269,7 +1267,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
12691267 Just (Infixr p') -> prettySe p' bnd r
12701268 Just f' -> prettySe (prec f'-1) bnd r
12711269 inFix l r = align . group $
1272− (left l <+> opName) <$> group (right r)
1270+ (left l <+> opName False) <$> group (right r)
12731271 prettySe p bnd (PApp _ hd@(PRef fc f) [tm]) -- symbols, like 'foo
12741272 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
12751273 f == sUN "Symbol_" = annotate (AnnType ("'" ++ str) ("The symbol " ++ str)) $
@@ -1436,7 +1434,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
14361434
14371435prettyDocumentedIst :: IState -> (Name, PTerm, Maybe Docstring) -> Doc OutputAnnotation
14381436prettyDocumentedIst ist (name, ty, docs) =
1439− prettyName True [] name <+> colon <+> align (prettyIst ist ty) <$>
1437+ prettyName True True [] name <+> colon <+> align (prettyIst ist ty) <$>
14401438 fromMaybe empty (fmap (\d -> renderDocstring d <> line) docs)
14411439
14421440-- | Pretty-printer helper for the binding site of a name
@@ -1446,18 +1444,28 @@ bindingOf :: Name -- ^^ the bound name
14461444bindingOf n imp = annotate (AnnBoundName n imp) (text (show n))
14471445
14481446-- | Pretty-printer helper for names that attaches the correct annotations
1449−prettyName :: Bool -- ^^ whether to show namespaces
1450− -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1451− -> Name -- ^^ the name to pprint
1452− -> Doc OutputAnnotation
1453−prettyName showNS bnd n | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) (text (strName n))
1454− | otherwise = annotate (AnnName n Nothing Nothing Nothing) (text (strName n))
1455− where strName (UN n) = T.unpack n
1456− strName (NS n ns) | showNS = (concatMap (++ ".") . map T.unpack . reverse) ns ++ strName n
1457− | otherwise = strName n
1458− strName n | n == falseTy = "_|_"
1459− strName (MN i s) = T.unpack s
1460− strName other = show other
1447+prettyName
1448+ :: Bool -- ^^ whether the name should be parenthasized if it is an infix operator
1449+ -> Bool -- ^^ whether to show namespaces
1450+ -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1451+ -> Name -- ^^ the name to pprint
1452+ -> Doc OutputAnnotation
1453+prettyName infixParen showNS bnd n
1454+ | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) fullName
1455+ | otherwise = annotate (AnnName n Nothing Nothing Nothing) fullName
1456+ where fullName = text nameSpace <> parenthasize (text (baseName 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
1463+ (NS n' ns) -> if showNS then (concatMap (++ ".") . map T.unpack . reverse) ns else ""
1464+ _ -> ""
1465+ isInfix = case baseName n of
1466+ "" -> False
1467+ (c : _) -> not (isAlpha c)
1468+ parenthasize = if isInfix && infixParen then enclose lparen rparen else id
14611469
14621470
14631471showCImp :: PPOption -> PClause -> Doc OutputAnnotation
@@ -1478,7 +1486,7 @@ showCImp ppo (PWith _ n l ws r w)
14781486showDImp :: PPOption -> PData -> Doc OutputAnnotation
14791487showDImp ppo (PDatadecl n ty cons)
14801488 = 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))
14821490
14831491showDecls :: PPOption -> [PDecl] -> Doc OutputAnnotation
14841492showDecls o ds = vsep (map (showDeclImp o) ds)