{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ <= 708
{-# LANGUAGE OverlappingInstances #-}
#endif
{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}

-- | Pretty-printer for BNFC.
--   Generated by the BNF converter.

module BNFC.Print where

import qualified BNFC.Abs
import Data.Char

-- | The top-level printing method.

printTree :: Print a => a -> String
printTree :: 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 -> [String] -> ShowS
rend Int
0 ((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 -> [String] -> ShowS
rend Int
i [String]
ss = case [String]
ss of
    String
"["      :[String]
ts -> Char -> ShowS
showChar Char
'[' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
rend Int
i [String]
ts
    String
"("      :[String]
ts -> Char -> ShowS
showChar Char
'(' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
rend Int
i [String]
ts
    String
"{"      :[String]
ts -> Char -> ShowS
showChar Char
'{' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
new (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
rend (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) [String]
ts
    String
"}" : String
";":[String]
ts -> Int -> ShowS
new (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
space String
"}" 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 -> ShowS
new (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
rend (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) [String]
ts
    String
"}"      :[String]
ts -> Int -> ShowS
new (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) 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 -> ShowS
new (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
rend (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) [String]
ts
    [String
";"]        -> Char -> ShowS
showChar Char
';'
    String
";"      :[String]
ts -> Char -> ShowS
showChar Char
';' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
new Int
i ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
rend Int
i [String]
ts
    String
t  : ts :: [String]
ts@(String
p:[String]
_) | String -> Bool
closingOrPunctuation String
p -> String -> ShowS
showString String
t ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
rend Int
i [String]
ts
    String
t        :[String]
ts -> String -> ShowS
space String
t ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [String] -> ShowS
rend Int
i [String]
ts
    [String]
_            -> ShowS
forall a. a -> a
id
  new :: Int -> ShowS
new Int
i     = Char -> ShowS
showChar Char
'\n' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS -> ShowS
replicateS (Int
2Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
i) (Char -> ShowS
showChar Char
' ') ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace
  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
  prtList :: Int -> [a] -> Doc
  prtList 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 {-# OVERLAPPABLE #-} Print a => Print [a] where
  prt :: Int -> [a] -> Doc
prt = Int -> [a] -> Doc
forall a. Print a => Int -> [a] -> Doc
prtList

instance Print Char where
  prt :: Int -> Char -> Doc
prt Int
_ Char
s = 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
s ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'\'')
  prtList :: Int -> String -> Doc
prtList Int
_ 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 Char
s = case Char
s of
  Char
_ | 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
_ -> 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 BNFC.Abs.Identifier where
  prt :: Int -> Identifier -> Doc
prt Int
_ (BNFC.Abs.Identifier ((Int, Int)
_,String
i)) = ShowS -> Doc
doc (ShowS -> Doc) -> ShowS -> Doc
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString (String -> ShowS) -> String -> ShowS
forall a b. (a -> b) -> a -> b
$ String
i

instance Print BNFC.Abs.Grammar where
  prt :: Int -> Grammar -> Doc
prt Int
i Grammar
e = case Grammar
e of
    BNFC.Abs.Grammar [Def]
defs -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [Def] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Def]
defs])

instance Print [BNFC.Abs.Def] where
  prt :: Int -> [Def] -> Doc
prt = Int -> [Def] -> Doc
forall a. Print a => Int -> [a] -> Doc
prtList

instance Print BNFC.Abs.Def where
  prt :: Int -> Def -> Doc
prt Int
i Def
e = case Def
e of
    BNFC.Abs.Rule Label
label Cat
cat [Item]
items -> 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 -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
cat, ShowS -> Doc
doc (String -> ShowS
showString String
"::="), Int -> [Item] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Item]
items])
    BNFC.Abs.Comment String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"comment"), Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str])
    BNFC.Abs.Comments String
str1 String
str2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"comment"), Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str1, Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str2])
    BNFC.Abs.Internal Label
label Cat
cat [Item]
items -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"internal"), Int -> Label -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label
label, ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
cat, ShowS -> Doc
doc (String -> ShowS
showString String
"::="), Int -> [Item] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Item]
items])
    BNFC.Abs.Token Identifier
identifier Reg
reg -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"token"), Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier, Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Reg
reg])
    BNFC.Abs.PosToken Identifier
identifier Reg
reg -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"position"), ShowS -> Doc
doc (String -> ShowS
showString String
"token"), Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier, Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Reg
reg])
    BNFC.Abs.Entryp [Cat]
cats -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"entrypoints"), Int -> [Cat] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Cat]
cats])
    BNFC.Abs.Separator MinimumSize
minimumsize Cat
cat String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"separator"), Int -> MinimumSize -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MinimumSize
minimumsize, Int -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
cat, Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str])
    BNFC.Abs.Terminator MinimumSize
minimumsize Cat
cat String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"terminator"), Int -> MinimumSize -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MinimumSize
minimumsize, Int -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
cat, Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str])
    BNFC.Abs.Delimiters Cat
cat String
str1 String
str2 Separation
separation MinimumSize
minimumsize -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"delimiters"), Int -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
cat, Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str1, Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str2, Int -> Separation -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Separation
separation, Int -> MinimumSize -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MinimumSize
minimumsize])
    BNFC.Abs.Coercions Identifier
