on master help sign in
Improve pretty-printing of function applications

* Show infix operators properly even if they have a number of arguments that isn't 2 * snd . snd $ (1,2,3) is now (snd . snd) (1,2,3) instead of . snd snd (1,2,3) * (+) 4 is shown as (+) 4 * Show applications where all arguments are implicit without parens around them Fixes #882.

commitb82f552b227fcd716d7d11dbf9e317eb8ea02dce authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateFri 14 Feb 2014, 18:49 (13 years ago) parenteea7c61
1 file changed+17−6
src/Idris/AbsSyntaxTree.hs+17−6
src/Idris/AbsSyntaxTree.hs+17−6
@@ -1131,17 +1131,28 @@ pprintPTerm impl bnd = prettySe 10 bnd
11311131 bracket p 2 $
11321132 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 bnd ty <>
11331133 rbrace <+> text "->" </> prettySe 10 ((n, True):bnd) sc
1134− prettySe p bnd (PApp _ (PRef _ f) [])
1135− | not impl = prettyName impl bnd f
1134+ prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
1135+ | UN nm <- basename f
1136+ , not impl && null (getExps args) = if isAlpha (thead nm)
1137+ then prettyName impl bnd f
1138+ else enclose lparen rparen $
1139+ prettyName impl bnd f
11361140 prettySe p bnd (PAppBind _ (PRef _ f) [])
11371141 | not impl = text "!" <> prettyName impl bnd f
11381142 prettySe p bnd (PApp _ (PRef _ op) args)
11391143 | UN nm <- basename op
11401144 , not (tnull nm) &&
1141− length (getExps args) == 2 && (not impl) && (not $ isAlpha (thead nm)) =
1142− let [l, r] = getExps args in
1143− bracket p 1 . align . group $
1144− (prettySe 1 bnd l <+> prettyName impl bnd op) <$> group (prettySe 0 bnd r)
1145+ (not impl) && (not $ isAlpha (thead nm)) =
1146+ case getExps args of
1147+ [] -> enclose lparen rparen opName
1148+ [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
1149+ [l,r] -> bracket p 1 $ inFix l r
1150+ (l:r:rest) -> bracket p 1 $
1151+ enclose lparen rparen (inFix l r) <+>
1152+ align (group (vsep (map (prettyArgSe bnd) rest)))
1153+ where opName = prettyName impl bnd op
1154+ inFix l r = align . group $
1155+ (prettySe 1 bnd l <+> opName) <$> group (prettySe 0 bnd r)
11451156 prettySe p bnd (PApp _ hd@(PRef fc f) [tm])
11461157 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
11471158 f == sUN "Symbol_" = char '\'' <> prettySe 10 bnd (PRef fc (sUN str))