@@ -1276,8 +1276,10 @@ pprintPTerm :: PPOption -- ^^ pretty printing options
1276 -> [FixDecl] -- ^^ Fixity declarations
1276 -> [FixDecl] -- ^^ Fixity declarations
1277 -> PTerm -- ^^ the term to pretty-print
1277 -> PTerm -- ^^ the term to pretty-print
1278 -> Doc OutputAnnotation
1278 -> Doc OutputAnnotation
1279−pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1279+pprintPTerm ppo bnd docArgs infixes = prettySe startPrec bnd
1281 prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
1283 prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
1282 prettySe p bnd (PQuote r) =
1284 prettySe p bnd (PQuote r) =
1283 text "![" <> pretty r <> text "]"
1285 text "![" <> pretty r <> text "]"
@@ -1287,21 +1289,21 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1287 | Just n <- snat p e = annotate (AnnData "Nat" "") (text (show n))
1289 | Just n <- snat p e = annotate (AnnData "Nat" "") (text (show n))
1288 prettySe p bnd (PRef fc n) = prettyName True (ppopt_impl ppo) bnd n
1290 prettySe p bnd (PRef fc n) = prettyName True (ppopt_impl ppo) bnd n
1289 prettySe p bnd (PLam fc n ty sc) =
1291 prettySe p bnd (PLam fc n ty sc) =
1290− bracket p 2 . group . align . hang 2 $
1292+ bracket p startPrec . group . align . hang 2 $
1291 text "\\" <> bindingOf n False <+> text "=>" <$>
1293 text "\\" <> bindingOf n False <+> text "=>" <$>
1292− prettySe 10 ((n, False):bnd) sc
1294+ prettySe startPrec ((n, False):bnd) sc
1293 prettySe p bnd (PLet fc n ty v sc) =
1295 prettySe p bnd (PLet fc n ty v sc) =
1294− bracket p 2 . group . align $
1296+ bracket p startPrec . group . align $
1295− kwd "let" <+> (group . align . hang 2 $ bindingOf n False <+> text "=" <$> prettySe 10 bnd v) </>
1297+ kwd "let" <+> (group . align . hang 2 $ bindingOf n False <+> text "=" <$> prettySe startPrec bnd v) </>
1296− kwd "in" <+> (group . align . hang 2 $ prettySe 10 ((n, False):bnd) sc)
1298+ kwd "in" <+> (group . align . hang 2 $ prettySe startPrec ((n, False):bnd) sc)
1297 prettySe p bnd (PPi (Exp l s _) n ty sc)
1299 prettySe p bnd (PPi (Exp l s _) n ty sc)
1298 | n `elem` allNamesIn sc || ppopt_impl ppo || n `elem` docArgs =
1300 | n `elem` allNamesIn sc || ppopt_impl ppo || n `elem` docArgs =
1299− bracket p 2 . group $
1301+ bracket p startPrec . group $
1300− enclose lparen rparen (group . align $ bindingOf n False <+> colon <+> prettySe 10 bnd ty) <+>
1302+ enclose lparen rparen (group . align $ bindingOf n False <+> colon <+> prettySe startPrec bnd ty) <+>
1301− st <> text "->" <$> prettySe 10 ((n, False):bnd) sc
1303+ st <> text "->" <$> prettySe startPrec ((n, False):bnd) sc
1302 | otherwise =
1304 | otherwise =
1303− bracket p 2 . group $
1305+ bracket p startPrec . group $
1304− group (prettySe 1 bnd ty <+> st) <> text "->" <$> group (prettySe 10 ((n, False):bnd) sc)
1306+ group (prettySe (startPrec + 1) bnd ty <+> st) <> text "->" <$> group (prettySe startPrec ((n, False):bnd) sc)
1307 case s of
1309 case s of
@@ -1309,22 +1311,22 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1309 _ -> empty
1311 _ -> empty
1310 prettySe p bnd (PPi (Imp l s _) n ty sc)
1312 prettySe p bnd (PPi (Imp l s _) n ty sc)
1311 | ppopt_impl ppo =
1313 | ppopt_impl ppo =
1312− bracket p 2 $
1314+ bracket p startPrec $
1313− lbrace <> bindingOf n True <+> colon <+> prettySe 10 bnd ty <> rbrace <+>
1315+ lbrace <> bindingOf n True <+> colon <+> prettySe startPrec bnd ty <> rbrace <+>
1314− st <> text "->" </> prettySe 10 ((n, True):bnd) sc
1316+ st <> text "->" </> prettySe startPrec ((n, True):bnd) sc
1315− | otherwise = prettySe 10 ((n, True):bnd) sc
1317+ | otherwise = prettySe startPrec ((n, True):bnd) sc
1318 case s of
1320 case s of
1319 Static -> text "[static]" <> space
1321 Static -> text "[static]" <> space
1320 _ -> empty
1322 _ -> empty
1321 prettySe p bnd (PPi (Constraint _ _) n ty sc) =
1323 prettySe p bnd (PPi (Constraint _ _) n ty sc) =
1322− bracket p 2 $
1324+ bracket p startPrec $
1323− prettySe 10 bnd ty <+> text "=>" </> prettySe 10 ((n, True):bnd) sc
1325+ prettySe (startPrec + 1) bnd ty <+> text "=>" </> prettySe startPrec ((n, True):bnd) sc
1324 prettySe p bnd (PPi (TacImp _ _ s) n ty sc) =
1326 prettySe p bnd (PPi (TacImp _ _ s) n ty sc) =
1325− bracket p 2 $
1327+ bracket p startPrec $
1326− lbrace <> kwd "tacimp" <+> pretty n <+> colon <+> prettySe 10 bnd ty <>
1328+ lbrace <> kwd "tacimp" <+> pretty n <+> colon <+> prettySe startPrec bnd ty <>
1327− rbrace <+> text "->" </> prettySe 10 ((n, True):bnd) sc
1329+ rbrace <+> text "->" </> prettySe startPrec ((n, True):bnd) sc
1328 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
1330 prettySe p bnd (PApp _ (PRef _ f) args) -- normal names, no explicit args
1329 | UN nm <- basename f
1331 | UN nm <- basename f
1330 , not (ppopt_impl ppo) && null (getShowArgs args) =
1332 , not (ppopt_impl ppo) && null (getShowArgs args) =
@@ -1337,50 +1339,48 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1337 (not (ppopt_impl ppo)) && (not $ isAlpha (thead nm)) =
1339 (not (ppopt_impl ppo)) && (not $ isAlpha (thead nm)) =
1338 case getShowArgs args of
1340 case getShowArgs args of
1339 [] -> opName True
1341 [] -> opName True
1340− [x] -> group (opName True <$> group (prettySe 0 bnd (getTm x)))
1342+ [x] -> group (opName True <$> group (prettySe startPrec bnd (getTm x)))
1341− [l,r] -> let precedence = fromMaybe 20 (fmap prec f)
1343+ [l,r] -> let precedence = maybe (startPrec - 1) prec f
1342 in bracket p precedence $ inFix (getTm l) (getTm r)
1344 in bracket p precedence $ inFix (getTm l) (getTm r)
1343 (l@(PExp _ _ _ _) : r@(PExp _ _ _ _) : rest) ->
1345 (l@(PExp _ _ _ _) : r@(PExp _ _ _ _) : rest) ->
1344− bracket p 1 $
1346+ bracket p funcAppPrec $
1345 enclose lparen rparen (inFix (getTm l) (getTm r)) <+>
1347 enclose lparen rparen (inFix (getTm l) (getTm r)) <+>
1346 align (group (vsep (map (prettyArgS bnd) rest)))
1348 align (group (vsep (map (prettyArgS bnd) rest)))
1347 as -> opName True <+> align (vsep (map (prettyArgS bnd) as))
1349 as -> opName True <+> align (vsep (map (prettyArgS bnd) as))
1348 where opName isPrefix = prettyName isPrefix (ppopt_impl ppo) bnd op
1350 where opName isPrefix = prettyName isPrefix (ppopt_impl ppo) bnd op
1349 f = getFixity (opStr op)
1351 f = getFixity (opStr op)
1350− left l = case f of
1352+ left = case f of
1351− Nothing -> prettySe (-1) bnd l
1353+ Nothing -> funcAppPrec + 1
1352− Just (Infixl p') -> prettySe p' bnd l
1354+ Just (Infixl p') -> p'
1353− Just f' -> prettySe (prec f'-1) bnd l
1355+ Just f' -> prec f' + 1
1354− right r = case f of
1356+ right = case f of
1355− Nothing -> prettySe (-1) bnd r
1357+ Nothing -> funcAppPrec + 1
1356− Just (Infixr p') -> prettySe p' bnd r
1358+ Just (Infixr p') -> p'
1357− Just f' -> prettySe (prec f'-1) bnd r
1359+ Just f' -> prec f' + 1
1358 inFix l r = align . group $
1360 inFix l r = align . group $
1359− (left l <+> opName False) <$> group (right r)
1361+ (prettySe left bnd l <+> opName False) <$>
1362+ group (prettySe right bnd r)
1360 prettySe p bnd (PApp _ hd@(PRef fc f) [tm]) -- symbols, like 'foo
1363 prettySe p bnd (PApp _ hd@(PRef fc f) [tm]) -- symbols, like 'foo
1361 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1364 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1362 f == sUN "Symbol_" = annotate (AnnType ("'" ++ str) ("The symbol " ++ str)) $
1365 f == sUN "Symbol_" = annotate (AnnType ("'" ++ str) ("The symbol " ++ str)) $
1363− char '\'' <> prettySe 10 bnd (PRef fc (sUN str))
1366+ char '\'' <> prettySe startPrec bnd (PRef fc (sUN str))
1364 prettySe p bnd (PApp _ f as) = -- Normal prefix applications
1367 prettySe p bnd (PApp _ f as) = -- Normal prefix applications
1365 let args = getShowArgs as
1368 let args = getShowArgs as
1366− fp = prettySe 1 bnd f
1369+ fp = prettySe (startPrec + 1) bnd f
1370+ shownArgs = if ppopt_impl ppo then as else args
1368− bracket p 1 . group $
1372+ bracket p funcAppPrec . group $
1370− then if null as
1373+ if null shownArgs
1371− then fp
1374+ then fp
1372− else fp <+> align (vsep (map (prettyArgS bnd) as))
1375+ else fp <+> align (vsep (map (prettyArgS bnd) shownArgs))
1375− else fp <+> align (vsep (map (prettyArgS bnd) args))
1376 prettySe p bnd (PCase _ scr cases) =
1376 prettySe p bnd (PCase _ scr cases) =
1377− align $ kwd "case" <+> prettySe 10 bnd scr <+> kwd "of" <$>
1377+ align $ kwd "case" <+> prettySe startPrec bnd scr <+> kwd "of" <$>
1378 indent 2 (vsep (map ppcase cases))
1378 indent 2 (vsep (map ppcase cases))
1380+ ppcase (l, r) = let prettyCase = prettySe startPrec
1381+ ([(n, False) | n <- vars l] ++ bnd)
1380− ppcase (l, r) = nest nestingSize $
1382+ in nest nestingSize $
1381− prettySe 10 ([(n, False) | n <- vars l] ++ bnd) l <+>
1383+ prettyCase l <+> text "=>" <+> prettyCase r
1383− prettySe 10 ([(n, False) | n <- vars l] ++ bnd) r
1384 -- Warning: this is a bit of a hack. At this stage, we don't have the
1384 -- Warning: this is a bit of a hack. At this stage, we don't have the
1385 -- global context, so we can't determine which names are constructors,
1385 -- global context, so we can't determine which names are constructors,
1386 -- which are types, and which are pattern variables on the LHS of the
1386 -- which are types, and which are pattern variables on the LHS of the
@@ -1395,7 +1395,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1395 noNS (NS _ _) = False
1395 noNS (NS _ _) = False
1396 noNS _ = True
1396 noNS _ = True
1398− prettySe p bnd (PHidden tm) = text "." <> prettySe 0 bnd tm
1398+ prettySe p bnd (PHidden tm) = text "." <> prettySe funcAppPrec bnd tm
1399 prettySe p bnd (PRefl _ _) = annName eqCon $ text "Refl"
1399 prettySe p bnd (PRefl _ _) = annName eqCon $ text "Refl"
1400 prettySe p bnd (PResolveTC _) = text "resolvetc"
1400 prettySe p bnd (PResolveTC _) = text "resolvetc"
1401 prettySe p bnd (PTrue _ IsType) = annName unitTy $ text "()"
1401 prettySe p bnd (PTrue _ IsType) = annName unitTy $ text "()"
@@ -1403,7 +1403,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1403 prettySe p bnd (PTrue _ TypeOrTerm) = text "()"
1403 prettySe p bnd (PTrue _ TypeOrTerm) = text "()"
1404 prettySe p bnd (PEq _ lt rt l r)
1404 prettySe p bnd (PEq _ lt rt l r)
1405 | ppopt_impl ppo =
1405 | ppopt_impl ppo =
1406− bracket p 1 $
1406+ bracket p eqPrec $
1407 enclose lparen rparen eq <+>
1407 enclose lparen rparen eq <+>
1408 align (group (vsep (map (prettyArgS bnd)
1408 align (group (vsep (map (prettyArgS bnd)
1409 [PImp 0 False [] (sUN "A") lt,
1409 [PImp 0 False [] (sUN "A") lt,
@@ -1411,47 +1411,42 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1411 PExp 0 [] (sUN "x") l,
1411 PExp 0 [] (sUN "x") l,
1412 PExp 0 [] (sUN "y") r])))
1412 PExp 0 [] (sUN "y") r])))
1413 | otherwise =
1413 | otherwise =
1414− bracket p 2 . align . group $
1414+ bracket p eqPrec . align . group $
1415− prettySe 10 bnd l <+> eq <$> group (prettySe 10 bnd r)
1415+ prettyTerm l <+> eq <$> group (prettyTerm r)
1416 where eq = annName eqTy (text "=")
1416 where eq = annName eqTy (text "=")
1418+ prettyTerm = prettySe (eqPrec + 1) bnd
1417 prettySe p bnd (PRewrite _ l r _) =
1419 prettySe p bnd (PRewrite _ l r _) =
1418− bracket p 2 $
1420+ bracket p startPrec $
1419− text "rewrite" <+> prettySe 10 bnd l <+> text "in" <+> prettySe 10 bnd r
1421+ text "rewrite" <+> prettySe (startPrec + 1) bnd l <+> text "in" <+> prettySe startPrec bnd r
1420 prettySe p bnd (PTyped l r) =
1422 prettySe p bnd (PTyped l r) =
1421− lparen <> prettySe 10 bnd l <+> colon <+> prettySe 10 bnd r <> rparen
1423+ lparen <> prettySe startPrec bnd l <+> colon <+> prettySe startPrec bnd r <> rparen
1422 prettySe p bnd pair@(PPair _ pun _ _) -- flatten tuples to the right, like parser
1424 prettySe p bnd pair@(PPair _ pun _ _) -- flatten tuples to the right, like parser
1423 | Just elts <- pairElts pair = enclose (ann lparen) (ann rparen) .
1425 | Just elts <- pairElts pair = enclose (ann lparen) (ann rparen) .
1424 align . group . vsep . punctuate (ann comma) $
1426 align . group . vsep . punctuate (ann comma) $
1425− map (prettySe 10 bnd) elts
1427+ map (prettySe startPrec bnd) elts
1426 where ann = case pun of
1428 where ann = case pun of
1427 TypeOrTerm -> id
1429 TypeOrTerm -> id
1428 IsType -> annName pairTy
1430 IsType -> annName pairTy
1429 IsTerm -> annName pairCon
1431 IsTerm -> annName pairCon
1430− prettySe p bnd (PDPair _ TypeOrTerm l t r) =
1432+ prettySe p bnd (PDPair _ pun l t r) =
1431− lparen <> prettySe 10 bnd l <+> text "**" <+> prettySe 10 bnd r <> rparen
1433+ annotated lparen <>
1432− prettySe p bnd (PDPair _ IsType (PRef _ n) t r) =
1434+ left <+>
1433− annName sigmaTy lparen <>
1435+ annotated (text "**") <+>
1436+ prettySe startPrec (addBinding bnd) r <>
1438+ where annotated = case pun of
1439+ IsType -> annName sigmaTy
1440+ IsTerm -> annName existsCon
1442+ (left, addBinding) = case (l, pun) of
1434− bindingOf n False <+>
1443+ (PRef _ n, IsType) -> (bindingOf n False, ((n, False) :))
1435− annName sigmaTy (text "**") <+>
1436− prettySe 10 ((n, False):bnd) r <>
1437− annName sigmaTy rparen
1438− prettySe p bnd (PDPair _ IsType l t r) =
1439− annName sigmaTy lparen <>
1440− prettySe 10 bnd l <+>
1441− annName sigmaTy (text "**") <+>
1442− prettySe 10 bnd r <>
1444+ _ -> (prettySe startPrec bnd l, id )
1443− annName sigmaTy rparen
1444− prettySe p bnd (PDPair _ IsTerm l t r) =
1445− annName existsCon lparen <>
1446− prettySe 10 bnd l <+>
1447− annName existsCon (text "**") <+>
1448− prettySe 10 bnd r <>
1449− annName existsCon rparen
1450 prettySe p bnd (PAlternative a as) =
1445 prettySe p bnd (PAlternative a as) =
1451 lparen <> text "|" <> prettyAs <> text "|" <> rparen
1446 lparen <> text "|" <> prettyAs <> text "|" <> rparen
1453 prettyAs =
1448 prettyAs =
1454− foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10 bnd) as
1449+ foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe startPrec bnd) as
1455 prettySe p bnd PType = annotate (AnnType "Type" "The type of types") $ text "Type"
1450 prettySe p bnd PType = annotate (AnnType "Type" "The type of types") $ text "Type"
1456 prettySe p bnd (PUniverse u) = annotate (AnnType (show u) "The type of unique types") $ text (show u)
1451 prettySe p bnd (PUniverse u) = annotate (AnnType (show u) "The type of unique types") $ text (show u)
1457 prettySe p bnd (PConstant c) = annotate (AnnConst c) (text (show c))
1452 prettySe p bnd (PConstant c) = annotate (AnnConst c) (text (show c))
@@ -1479,10 +1474,10 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1479 prettyArgS bnd (PConstraint _ _ _ tm) = prettyArgSc bnd tm
1474 prettyArgS bnd (PConstraint _ _ _ tm) = prettyArgSc bnd tm
1480 prettyArgS bnd (PTacImplicit _ _ n _ tm) = prettyArgSti bnd (n, tm)
1475 prettyArgS bnd (PTacImplicit _ _ n _ tm) = prettyArgSti bnd (n, tm)
1482− prettyArgSe bnd arg = prettySe 0 bnd arg
1477+ prettyArgSe bnd arg = prettySe (funcAppPrec + 1) bnd arg
1483− prettyArgSi bnd (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1478+ prettyArgSi bnd (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe startPrec bnd val <> rbrace
1484− prettyArgSc bnd val = lbrace <> lbrace <> prettySe 10 bnd val <> rbrace <> rbrace
1479+ prettyArgSc bnd val = lbrace <> lbrace <> prettySe startPrec bnd val <> rbrace <> rbrace
1485− prettyArgSti bnd (n, val) = lbrace <> kwd "auto" <+> pretty n <+> text "=" <+> prettySe 10 bnd val <> rbrace
1480+ prettyArgSti bnd (n, val) = lbrace <> kwd "auto" <+> pretty n <+> text "=" <+> prettySe startPrec bnd val <> rbrace
1487 annName :: Name -> Doc OutputAnnotation -> Doc OutputAnnotation
1482 annName :: Name -> Doc OutputAnnotation -> Doc OutputAnnotation
1488 annName n = annotate (AnnName n Nothing Nothing Nothing)
1483 annName n = annotate (AnnName n Nothing Nothing Nothing)
@@ -1539,7 +1534,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe 10 bnd
1539 snat _ _ = Nothing
1534 snat _ _ = Nothing
1541 bracket outer inner doc
1536 bracket outer inner doc
1542− | inner > outer = lparen <> doc <> rparen
1537+ | outer > inner = lparen <> doc <> rparen
1543 | otherwise = doc
1538 | otherwise = doc
1545 kwd = annotate AnnKeyword . text
1540 kwd = annotate AnnKeyword . text