@@ -1185,7 +1185,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
11851185 prettySe p bnd e
11861186 | Just str <- slist p bnd e = str
11871187 | Just n <- snat p e = annotate (AnnData "Nat" "") (text (show n))
1188− prettySe p bnd (PRef fc n) = prettyName (ppopt_impl ppo) bnd n
1188+ prettySe p bnd (PRef fc n) = prettyNamePossParen True (ppopt_impl ppo) bnd n
11891189 prettySe p bnd (PLam n ty sc) =
11901190 bracket p 2 . group . align . hang 2 $
11911191 text "\\" <> bindingOf n False <+> text "=>" <$>
@@ -1229,24 +1229,22 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
12291229 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
12301230 | UN nm <- basename f
12311231 , not (ppopt_impl ppo) && null (getExps args) =
1232− if isAlpha (thead nm)
1233− then prettyName (ppopt_impl ppo) bnd f
1234− else enclose lparen rparen $ prettyName (ppopt_impl ppo) bnd f
1232+ prettyNamePossParen True (ppopt_impl ppo) bnd f
12351233 prettySe p bnd (PAppBind _ (PRef _ f) [])
1236− | not (ppopt_impl ppo) = text "!" <> prettyName (ppopt_impl ppo) bnd f
1234+ | not (ppopt_impl ppo) = text "!" <> prettyNamePossParen True (ppopt_impl ppo) bnd f
12371235 prettySe p bnd (PApp _ (PRef _ op) args) -- infix operators
12381236 | UN nm <- basename op
12391237 , not (tnull nm) &&
12401238 (not (ppopt_impl ppo)) && (not $ isAlpha (thead nm)) =
12411239 case getExps args of
1242− [] -> enclose lparen rparen opName
1243− [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
1240+ [] -> opName True
1241+ [x] -> group (opName True <$> group (prettySe 0 bnd x))
12441242 [l,r] -> let precedence = fromMaybe 20 (fmap prec f)
12451243 in bracket p precedence $ inFix l r
12461244 (l:r:rest) -> bracket p 1 $
12471245 enclose lparen rparen (inFix l r) <+>
12481246 align (group (vsep (map (prettyArgSe bnd) rest)))
1249− where opName = prettyName (ppopt_impl ppo) bnd op
1247+ where opName isPrefix = prettyNamePossParen isPrefix (ppopt_impl ppo) bnd op
12501248 f = getFixity (opStr op)
12511249 left l = case f of
12521250 Nothing -> prettySe (-1) bnd l
@@ -1257,7 +1255,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
12571255 Just (Infixr p') -> prettySe p' bnd r
12581256 Just f' -> prettySe (prec f'-1) bnd r
12591257 inFix l r = align . group $
1260− (left l <+> opName) <$> group (right r)
1258+ (left l <+> opName False) <$> group (right r)
12611259 prettySe p bnd (PApp _ hd@(PRef fc f) [tm]) -- symbols, like 'foo
12621260 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
12631261 f == sUN "Symbol_" = annotate (AnnType ("'" ++ str) ("The symbol " ++ str)) $
@@ -1424,7 +1422,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
14241422
14251423prettyDocumentedIst :: IState -> (Name, PTerm, Maybe Docstring) -> Doc OutputAnnotation
14261424prettyDocumentedIst ist (name, ty, docs) =
1427− prettyNamePossParen True [] name <+> colon <+> align (prettyIst ist ty) <$>
1425+ prettyNamePossParen True True [] name <+> colon <+> align (prettyIst ist ty) <$>
14281426 fromMaybe empty (fmap (\d -> renderDocstring d <> line) docs)
14291427
14301428-- | Pretty-printer helper for the binding site of a name
@@ -1434,26 +1432,32 @@ bindingOf :: Name -- ^^ the bound name
14341432bindingOf n imp = annotate (AnnBoundName n imp) (text (show n))
14351433
14361434-- | Pretty-printer helper for names that attaches the correct annotations
1437−prettyName :: Bool -- ^^ whether to show namespaces
1438− -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1439− -> Name -- ^^ the name to pprint
1440− -> Doc OutputAnnotation
1441−prettyName showNS bnd n | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) (text (strName n))
1442− | otherwise = annotate (AnnName n Nothing Nothing Nothing) (text (strName n))
1443− where strName (UN n) = T.unpack n
1444− strName (NS n ns) | showNS = (concatMap (++ ".") . map T.unpack . reverse) ns ++ strName n
1445− | otherwise = strName n
1446− strName n | n == falseTy = "_|_"
1447− strName (MN i s) = T.unpack s
1448− strName other = show other
1449−
1450−prettyNamePossParen :: Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
1451−prettyNamePossParen showNS bnd n = parenthasize (prettyName showNS bnd n) where
1452− UN basename = case n of
1453− NS n' _ -> n'
1454− _ -> n
1455− isInfix = not (isAlpha (thead basename))
1456− parenthasize = if isInfix then enclose lparen rparen else id
1435+prettyNamePossParen
1436+ :: Bool -- ^^ whether the name should be parenthasized if it is an infix operator
1437+ -> Bool -- ^^ whether to show namespaces
1438+ -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
1439+ -> Name -- ^^ the name to pprint
1440+ -> Doc OutputAnnotation
1441+prettyNamePossParen infixParen showNS bnd n
1442+ | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) fullName
1443+ | otherwise = annotate (AnnName n Nothing Nothing Nothing) fullName
1444+ where fullName = text nameSpace <> parenthasize (text (baseName n))
1445+ baseName (UN n) = T.unpack n
1446+ baseName (NS n ns) = baseName n
1447+ baseName (MN i s) = T.unpack s
1448+ baseName n | n == falseTy = "_|_"
1449+ baseName other = show other
1450+ nameSpace = case n of
1451+ (NS n' ns) -> if showNS then (concatMap (++ ".") . map T.unpack . reverse) ns else ""
1452+ _ -> ""
1453+ isInfix = case baseName n of
1454+ "" -> False
1455+ (c : _) -> not (isAlpha c)
1456+ parenthasize = if isInfix && infixParen then enclose lparen rparen else id
1457+
1458+
1459+prettyName :: Bool -> [(Name, Bool)] -> Name -> Doc OutputAnnotation
1460+prettyName = prettyNamePossParen False
14571461
14581462
14591463showCImp :: PPOption -> PClause -> Doc OutputAnnotation
@@ -1474,7 +1478,7 @@ showCImp ppo (PWith _ n l ws r w)
14741478showDImp :: PPOption -> PData -> Doc OutputAnnotation
14751479showDImp ppo (PDatadecl n ty cons)
14761480 = text "data" <+> text (show n) <+> colon <+> prettyImp ppo ty <+> text "where" <$>
1477− (indent 2 $ vsep (map (\ (_, _, n, t, _, _) -> pipe <+> prettyName False [] n <+> colon <+> prettyImp ppo t) cons))
1481+ (indent 2 $ vsep (map (\ (_, _, n, t, _, _) -> pipe <+> prettyNamePossParen True False [] n <+> colon <+> prettyImp ppo t) cons))
14781482
14791483showDecls :: PPOption -> [PDecl] -> Doc OutputAnnotation
14801484showDecls o ds = vsep (map (showDeclImp o) ds)