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

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

-- | Pretty-printer for RSTT.

module RSTT.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 RSTT.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 (t :: * -> *) a. Foldable t => t a -> Bool
null String
spc, String -> 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
      t' :: String
t'          = String -> ShowS
showString String
t []
      (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 (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 (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 (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 RSTT.Syntax.Abs.Label where
  prt :: Int -> Label -> Doc
prt Int
_ (RSTT.Syntax.Abs.Label String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print RSTT.Syntax.Abs.Var where
  prt :: Int -> Var -> Doc
prt Int
_ (RSTT.Syntax.Abs.Var String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print RSTT.Syntax.Abs.Line where
  prt :: Int -> Line -> Doc
prt Int
_ (RSTT.Syntax.Abs.Line String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print RSTT.Syntax.Abs.Program where
  prt :: Int -> Program -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.Program [Decl]
decls -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [Decl] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Decl]
decls])

instance Print RSTT.Syntax.Abs.Decl where
  prt :: Int -> Decl -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.DeclCube Label
label [PointConDecl]
pointcondecls -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"cube"), Int -> Label -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label
label, ShowS -> Doc
doc (String -> ShowS
showString String
"with"), ShowS -> Doc
doc (String -> ShowS
showString String
"{"), Int -> [PointConDecl] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [PointConDecl]
pointcondecls, ShowS -> Doc
doc (String -> ShowS
showString String
"}")])
    RSTT.Syntax.Abs.DeclTopePrefix Label
label [Cube]
cubes [TopeRule]
toperules -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"tope"), Int -> Label -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label
label, ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> [Cube] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Cube]
cubes, ShowS -> Doc
doc (String -> ShowS
showString String
")"), ShowS -> Doc
doc (String -> ShowS
showString String
"with"), ShowS -> Doc
doc (String -> ShowS
showString String
"{"), Int -> [TopeRule] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [TopeRule]
toperules, ShowS -> Doc
doc (String -> ShowS
showString String
"}")])
    RSTT.Syntax.Abs.DeclShape Var
var Shape
shape -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"shape"), Int -> Var -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Var
var, ShowS -> Doc
doc (String -> ShowS
showString String
":="), Int -> Shape -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Shape
shape])
    RSTT.Syntax.Abs.DeclCommandProve Sequent
sequent -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"prove"), ShowS -> Doc
doc (String -> ShowS
showString String
"{"), Int -> Sequent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Sequent
sequent, ShowS -> Doc
doc (String -> ShowS
showString String
"}")])
    RSTT.Syntax.Abs.DeclCommandRenderLatex Shape
shape -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"render"), ShowS -> Doc
doc (String -> ShowS
showString String
"latex"), Int -> Shape -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Shape
shape])

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

instance Print RSTT.Syntax.Abs.Shape where
  prt :: Int -> Shape -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.Shape PointPattern
pointpattern Cube
cube Tope
tope -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"{"), Int -> PointPattern -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 PointPattern
pointpattern, ShowS -> Doc
doc (String -> ShowS
showString String
":"), Int -> Cube -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cube
cube, ShowS -> Doc
doc (String -> ShowS
showString String
"|"), Int -> Tope -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Tope
tope, ShowS -> Doc
doc (String -> ShowS
showString String
"}")])

instance Print RSTT.Syntax.Abs.PointPattern where
  prt :: Int -> PointPattern -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.PointPatternVar Var
var -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Var -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Var
var])
    RSTT.Syntax.Abs.PointPatternPair PointPattern
pointpattern1 PointPattern
pointpattern2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\10216"), Int -> PointPattern -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 PointPattern
pointpattern1, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> PointPattern -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 PointPattern
pointpattern2, ShowS -> Doc
doc (String -> ShowS
showString String
"\10217")])

instance Print RSTT.Syntax.Abs.PointConDecl where
  prt :: Int -> PointConDecl -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.NullaryPointConDecl Label
label -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"point"), Int -> Label -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label
label])
    RSTT.Syntax.Abs.PrefixPointConDecl Label
label [Cube]
cubes -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"point"), Int -> Label -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label
label, ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> [Cube] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Cube]
cubes, ShowS -> Doc
doc (String -> ShowS
showString String
")")])

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

instance Print RSTT.Syntax.Abs.Cube where
  prt :: Int -> Cube -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.CubeProduct Cube
cube1 Cube
cube2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Cube -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cube
cube1, ShowS -> Doc
doc (String -> ShowS
showString String
"\215"), Int -> Cube -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Cube
cube2])
    Cube
RSTT.Syntax.Abs.CubeUnit -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
1 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\120793")])
    RSTT.Syntax.Abs.CubeCon Label
label -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
1 ([Doc] -> Doc
concatD [Int -> Label -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label
label])
    RSTT.Syntax.Abs.CubeVar Var
var -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
1 ([Doc] -> Doc
concatD [Int -> Var -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Var
var])

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

instance Print RSTT.Syntax.Abs.TopeRule where
  prt :: Int -> TopeRule -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.TopeRule RuleName
