{-
Copyright EO/Polystat Development Team (c) 2023

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * Neither the name of EO/Polystat Development Team nor the names of other
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-}

-- 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.EO.Phi.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.EO.Phi.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.EO.Phi.Syntax.Abs.Bytes where
  prt :: Int -> Bytes -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.Bytes String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.Function where
  prt :: Int -> Function -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.Function String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.LabelId where
  prt :: Int -> LabelId -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.LabelId String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.AlphaIndex where
  prt :: Int -> AlphaIndex -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.AlphaIndex String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.LabelMetaId where
  prt :: Int -> LabelMetaId -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.LabelMetaId String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.TailMetaId where
  prt :: Int -> TailMetaId -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.TailMetaId String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.BindingsMetaId where
  prt :: Int -> BindingsMetaId -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.BindingsMetaId String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.ObjectMetaId where
  prt :: Int -> ObjectMetaId -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.ObjectMetaId String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.BytesMetaId where
  prt :: Int -> BytesMetaId -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.BytesMetaId String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.MetaFunctionName where
  prt :: Int -> MetaFunctionName -> Doc
prt Int
_ (Language.EO.Phi.Syntax.Abs.MetaFunctionName String
i) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
i
instance Print Language.EO.Phi.Syntax.Abs.Program where
  prt :: Int -> Program -> Doc
prt Int
i = \case
    Language.EO.Phi.Syntax.Abs.Program [Binding]
bindings -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"{"), ShowS -> Doc
doc (String -> ShowS
showString String
"\10214"), Int -> [Binding] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Binding]
bindings, ShowS -> Doc
doc (String -> ShowS
showString String
"\10215"), ShowS -> Doc
doc (String -> ShowS
showString String
"}")])

instance Print Language.EO.Phi.Syntax.Abs.MetaId where
  prt :: Int -> MetaId -> Doc
prt Int
i = \case
    Language.EO.Phi.Syntax.Abs.MetaIdLabel LabelMetaId
labelmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> LabelMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 LabelMetaId
labelmetaid])
    Language.EO.Phi.Syntax.Abs.MetaIdTail TailMetaId
tailmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> TailMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 TailMetaId
tailmetaid])
    Language.EO.Phi.Syntax.Abs.MetaIdBindings BindingsMetaId
bindingsmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> BindingsMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 BindingsMetaId
bindingsmetaid])
    Language.EO.Phi.Syntax.Abs.MetaIdObject ObjectMetaId
objectmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> ObjectMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ObjectMetaId
objectmetaid])
    Language.EO.Phi.Syntax.Abs.MetaIdBytes BytesMetaId
bytesmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> BytesMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 BytesMetaId
bytesmetaid])

instance Print Language.EO.Phi.Syntax.Abs.Object where
  prt :: Int -> Object -> Doc
prt Int
i = \case
    Language.EO.Phi.Syntax.Abs.Formation [Binding]
bindings -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\10214"), Int -> [Binding] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Binding]
bindings, ShowS -> Doc
doc (String -> ShowS
showString String
"\10215")])
    Language.EO.Phi.Syntax.Abs.Application Object
object [Binding]
bindings -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object, ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> [Binding] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Binding]
bindings, ShowS -> Doc
doc (String -> ShowS
showString String
")")])
    Language.EO.Phi.Syntax.Abs.ObjectDispatch Object
object Attribute
attribute -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object, ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> Attribute -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Attribute
attribute])
    Object
Language.EO.Phi.Syntax.Abs.GlobalObject -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\934")])
    Object
Language.EO.Phi.Syntax.Abs.ThisObject -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\958")])
    Object
Language.EO.Phi.Syntax.Abs.Termination -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8869")])
    Language.EO.Phi.Syntax.Abs.MetaSubstThis Object
object1 Object
object2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object1, ShowS -> Doc
doc (String -> ShowS
showString String
"["), ShowS -> Doc
doc (String -> ShowS
showString String
"\958"), ShowS -> Doc
doc (String -> ShowS
showString String
"\8614"), Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object2, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])
    Language.EO.Phi.Syntax.Abs.MetaContextualize Object
object1 Object
object2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8968"), Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object1, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object2, ShowS -> Doc
doc (String -> ShowS
showString String
"\8969")])
    Language.EO.Phi.Syntax.Abs.MetaObject ObjectMetaId
objectmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> ObjectMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ObjectMetaId
objectmetaid])
    Language.EO.Phi.Syntax.Abs.MetaTailContext Object
object TailMetaId
tailmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object, ShowS -> Doc
doc (String -> ShowS
showString String
"*"), Int -> TailMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 TailMetaId
tailmetaid])
    Language.EO.Phi.Syntax.Abs.MetaFunction MetaFunctionName
metafunctionname Object
object -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> MetaFunctionName -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MetaFunctionName
metafunctionname, ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object, ShowS -> Doc
doc (String -> ShowS
showString String
")")])

