-- File generated by the BNF Converter (bnfc 2.9.5).

{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
#if __GLASGOW_HASKELL__ <= 708
{-# LANGUAGE OverlappingInstances #-}
#endif

-- | Pretty-printer for Language.

module Language.SOAS.Syntax.Print where

import Prelude
  ( ($), (.)
  , Bool(..), (==), (<)
  , Int, Integer, Double, (+), (-), (*)
  , String, (++)
  , ShowS, showChar, showString
  , all, elem, foldr, id, map, null, replicate, shows, span
  )
import Data.Char ( Char, isSpace )
import qualified Language.SOAS.Syntax.Abs

-- | The top-level printing method.

printTree :: Print a => a -> String
printTree :: forall a. Print a => a -> String
printTree = Doc -> String
render (Doc -> String) -> (a -> Doc) -> a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0

type Doc = [ShowS] -> [ShowS]

doc :: ShowS -> Doc
doc :: ShowS -> Doc
doc = (:)

render :: Doc -> String
render :: Doc -> String
render Doc
d = Int -> Bool -> [String] -> ShowS
rend Int
0 Bool
False ((ShowS -> String) -> [ShowS] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String
"") ([ShowS] -> [String]) -> [ShowS] -> [String]
forall a b. (a -> b) -> a -> b
$ Doc
d []) String
""
  where
  rend
    :: Int        -- ^ Indentation level.
    -> Bool       -- ^ Pending indentation to be output before next character?
    -> [String]
    -> ShowS
  rend :: Int -> Bool -> [String] -> ShowS
rend Int
i Bool
p = \case
      String
"["      :[String]
ts -> Char -> ShowS
char Char
'[' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> [String] -> ShowS
rend Int
i Bool
False [String]
ts
      String
"("      :[String]
ts -> Char -> ShowS
char Char
'(' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> [String] -> ShowS
rend Int
i Bool
False [String]
ts
      String
"{"      :[String]
ts -> Int -> Bool -> ShowS
onNewLine Int
i     Bool
p ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar   Char
'{'  ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
new (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) [String]
ts
      String
"}" : String
";":[String]
ts -> Int -> Bool -> ShowS
onNewLine (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) Bool
p ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"};" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
new (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) [String]
ts
      String
"}"      :[String]
ts -> Int -> Bool -> ShowS
onNewLine (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) Bool
p ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar   Char
'}'  ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
new (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) [String]
ts
      [String
";"]        -> Char -> ShowS
char Char
';'
      String
";"      :[String]
ts -> Char -> ShowS
char Char
';' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
new Int
i [String]
ts
      String
t  : ts :: [String]
ts@(String
s:[String]
_) | String -> Bool
closingOrPunctuation String
s
                   -> ShowS
pending ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
t ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> [String] -> ShowS
rend Int
i Bool
False [String]
ts
      String
t        :[String]
ts -> ShowS
pending ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
space String
t      ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> [String] -> ShowS
rend Int
i Bool
False [String]
ts
      []           -> ShowS
forall a. a -> a
id
    where
    -- Output character after pending indentation.
    char :: Char -> ShowS
    char :: Char -> ShowS
char Char
c = ShowS
pending ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
c

    -- Output pending indentation.
    pending :: ShowS
    pending :: ShowS
pending = if Bool
p then Int -> ShowS
indent Int
i else ShowS
forall a. a -> a
id

  -- Indentation (spaces) for given indentation level.
  indent :: Int -> ShowS
  indent :: Int -> ShowS
indent Int
i = Int -> ShowS -> ShowS
replicateS (Int
2Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
i) (Char -> ShowS
showChar Char
' ')

  -- Continue rendering in new line with new indentation.
  new :: Int -> [String] -> ShowS
  new :: Int -> [String] -> ShowS
new Int
j [String]
ts = Char -> ShowS
showChar Char
'\n' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> [String] -> ShowS
rend Int
j Bool
True [String]
ts

  -- Make sure we are on a fresh line.
  onNewLine :: Int -> Bool -> ShowS
  onNewLine :: Int -> Bool -> ShowS
onNewLine Int
i Bool
p = (if Bool
p then ShowS
forall a. a -> a
id else Char -> ShowS
showChar Char
'\n') ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
indent Int
i

  -- Separate given string from following text by a space (if needed).
  space :: String -> ShowS
  space :: String -> ShowS
space String
t String
s =
    case ((Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace String
t, String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
spc, String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
rest) of
      (Bool
True , Bool
_   , Bool
True ) -> []             -- remove trailing space
      (Bool
False, Bool
_   , Bool
True ) -> String
t              -- remove trailing space
      (Bool
False, Bool
True, Bool
False) -> String
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char
' ' Char -> ShowS
forall a. a -> [a] -> [a]
: String
s   -- add space if none
      (Bool, Bool, Bool)
_                    -> String
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s
    where
      (String
spc, String
rest) = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
span Char -> Bool
isSpace String
s

  closingOrPunctuation :: String -> Bool
  closingOrPunctuation :: String -> Bool
closingOrPunctuation [Char
c] = Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
closerOrPunct
  closingOrPunctuation String
_   = Bool
False

  closerOrPunct :: String
  closerOrPunct :: String
closerOrPunct = String
")],;"

parenth :: Doc -> Doc
parenth :: Doc -> Doc
parenth Doc
ss = ShowS -> Doc
doc (Char -> ShowS
showChar Char
'(') Doc -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc
ss Doc -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS -> Doc
doc (Char -> ShowS
showChar Char
')')

concatS :: [ShowS] -> ShowS
concatS :: [ShowS] -> ShowS
concatS = (ShowS -> ShowS -> ShowS) -> ShowS -> [ShowS] -> ShowS
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ShowS
forall a. a -> a
id

concatD :: [Doc] -> Doc
concatD :: [Doc] -> Doc
concatD = (Doc -> Doc -> Doc) -> Doc -> [Doc] -> Doc
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Doc -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) Doc
forall a. a -> a
id

replicateS :: Int -> ShowS -> ShowS
replicateS :: Int -> ShowS -> ShowS
replicateS Int
n ShowS
f = [ShowS] -> ShowS
concatS (Int -> ShowS -> [ShowS]
forall a. Int -> a -> [a]
replicate Int
n ShowS
f)

-- | The printer class does the job.

class Print a where
  prt :: Int -> a -> Doc

instance {-# OVERLAPPABLE #-} Print a => Print [a] where
  prt :: Int -> [a] -> Doc
prt Int
i = [Doc] -> Doc
concatD ([Doc] -> Doc) -> ([a] -> [Doc]) -> [a] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
i)

instance Print Char where
  prt :: Int -> Char -> Doc
prt Int
_ Char
c = ShowS -> Doc
doc (Char -> ShowS
showChar Char
'\'' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Char -> ShowS
mkEsc Char
'\'' Char
c ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'\'')

instance Print String where
  prt :: Int -> String -> Doc
prt Int
_ = String -> Doc
printString

printString :: String -> Doc
printString :: String -> Doc
printString String
s = ShowS -> Doc
doc (Char -> ShowS
showChar Char
'"' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ShowS] -> ShowS
concatS ((Char -> ShowS) -> String -> [ShowS]
forall a b. (a -> b) -> [a] -> [b]
map (Char -> Char -> ShowS
mkEsc Char
'"') String
s) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'"')

