



{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}




-- {-# OPTIONS_GHC -Wall #-}
-- {-# OPTIONS_GHC -fno-warn-unused-matches #-}
-- {-# OPTIONS_GHC -fno-warn-name-shadowing #-}



-- |
-- Copyright :  (c) Andreas Reuleaux 2015
-- License   :  BSD2
-- Maintainer:  Andreas Reuleaux <rx@a-rx.info>
-- Stability :  experimental
-- Portability: non-portable
--
-- This module provides pretty printing functionality for Pire:
-- common or basic functions



module Pire.Pretty.Wrap where


import Pire.Syntax.Eps
import Pire.Syntax.Expr



import Text.PrettyPrint as TPP




bindParens :: Eps -> Doc -> Doc
bindParens RuntimeP    d = d
bindParens ErasedP     d = brackets d



mandatoryBindParens :: Eps -> Doc -> Doc
mandatoryBindParens RuntimeP d = parens d
mandatoryBindParens ErasedP  d = brackets d


-- deciding whether to add parens to the func of an application

-- back to the original pi-forall defs, now that we
-- have a means to distinguish beforehand w/ wsAware
-- whether to use wrapf/wraparg at all

-- white space aware and regular (non white space aware)
-- expressions are never mixed (although theortically possible)
-- except at the lowest level: Ws_ (V "foo") $ Ws "bar"

wrapf :: Expr t a -> Doc -> Doc
wrapf f = case f of
  V   _         -> id

  -- Ws_ _ _       -> id

  (:@) _ _      -> id
  ErasedApp _ _ -> id
  Paren _       -> id
  Position _ a       -> wrapf a
  TrustMe _     -> id
  _             -> parens


wraparg :: Expr t a -> Doc -> Doc
wraparg x = case x of
  V _         -> id
  
  -- should be necessary
  -- Ws_ _ _     -> id

  Type        -> id
  TyUnit      -> id
  LitUnit     -> id
  TyBool      -> id
  LitBool _   -> id
  Sigma _ _ _ -> id
  TrustMe _   -> id      
  TCon _ []   -> id  

  -- rethink
  -- (isNumeral -> Just x) -> id
  Nat _       -> id

  DCon _ [] _ -> id
  Refl _      -> id
  Position _ a     -> wraparg a
  _           -> parens