identifier Integer
n -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"coercions"), Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier, Int -> Integer -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Integer
n])
    BNFC.Abs.Rules Identifier
identifier [RHS]
rhss -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"rules"), Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier, ShowS -> Doc
doc (String -> ShowS
showString String
"::="), Int -> [RHS] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [RHS]
rhss])
    BNFC.Abs.Function Identifier
identifier [Arg]
args Exp
exp -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"define"), Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier, Int -> [Arg] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Arg]
args, ShowS -> Doc
doc (String -> ShowS
showString String
"="), Int -> Exp -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Exp
exp])
    BNFC.Abs.Layout [String]
strs -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"layout"), Int -> [String] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [String]
strs])
    BNFC.Abs.LayoutStop [String]
strs -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"layout"), ShowS -> Doc
doc (String -> ShowS
showString String
"stop"), Int -> [String] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [String]
strs])
    Def
BNFC.Abs.LayoutTop -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"layout"), ShowS -> Doc
doc (String -> ShowS
showString String
"toplevel")])
  prtList :: Int -> [Def] -> Doc
prtList Int
_ [] = [Doc] -> Doc
concatD []
  prtList Int
_ [Def
x] = [Doc] -> Doc
concatD [Int -> Def -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Def
x]

  prtList Int
_ (Def
x:[Def]
xs) = [Doc] -> Doc
concatD [Int -> Def -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Def
x, ShowS -> Doc
doc (String -> ShowS
showString String
";"), Int -> [Def] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Def]
xs]

instance Print BNFC.Abs.Item where
  prt :: Int -> Item -> Doc
prt Int
i Item
e = case Item
e of
    BNFC.Abs.Terminal String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str])
    BNFC.Abs.NTerminal Cat
cat -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
cat])
  prtList :: Int -> [Item] -> Doc
prtList Int
_ [] = [Doc] -> Doc
concatD []
  prtList Int
_ (Item
x:[Item]
xs) = [Doc] -> Doc
concatD [Int -> Item -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Item
x, Int -> [Item] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Item]
xs]

instance Print [BNFC.Abs.Item] where
  prt :: Int -> [Item] -> Doc
prt = Int -> [Item] -> Doc
forall a. Print a => Int -> [a] -> Doc
prtList

instance Print BNFC.Abs.Cat where
  prt :: Int -> Cat -> Doc
prt Int
i Cat
e = case Cat
e of
    BNFC.Abs.ListCat Cat
cat -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
cat, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])
    BNFC.Abs.IdCat Identifier
identifier -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier])
  prtList :: Int -> [Cat] -> Doc
prtList Int
_ [] = [Doc] -> Doc
concatD []
  prtList Int
_ [Cat
x] = [Doc] -> Doc
concatD [Int -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
x]
  prtList Int
_ (Cat
x:[Cat]
xs) = [Doc] -> Doc
concatD [Int -> Cat -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [Cat] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Cat]
xs]

instance Print [BNFC.Abs.Cat] where
  prt :: Int -> [Cat] -> Doc
prt = Int -> [Cat] -> Doc
forall a. Print a => Int -> [a] -> Doc
prtList

instance Print BNFC.Abs.Label where
  prt :: Int -> Label -> Doc
prt Int
i Label
e = case Label
e of
    BNFC.Abs.Id Identifier
identifier -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier])
    Label
BNFC.Abs.Wild -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"_")])
    Label
BNFC.Abs.ListE -> 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
"]")])
    Label
BNFC.Abs.ListCons -> 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
":"), ShowS -> Doc
doc (String -> ShowS
showString String
")")])
    Label
BNFC.Abs.ListOne -> 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
":"), ShowS -> Doc
doc (String -> ShowS
showString String
"["), ShowS -> Doc
doc (String -> ShowS
showString String
"]"), ShowS -> Doc
doc (String -> ShowS
showString String
")")])

instance Print BNFC.Abs.Arg where
  prt :: Int -> Arg -> Doc
prt Int
i Arg
e = case Arg
e of
    BNFC.Abs.Arg Identifier
identifier -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier])
  prtList :: Int -> [Arg] -> Doc
prtList Int
_ [] = [Doc] -> Doc
concatD []
  prtList Int
_ (Arg
x:[Arg]
xs) = [Doc] -> Doc
concatD [Int -> Arg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Arg
x, Int -> [Arg] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Arg]
xs]

instance Print [BNFC.Abs.Arg] where
  prt :: Int -> [Arg] -> Doc
prt = Int -> [Arg] -> Doc
forall a. Print a => Int -> [a] -> Doc
prtList

instance Print BNFC.Abs.Separation where
  prt :: Int -> Separation -> Doc
prt Int
i Separation
e = case Separation
e of
    Separation
BNFC.Abs.SepNone -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [])
    BNFC.Abs.SepTerm String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"terminator"), Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str])
    BNFC.Abs.SepSepar String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"separator"), Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str])

instance Print [String] where
  prt :: Int -> [String] -> Doc