mkEsc :: Char -> Char -> ShowS
mkEsc :: Char -> Char -> ShowS
mkEsc Char
q = \case
  Char
s | Char
s Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
q -> Char -> ShowS
showChar Char
'\\' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
s
  Char
'\\' -> String -> ShowS
showString String
"\\\\"
  Char
'\n' -> String -> ShowS
showString String
"\\n"
  Char
'\t' -> String -> ShowS
showString String
"\\t"
  Char
s -> Char -> ShowS
showChar Char
s

prPrec :: Int -> Int -> Doc -> Doc
prPrec :: Int -> Int -> Doc -> Doc
prPrec Int
i Int
j = if Int
j Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
i then Doc -> Doc
parenth else Doc -> Doc
forall a. a -> a
id

instance Print Integer where
  prt :: Int -> Integer -> Doc
prt Int
_ Integer
x = ShowS -> Doc
doc (Integer -> ShowS
forall a. Show a => a -> ShowS
shows Integer
x)

instance Print Double where
  prt :: Int -> Double -> Doc
prt Int
_ Double
x = ShowS -> Doc
doc (Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
x)

instance Print Language.SOAS.Syntax.Abs.VarIdent where
  prt :: Int -> VarIdent -> Doc
prt Int
_ (Language.SOAS.Syntax.Abs.VarIdent String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.SOAS.Syntax.Abs.OpIdent where
  prt :: Int -> OpIdent -> Doc
prt Int
_ (Language.SOAS.Syntax.Abs.OpIdent String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.SOAS.Syntax.Abs.MetaVarIdent where
  prt :: Int -> MetaVarIdent -> Doc
prt Int
_ (Language.SOAS.Syntax.Abs.MetaVarIdent String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print (Language.SOAS.Syntax.Abs.TermTyping' a) where
  prt :: Int -> TermTyping' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.TermTyping a
_ TypeBinders' a
typebinders Context' a
context ScopedTerm' a
scopedterm ScopedType' a
scopedtype -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8704"), Int -> TypeBinders' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 TypeBinders' a
typebinders, ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> Context' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Context' a
context, ShowS -> Doc
doc (String -> ShowS
showString String
"\8866"), Int -> ScopedTerm' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedTerm' a
scopedterm, ShowS -> Doc
doc (String -> ShowS
showString String
":"), Int -> ScopedType' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedType' a
scopedtype])

instance Print (Language.SOAS.Syntax.Abs.Context' a) where
  prt :: Int -> Context' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.Context a
_ [MetaVarTyping' a]
metavartypings [VarTyping' a]
vartypings -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [MetaVarTyping' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [MetaVarTyping' a]
metavartypings, ShowS -> Doc
doc (String -> ShowS
showString String
"|"), Int -> [VarTyping' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [VarTyping' a]
vartypings])

instance Print (Language.SOAS.Syntax.Abs.VarTyping' a) where
  prt :: Int -> VarTyping' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.VarTyping a
_ VarIdent
varident Type' a
type_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> VarIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 VarIdent
varident, ShowS -> Doc
doc (String -> ShowS
showString String
":"), Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Type' a
type_])

instance Print [Language.SOAS.Syntax.Abs.VarTyping' a] where
  prt :: Int -> [VarTyping' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
  prt Int
_ [VarTyping' a
x] = [Doc] -> Doc
concatD [Int -> VarTyping' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 VarTyping' a
x]
  prt Int
_ (VarTyping' a
x:[VarTyping' a]
xs) = [Doc] -> Doc
concatD [Int -> VarTyping' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 VarTyping' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [VarTyping' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [VarTyping' a]
xs]

instance Print (Language.SOAS.Syntax.Abs.MetaVarTyping' a) where
  prt :: Int -> MetaVarTyping' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.MetaVarTyping a
_ MetaVarIdent
metavarident [Type' a]
types Type' a
type_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> MetaVarIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MetaVarIdent
metavarident, ShowS -> Doc
doc (String -> ShowS
showString String
":"), ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> [Type' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Type' a]
types, ShowS -> Doc
doc (String -> ShowS
showString String
"]"), Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Type' a
type_])

instance Print [Language.SOAS.Syntax.Abs.MetaVarTyping' a] where
  prt :: Int -> [MetaVarTyping' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
  prt Int
_ [MetaVarTyping' a
x] = [Doc] -> Doc
concatD [Int -> MetaVarTyping' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MetaVarTyping' a
x]
  prt Int
_ (MetaVarTyping' a
x:[MetaVarTyping' a]
xs) = [Doc] -> Doc
concatD [Int -> MetaVarTyping' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MetaVarTyping' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [MetaVarTyping' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [MetaVarTyping' a]
xs]

instance Print (Language.SOAS.Syntax.Abs.OpTyping' a) where
  prt :: Int -> OpTyping' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.OpTyping a
_ OpIdent
opident TypeBinders' a
typebinders [ScopedOpArgTyping' a]
scopedopargtypings ScopedType' a
scopedtype -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> OpIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 OpIdent
opident, ShowS -> Doc
doc (String -> ShowS
showString String
":"), ShowS -> Doc
doc (String -> ShowS
showString String
"\8704"), Int -> TypeBinders' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 TypeBinders' a
typebinders, ShowS -> Doc
doc (String -> ShowS
showString String
"."), ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> [ScopedOpArgTyping' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [ScopedOpArgTyping' a]
scopedopargtypings, ShowS -> Doc
doc (String -> ShowS
showString String
")"), ShowS -> Doc
doc (String -> ShowS
showString String
"\8594"), Int -> ScopedType' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedType' a
scopedtype])

instance Print (Language.SOAS.Syntax.Abs.Constraint' a) where
  prt :: Int -> Constraint' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.ConstraintEq a
_ Binders' a
binders ScopedTerm' a
scopedterm1 ScopedTerm' a
scopedterm2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8704"), Int -> Binders' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Binders' a
binders, ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> ScopedTerm' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedTerm' a
scopedterm1, ShowS -> Doc
doc (String -> ShowS
showString String
"="), Int -> ScopedTerm' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedTerm' a
scopedterm2])

instance Print (Language.SOAS.Syntax.Abs.Unifier' a) where
  prt :: Int -> Unifier' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.Unifier a
_ [Subst' a]
substs -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> [Subst' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Subst' a]
substs, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])

instance Print (Language.SOAS.Syntax.Abs.Subst' a) where
  prt :: Int -> Subst' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.Subst a
_ MetaVarIdent
metavarident Binders' a
binders ScopedTerm' a
scopedterm -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> MetaVarIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MetaVarIdent
metavarident, ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> Binders' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Binders' a
binders, ShowS -> Doc
doc (String -> ShowS
showString String
"]"), ShowS -> Doc
doc (String -> ShowS
showString String
"\8614"), Int -> ScopedTerm' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedTerm' a
scopedterm])

instance Print [Language.SOAS.Syntax.Abs.Subst' a] where
  prt :: Int -> [Subst' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
  prt Int
_ [Subst' a
x] = [Doc] -> Doc
concatD [Int -> Subst' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Subst' a
x]
  prt Int
_ (Subst' a
x:[Subst' a]
xs) = [Doc] -> Doc
concatD [Int -> Subst' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Subst' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [Subst' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Subst' a]
xs]

instance Print (Language.SOAS.Syntax.Abs.Term' a) where
  prt :: Int -> Term' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.Var a
_ VarIdent
varident -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> VarIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 VarIdent
varident])
    Language.SOAS.Syntax.Abs.Op a
_ OpIdent
opident [OpArg' a]
opargs -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> OpIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 OpIdent
opident, ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> [OpArg' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [OpArg' a]
opargs, ShowS -> Doc
doc (String -> ShowS
showString String
")")])
    Language.SOAS.Syntax.Abs.MetaVar a
_ MetaVarIdent
metavarident [Term' a]
terms -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> MetaVarIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MetaVarIdent
metavarident, ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> [Term' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Term' a]
terms, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])

instance Print [Language.SOAS.Syntax.Abs.Term' a] where
  prt :: Int -> [Term' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
  prt Int
_ [Term' a
x] = [Doc] -> Doc
concatD [Int -> Term' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Term' a
x]
  prt Int
_ (Term' a
x:[Term' a]
xs) = [Doc] -> Doc
concatD [Int -> Term' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Term' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [Term' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Term' a]
xs]

instance Print (Language.SOAS.Syntax.Abs.OpArg' a) where
  prt :: Int -> OpArg' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.OpArg a
_ Binders' a
binders ScopedTerm' a
scopedterm -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Binders' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Binders' a
binders, ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> ScopedTerm' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedTerm' a
scopedterm])
    Language.SOAS.Syntax.Abs.PlainOpArg a
_ Term' a
term -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Term' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Term' a
term])

instance Print [Language.SOAS.Syntax.Abs.OpArg' a] where
  prt :: Int -> [OpArg' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
  prt Int
_ [OpArg' a
x] = [Doc] -> Doc
concatD [Int -> OpArg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 OpArg' a
x]
  prt Int
_ (OpArg' a
x:[OpArg' a]
xs) = [Doc] -> Doc
concatD [Int -> OpArg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 OpArg' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [OpArg' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [OpArg' a]
xs]

instance Print (Language.SOAS.Syntax.Abs.Binders' a) where
  prt :: Int -> Binders' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.NoBinders a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [])
    Language.SOAS.Syntax.Abs.SomeBinders a
_ VarIdent
varident Binders' a
binders -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> VarIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 VarIdent
varident, Int -> Binders' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Binders' a
binders])

instance Print (Language.SOAS.Syntax.Abs.ScopedTerm' a) where
  prt :: Int -> ScopedTerm' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.ScopedTerm a
_ Term' a
term -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Term' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Term' a
term])

instance Print (Language.SOAS.Syntax.Abs.Type' a) where
  prt :: Int -> Type' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.TypeFun a
_ Type' a
type_1 Type' a
type_2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Type' a
type_1, ShowS -> Doc
doc (String -> ShowS
showString String
"\8594"), Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Type' a
type_2])
    Language.SOAS.Syntax.Abs.TypeProduct a
_ Type' a
type_1 Type' a
type_2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
1 ([Doc] -> Doc
concatD [Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Type' a
type_1, ShowS -> Doc
doc (String -> ShowS
showString String
"\215"), Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Type' a
type_2])
    Language.SOAS.Syntax.Abs.TypeVar a
_ VarIdent
varident -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> VarIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 VarIdent
varident])

instance Print [Language.SOAS.Syntax.Abs.Type' a] where
  prt :: Int -> [Type' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
  prt Int
_ [Type' a
x] = [Doc] -> Doc
concatD [Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Type' a
x]
  prt Int
_ (Type' a
x:[Type' a]
xs) = [Doc] -> Doc
concatD [Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Type' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [Type' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Type' a]
xs]

instance Print (Language.SOAS.Syntax.Abs.TypeBinders' a) where
  prt :: Int -> TypeBinders' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.NoTypeBinders a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [])
    Language.SOAS.Syntax.Abs.SomeTypeBinders a
_ VarIdent
varident TypeBinders' a
typebinders -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> VarIdent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 VarIdent
varident, Int -> TypeBinders' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 TypeBinders' a
typebinders])

instance Print (Language.SOAS.Syntax.Abs.ScopedOpArgTyping' a) where
  prt :: Int -> ScopedOpArgTyping' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.ScopedOpArgTyping a
_ OpArgTyping' a
opargtyping -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> OpArgTyping' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 OpArgTyping' a
opargtyping])

instance Print [Language.SOAS.Syntax.Abs.ScopedOpArgTyping' a] where
  prt :: Int -> [ScopedOpArgTyping' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
  prt Int
_ [ScopedOpArgTyping' a
x] = [Doc] -> Doc
concatD [Int -> ScopedOpArgTyping' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedOpArgTyping' a
x]
  prt Int
_ (ScopedOpArgTyping' a
x:[ScopedOpArgTyping' a]
xs) = [Doc] -> Doc
concatD [Int -> ScopedOpArgTyping' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedOpArgTyping' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [ScopedOpArgTyping' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [ScopedOpArgTyping' a]
xs]

instance Print (Language.SOAS.Syntax.Abs.OpArgTyping' a) where
  prt :: Int -> OpArgTyping' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.OpArgTyping a
_ [Type' a]
types Type' a
type_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [Type' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Type' a]
types, ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Type' a
type_])

instance Print (Language.SOAS.Syntax.Abs.ScopedType' a) where
  prt :: Int -> ScopedType' a -> Doc
prt Int
i = \case
    Language.SOAS.Syntax.Abs.ScopedType a
_ Type' a
type_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Type' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Type' a
type_])

instance Print [Language.SOAS.Syntax.Abs.ScopedType' a] where
  prt :: Int -> [ScopedType' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
  prt Int
_ (ScopedType' a
x:[ScopedType' a]
xs) = [Doc] -> Doc
concatD [Int -> ScopedType' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ScopedType' a
x, Int -> [ScopedType' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [ScopedType' a]
xs]