From 67264e748ad8075c7fb59529749c3b416b50c6bb Mon Sep 17 00:00:00 2001 From: Paul Chiusano Date: Tue, 1 Dec 2015 23:19:24 -0500 Subject: [PATCH] fix parenthesization bug in prettyprinters --- shared/src/Unison/Views.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shared/src/Unison/Views.hs b/shared/src/Unison/Views.hs index a34874cb9..c83180a50 100644 --- a/shared/src/Unison/Views.hs +++ b/shared/src/Unison/Views.hs @@ -5,7 +5,6 @@ module Unison.Views where import Data.List -import Data.Maybe import Data.Map (Map) import Data.Text (Text) import Unison.Doc (Doc) @@ -94,12 +93,13 @@ term ref t = go no View.low t where Symbol.Symbol _ name view = op fn (taken, remaining) = splitAt (View.arity view) args fmt (child,path) = (\p -> go (fn ==) p child, path) - applied = fromMaybe unsaturated (View.instantiate view fnP name (map fmt taken)) + applied = maybe unsaturated (D.parenthesize (p > View.precedence view)) $ + View.instantiate view fnP name (map fmt taken) unsaturated = D.sub' fnP $ go no View.high fn in (if inChain fn then id else D.group) $ case remaining of [] -> applied - args -> D.parenthesize (p > View.high) . D.group . D.docs $ + args -> D.group . D.docs $ [ applied, D.breakable " " , D.nest " " . D.group . D.delimit (D.breakable " ") $ [ D.sub' p (go no (View.increase View.high) s) | (s,p) <- args ] ] @@ -140,12 +140,13 @@ type' ref t = go no View.low t Symbol _ name view = op fn (taken, remaining) = splitAt (View.arity view) args fmt (child,path) = (\p -> D.sub' path (go (fn ==) p child), path) - applied = fromMaybe unsaturated (View.instantiate view fnP name (map fmt taken)) + applied = maybe unsaturated (D.parenthesize (p > View.precedence view)) + (View.instantiate view fnP name (map fmt taken)) unsaturated = D.sub' fnP $ go no View.high fn in (if inChain fn then id else D.group) $ case remaining of [] -> applied - args -> D.parenthesize (p > View.high) . D.group . D.docs $ + args -> D.group . D.docs $ [ applied, D.breakable " " , D.nest " " . D.group . D.delimit (D.breakable " ") $ [ D.sub' p (go no (View.increase View.high) s) | (s,p) <- args ] ]