prt = Int -> [String] -> Doc
forall a. Print a => Int -> [a] -> Doc
prtList

instance Print BNFC.Abs.Exp where
  prt :: Int -> Exp -> Doc
prt Int
i Exp
e = case Exp
e of
    BNFC.Abs.Cons Exp
exp1 Exp
exp2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Exp -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Exp
exp1, ShowS -> Doc
doc (String -> ShowS
showString String
":"), Int -> Exp -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Exp
exp2])
    BNFC.Abs.App Identifier
identifier [Exp]
exps -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
1 ([Doc] -> Doc
concatD [Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier, Int -> [Exp] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 [Exp]
exps])
    BNFC.Abs.Var Identifier
identifier -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> Identifier -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Identifier
identifier])
    BNFC.Abs.LitInt Integer
n -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> Integer -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Integer
n])
    BNFC.Abs.LitChar Char
c -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> Char -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Char
c])
    BNFC.Abs.LitString String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str])
    BNFC.Abs.LitDouble Double
d -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> Double -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Double
d])
    BNFC.Abs.List [Exp]
exps -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> [Exp] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Exp]
exps, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])
  prtList :: Int -> [Exp] -> Doc
prtList Int
2 [Exp
x] = [Doc] -> Doc
concatD [Int -> Exp -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Exp
x]
  prtList Int
2 (Exp
x:[Exp]
xs) = [Doc] -> Doc
concatD [Int -> Exp -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Exp
x, Int -> [Exp] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 [Exp]
xs]
  prtList Int
_ [] = [Doc] -> Doc
concatD []
  prtList Int
_ [Exp
x] = [Doc] -> Doc
concatD [Int -> Exp -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Exp
x]
  prtList Int
_ (Exp
x:[Exp]
xs) = [Doc] -> Doc
concatD [Int -> Exp -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Exp
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [Exp] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Exp]
xs]

instance Print [BNFC.Abs.Exp] where
  prt :: Int -> [Exp] -> Doc
prt = Int -> [Exp] -> Doc
forall a. Print a => Int -> [a] -> Doc
prtList

instance Print BNFC.Abs.RHS where
  prt :: Int -> RHS -> Doc
prt Int
i RHS
e = case RHS
e of
    BNFC.Abs.RHS [Item]
items -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [Item] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Item]
items])
  prtList :: Int -> [RHS] -> Doc
prtList Int
_ [RHS
x] = [Doc] -> Doc
concatD [Int -> RHS -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 RHS
x]
  prtList Int
_ (RHS
x:[RHS]
xs) = [Doc] -> Doc
concatD [Int -> RHS -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 RHS
x, ShowS -> Doc
doc (String -> ShowS
showString String
"|"), Int -> [RHS] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [RHS]
xs]

instance Print [BNFC.Abs.RHS] where
  prt :: Int -> [RHS] -> Doc
prt = Int -> [RHS] -> Doc
forall a. Print a => Int -> [a] -> Doc
prtList

instance Print BNFC.Abs.MinimumSize where
  prt :: Int -> MinimumSize -> Doc
prt Int
i MinimumSize
e = case MinimumSize
e of
    MinimumSize
BNFC.Abs.MNonempty -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"nonempty")])
    MinimumSize
BNFC.Abs.MEmpty -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [])

instance Print BNFC.Abs.Reg where
  prt :: Int -> Reg -> Doc
prt Int
i Reg
e = case Reg
e of
    BNFC.Abs.RAlt Reg
reg1 Reg
reg2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Reg
reg1, ShowS -> Doc
doc (String -> ShowS
showString String
"|"), Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Reg
reg2])
    BNFC.Abs.RMinus Reg
reg1 Reg
reg2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
1 ([Doc] -> Doc
concatD [Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Reg
reg1, ShowS -> Doc
doc (String -> ShowS
showString String
"-"), Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Reg
reg2])
    BNFC.Abs.RSeq Reg
reg1 Reg
reg2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Reg
reg1, Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Reg
reg2])
    BNFC.Abs.RStar Reg
reg -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Reg
reg, ShowS -> Doc
doc (String -> ShowS
showString String
"*")])
    BNFC.Abs.RPlus Reg
reg -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Reg
reg, ShowS -> Doc
doc (String -> ShowS
showString String
"+")])
    BNFC.Abs.ROpt Reg
reg -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Reg -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Reg
reg, ShowS -> Doc
doc (String -> ShowS
showString String
"?")])
    Reg
BNFC.Abs.REps -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"eps")])
    BNFC.Abs.RChar Char
c -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Char -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Char
c])
    BNFC.Abs.RAlts String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])
    BNFC.Abs.RSeqs String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"{"), Int -> String -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 String
str, ShowS -> Doc
doc (String -> ShowS
showString String
"}")])
    Reg
BNFC.Abs.RDigit -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"digit")])
    Reg
BNFC.Abs.RLetter -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"letter")])
    Reg
BNFC.Abs.RUpper -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"upper")])
    Reg
BNFC.Abs.RLower -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"lower")])
    Reg
BNFC.Abs.RAny -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"char")])