@@ -31,6 +31,7 @@ import qualified Data.Map as M
31import Data.Either
31import Data.Either
32import qualified Data.Set as S
32import qualified Data.Set as S
33import Data.Word (Word)
33import Data.Word (Word)
34+import Data.Maybe (fromMaybe)
35import Debug.Trace
36import Debug.Trace
@@ -1133,6 +1134,10 @@ prettyImp :: Bool -- ^^ whether to show implicits
1133 -> Doc OutputAnnotation
1134 -> Doc OutputAnnotation
1134prettyImp impl = pprintPTerm impl [] [] []
1135prettyImp impl = pprintPTerm impl [] [] []
1137+-- | Do the right thing for rendering a term in an IState
1138+prettyIst :: IState -> PTerm -> Doc OutputAnnotation
1139+prettyIst ist = pprintPTerm (opt_showimp (idris_options ist)) [] [] (idris_infixes ist)
1136-- | Pretty-print a high-level Idris term in some bindings context with infix info
1141-- | Pretty-print a high-level Idris term in some bindings context with infix info
1137pprintPTerm :: Bool -- ^^ whether to show implicits
1142pprintPTerm :: Bool -- ^^ whether to show implicits
1138 -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
1143 -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
@@ -1205,13 +1210,23 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1205 case getExps args of
1210 case getExps args of
1206 [] -> enclose lparen rparen opName
1211 [] -> enclose lparen rparen opName
1207 [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
1212 [x] -> group (enclose lparen rparen opName <$> group (prettySe 0 bnd x))
1213+ [l,r] -> let precedence = fromMaybe 20 (fmap prec f)
1208− [l,r] -> bracket p 1 $ inFix l r
1214+ in trace ("p=" ++ show p++",prec="++show precedence) (bracket p precedence $ inFix l r)
1209 (l:r:rest) -> bracket p 1 $
1215 (l:r:rest) -> bracket p 1 $
1210 enclose lparen rparen (inFix l r) <+>
1216 enclose lparen rparen (inFix l r) <+>
1211 align (group (vsep (map (prettyArgSe bnd) rest)))
1217 align (group (vsep (map (prettyArgSe bnd) rest)))
1212 where opName = prettyName impl bnd op
1218 where opName = prettyName impl bnd op
1219+ f = getFixity (opStr op)
1221+ Nothing -> prettySe (-1) bnd l
1222+ Just (Infixl p') -> prettySe p' bnd l
1223+ Just f' -> prettySe (prec f'-1) bnd l
1224+ right r = case f of
1225+ Nothing -> prettySe (-1) bnd r
1226+ Just (Infixr p') -> prettySe p' bnd r
1227+ Just f' -> prettySe (prec f'-1) bnd r
1213 inFix l r = align . group $
1228 inFix l r = align . group $
1214− (prettySe 1 bnd l <+> opName) <$> group (prettySe 0 bnd r)
1229+ (left l <+> opName) <$> group (right r)
1215 prettySe p bnd (PApp _ hd@(PRef fc f) [tm])
1230 prettySe p bnd (PApp _ hd@(PRef fc f) [tm])
1216 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1231 | PConstant (Idris.Core.TT.Str str) <- getTm tm,
1217 f == sUN "Symbol_" = char '\'' <> prettySe 10 bnd (PRef fc (sUN str))
1232 f == sUN "Symbol_" = char '\'' <> prettySe 10 bnd (PRef fc (sUN str))
@@ -1316,6 +1331,10 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1316 annName :: Name -> Doc OutputAnnotation -> Doc OutputAnnotation
1331 annName :: Name -> Doc OutputAnnotation -> Doc OutputAnnotation
1317 annName n = annotate (AnnName n Nothing Nothing Nothing)
1332 annName n = annotate (AnnName n Nothing Nothing Nothing)
1334+ opStr :: Name -> String
1335+ opStr (NS n _) = opStr n
1336+ opStr (UN n) = T.unpack n
1319 basename :: Name -> Name
1338 basename :: Name -> Name
1320 basename (NS n _) = basename n
1339 basename (NS n _) = basename n
1321 basename n = n
1340 basename n = n
@@ -1369,6 +1388,12 @@ pprintPTerm impl bnd docArgs infixes = prettySe 10 bnd
1370 kwd = annotate AnnKeyword . text
1389 kwd = annotate AnnKeyword . text
1391+ fixities :: M.Map String Fixity
1392+ fixities = M.fromList [(s, f) | (Fix f s) <- infixes]
1394+ getFixity :: String -> Maybe Fixity
1395+ getFixity = flip M.lookup fixities
1372-- | Pretty-printer helper for the binding site of a name
1397-- | Pretty-printer helper for the binding site of a name
1373bindingOf :: Name -- ^^ the bound name
1398bindingOf :: Name -- ^^ the bound name
1374 -> Bool -- ^^ whether the name is implicit
1399 -> Bool -- ^^ whether the name is implicit