rulename [Sequent]
sequents Line
line Sequent
sequent -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"rule"), Int -> RuleName -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 RuleName
rulename, ShowS -> Doc
doc (String -> ShowS
showString String
"where"), ShowS -> Doc
doc (String -> ShowS
showString String
"{"), Int -> [Sequent] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Sequent]
sequents, Int -> Line -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Line
line, ShowS -> Doc
doc (String -> ShowS
showString String
";"), Int -> Sequent -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Sequent
sequent, ShowS -> Doc
doc (String -> ShowS
showString String
"}")])

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

instance Print RSTT.Syntax.Abs.RuleName where
  prt :: Int -> RuleName -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.RuleName String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [String -> Doc
printString String
str])

instance Print RSTT.Syntax.Abs.Sequent where
  prt :: Int -> Sequent -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.Sequent CubeContext
cubecontext TopeContext
topecontext Tope
tope -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> CubeContext -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 CubeContext
cubecontext, ShowS -> Doc
doc (String -> ShowS
showString String
"|"), Int -> TopeContext -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 TopeContext
topecontext, ShowS -> Doc
doc (String -> ShowS
showString String
"\8866"), Int -> Tope -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Tope
tope])

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

instance Print RSTT.Syntax.Abs.CubeContext where
  prt :: Int -> CubeContext -> Doc
prt Int
i = \case
    CubeContext
RSTT.Syntax.Abs.CubeContextEmpty -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8901")])
    RSTT.Syntax.Abs.CubeContextNonEmpty [PointDecl]
pointdecls -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [PointDecl] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [PointDecl]
pointdecls])

instance Print RSTT.Syntax.Abs.PointDecl where
  prt :: Int -> PointDecl -> Doc
prt Int
i = \case
    RSTT.Syntax.Abs.PointDecl Var
var Cube
cube -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Var -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Var
var, ShowS -> Doc
doc (String -> ShowS
showString String
":"), Int -> Cube -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cube
cube])

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

instance Print RSTT.Syntax.Abs.TopeContext where
  prt :: Int -> TopeContext -> Doc
prt Int
i = \case
    TopeContext
RSTT.Syntax.Abs.TopeContextEmpty -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8901")])
    RSTT.Syntax.Abs.TopeContextNonEmpty [Tope]
topes -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [Tope] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Tope]
topes])

instance Print RSTT.Syntax.Abs.Tope where
  prt :: Int -> Tope -> Doc
prt Int
i = \case
    Tope
RSTT.Syntax.Abs.TopeTop -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8868")])
    Tope
RSTT.Syntax.Abs.TopeBottom -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8869")])
    RSTT.Syntax.Abs.TopeImplies Tope
tope1 Tope
tope2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Tope -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Tope
tope1, ShowS -> Doc
doc (String -> ShowS
showString String
"\8658"), Int -> Tope -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Tope
tope2])
    RSTT.Syntax.Abs.TopeOr Tope
tope1 Tope
tope2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
1 ([Doc] -> Doc
concatD [Int -> Tope -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Tope
tope1, ShowS -> Doc
doc (String -> ShowS
showString String
"\8744"), Int -> Tope -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Tope
tope2])
    RSTT.Syntax.Abs.TopeAnd Tope
tope1 Tope
tope2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> Tope -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Tope
tope1, ShowS -> Doc
doc (String -> ShowS
showString String
"\8743"), Int -> Tope -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Tope
tope2])
    RSTT.Syntax.Abs.TopeEQ Point
point1 Point
point2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Point -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Point
point1, ShowS -> Doc
doc (String -> ShowS
showString String
"\8801"), Int -> Point -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Point
point2])
    RSTT.Syntax.Abs.TopeCon Label
label [Point]
points -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Label -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label
label, ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> [Point] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Point]
points, ShowS -> Doc
doc (String -> ShowS
showString String
")")])
    RSTT.Syntax.Abs.TopeVar Var
var -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Var -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Var
var])

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

instance Print RSTT.Syntax.Abs.Point where
  prt :: Int -> Point -> Doc
prt Int
i = \case
    Point
RSTT.Syntax.Abs.PointUnit -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8902")])
    RSTT.Syntax.Abs.PointPair Point
point1 Point
point2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\10216"), Int -> Point -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Point
point1, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> Point -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Point
point2, ShowS -> Doc
doc (String -> ShowS
showString String
"\10217")])
    RSTT.Syntax.Abs.PointFirst Point
point -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\960\8321"), ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> Point -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Point
point, ShowS -> Doc
doc (String -> ShowS
showString String
")")])
    RSTT.Syntax.Abs.PointSecond Point
point -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\960\8322"), ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> Point -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Point
point, ShowS -> Doc
doc (String -> ShowS
showString String
")")])
    RSTT.Syntax.Abs.PointCon Label
label [Point]
points -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Label -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label
label, ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> [Point] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Point]
points, ShowS -> Doc
doc (String -> ShowS
showString String
")")])
    RSTT.Syntax.Abs.PointVar Var
var -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Var -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Var
var])

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