instance Print Language.EO.Phi.Syntax.Abs.Binding where
  prt :: Int -> Binding -> Doc
prt Int
i = \case
    Language.EO.Phi.Syntax.Abs.AlphaBinding Attribute
attribute Object
object -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Attribute -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Attribute
attribute, ShowS -> Doc
doc (String -> ShowS
showString String
"\8614"), Int -> Object -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Object
object])
    Language.EO.Phi.Syntax.Abs.EmptyBinding Attribute
attribute -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Attribute -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Attribute
attribute, ShowS -> Doc
doc (String -> ShowS
showString String
"\8614"), ShowS -> Doc
doc (String -> ShowS
showString String
"\8709")])
    Language.EO.Phi.Syntax.Abs.DeltaBinding Bytes
bytes -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\916"), ShowS -> Doc
doc (String -> ShowS
showString String
"\10509"), Int -> Bytes -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Bytes
bytes])
    Binding
Language.EO.Phi.Syntax.Abs.DeltaEmptyBinding -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\916"), ShowS -> Doc
doc (String -> ShowS
showString String
"\10509"), ShowS -> Doc
doc (String -> ShowS
showString String
"\8709")])
    Language.EO.Phi.Syntax.Abs.LambdaBinding Function
function -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\955"), ShowS -> Doc
doc (String -> ShowS
showString String
"\10509"), Int -> Function -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Function
function])
    Language.EO.Phi.Syntax.Abs.MetaBindings BindingsMetaId
bindingsmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> BindingsMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 BindingsMetaId
bindingsmetaid])
    Language.EO.Phi.Syntax.Abs.MetaDeltaBinding BytesMetaId
bytesmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\916"), ShowS -> Doc
doc (String -> ShowS
showString String
"\10509"), Int -> BytesMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 BytesMetaId
bytesmetaid])

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

instance Print Language.EO.Phi.Syntax.Abs.Attribute where
  prt :: Int -> Attribute -> Doc
prt Int
i = \case
    Attribute
Language.EO.Phi.Syntax.Abs.Phi -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\966")])
    Attribute
Language.EO.Phi.Syntax.Abs.Rho -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\961")])
    Language.EO.Phi.Syntax.Abs.Label LabelId
labelid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> LabelId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 LabelId
labelid])
    Language.EO.Phi.Syntax.Abs.Alpha AlphaIndex
alphaindex -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> AlphaIndex -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 AlphaIndex
alphaindex])
    Language.EO.Phi.Syntax.Abs.MetaAttr LabelMetaId
labelmetaid -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> LabelMetaId -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 LabelMetaId
labelmetaid])

instance Print Language.EO.Phi.Syntax.Abs.RuleAttribute where
  prt :: Int -> RuleAttribute -> Doc
prt Int
i = \case
    Language.EO.Phi.Syntax.Abs.ObjectAttr Attribute
attribute -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Attribute -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Attribute
attribute])
    RuleAttribute
Language.EO.Phi.Syntax.Abs.DeltaAttr -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\916")])
    RuleAttribute
Language.EO.Phi.Syntax.Abs.LambdaAttr -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\955")])

instance Print Language.EO.Phi.Syntax.Abs.PeeledObject where
  prt :: Int -> PeeledObject -> Doc
prt Int
i = \case
    Language.EO.Phi.Syntax.Abs.PeeledObject ObjectHead
objecthead [ObjectAction]
objectactions -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> ObjectHead -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 ObjectHead
objecthead, Int -> [ObjectAction] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [ObjectAction]
objectactions])

instance Print Language.EO.Phi.Syntax.Abs.ObjectHead where
  prt :: Int -> ObjectHead -> Doc
prt Int
i = \case
    Language.EO.Phi.Syntax.Abs.HeadFormation [Binding]
bindings -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\10214"), Int -> [Binding] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Binding]
bindings, ShowS -> Doc
doc (String -> ShowS
showString String
"\10215")])
    ObjectHead
Language.EO.Phi.Syntax.Abs.HeadGlobal -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\934")])
    ObjectHead
Language.EO.Phi.Syntax.Abs.HeadThis -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\958")])
    ObjectHead
Language.EO.Phi.Syntax.Abs.HeadTermination -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"\8869")])

instance Print Language.EO.Phi.Syntax.Abs.ObjectAction where
  prt :: Int -> ObjectAction -> Doc
prt Int
i = \case
    Language.EO.Phi.Syntax.Abs.ActionApplication [Binding]
bindings -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"("), Int -> [Binding] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Binding]
bindings, ShowS -> Doc
doc (String -> ShowS
showString String
")")])
    Language.EO.Phi.Syntax.Abs.ActionDispatch Attribute
attribute -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> Attribute -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Attribute
attribute])

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