{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
#if __GLASGOW_HASKELL__ <= 708
{-# LANGUAGE OverlappingInstances #-}
#endif
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
module BNFC.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 BNFC.Abs
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 -> 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
-> Bool
-> [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 -> 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
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
pending :: ShowS
pending :: ShowS
pending = if Bool
p then Int -> ShowS
indent Int
i else ShowS
forall a. a -> a
id
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
' ')
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
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
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 ) -> []
(Bool
False, Bool
_ , Bool
True ) -> String
t'
(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
(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)
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 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
i
instance Print (BNFC.Abs.Grammar' a) where
prt :: Int -> Grammar' a -> Doc
prt Int
i = \case
BNFC.Abs.Grammar a
_ [Def' a]
defs -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [Def' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Def' a]
defs])
instance Print [BNFC.Abs.Def' a] where
prt :: Int -> [Def' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
prt Int
_ [Def' a
x] = [Doc] -> Doc
concatD [Int -> Def' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Def' a
x]
prt Int
_ (Def' a
x:[Def' a]
xs) = [Doc] -> Doc
concatD [Int -> Def' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Def' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
";"), Int -> [Def' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Def' a]
xs]
instance Print (BNFC.Abs.Def' a) where
prt :: Int -> Def' a -> Doc
prt Int
i = \case
BNFC.Abs.Rule a
_ Label' a
label Cat' a
cat RHS' a
rhs -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Label' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label' a
label, ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
cat, ShowS -> Doc
doc (String -> ShowS
showString String
"::="), Int -> RHS' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 RHS' a
rhs])
BNFC.Abs.Comment a
_ String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"comment"), String -> Doc
printString String
str])
BNFC.Abs.Comments a
_ String
str1 String
str2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"comment"), String -> Doc
printString String
str1, String -> Doc
printString String
str2])
BNFC.Abs.Internal a
_ Label' a
label Cat' a
cat RHS' a
rhs -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"internal"), Int -> Label' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Label' a
label, ShowS -> Doc
doc (String -> ShowS
showString String
"."), Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
cat, ShowS -> Doc
doc (String -> ShowS
showString String
"::="), Int -> RHS' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 RHS' a
rhs])
BNFC.Abs.Token a
_ Identifier
identifier Reg' a
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' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Reg' a
reg])
BNFC.Abs.PosToken a
_ Identifier
identifier Reg' a
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' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Reg' a
reg])
BNFC.Abs.Entryp a
_ [Cat' a]
cats -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"entrypoints"), Int -> [Cat' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Cat' a]
cats])
BNFC.Abs.Separator a
_ MinimumSize' a
minimumsize Cat' a
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' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MinimumSize' a
minimumsize, Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
cat, String -> Doc
printString String
str])
BNFC.Abs.Terminator a
_ MinimumSize' a
minimumsize Cat' a
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' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MinimumSize' a
minimumsize, Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
cat, String -> Doc
printString String
str])
BNFC.Abs.Delimiters a
_ Cat' a
cat String
str1 String
str2 Separation' a
separation MinimumSize' a
minimumsize -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"delimiters"), Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
cat, String -> Doc
printString String
str1, String -> Doc
printString String
str2, Int -> Separation' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Separation' a
separation, Int -> MinimumSize' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 MinimumSize' a
minimumsize])
BNFC.Abs.Coercions a
_ 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 a
_ Identifier
identifier [RHS' a]
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' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [RHS' a]
rhss])
BNFC.Abs.Function a
_ Identifier
identifier [Arg' a]
args Exp' a
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' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Arg' a]
args, ShowS -> Doc
doc (String -> ShowS
showString String
"="), Int -> Exp' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Exp' a
exp])
BNFC.Abs.Layout a
_ [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 a
_ [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])
BNFC.Abs.LayoutTop a
_ -> 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")])
instance Print (BNFC.Abs.Item' a) where
prt :: Int -> Item' a -> Doc
prt Int
i = \case
BNFC.Abs.Terminal a
_ String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [String -> Doc
printString String
str])
BNFC.Abs.NTerminal a
_ Cat' a
cat -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
cat])
instance Print [BNFC.Abs.Item' a] where
prt :: Int -> [Item' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
prt Int
_ (Item' a
x:[Item' a]
xs) = [Doc] -> Doc
concatD [Int -> Item' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Item' a
x, Int -> [Item' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Item' a]
xs]
instance Print (BNFC.Abs.Cat' a) where
prt :: Int -> Cat' a -> Doc
prt Int
i = \case
BNFC.Abs.ListCat a
_ Cat' a
cat -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
cat, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])
BNFC.Abs.IdCat a
_ 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])
instance Print [BNFC.Abs.Cat' a] where
prt :: Int -> [Cat' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
prt Int
_ [Cat' a
x] = [Doc] -> Doc
concatD [Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
x]
prt Int
_ (Cat' a
x:[Cat' a]
xs) = [Doc] -> Doc
concatD [Int -> Cat' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Cat' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [Cat' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Cat' a]
xs]
instance Print (BNFC.Abs.Label' a) where
prt :: Int -> Label' a -> Doc
prt Int
i = \case
BNFC.Abs.Id a
_ 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])
BNFC.Abs.Wild a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"_")])
BNFC.Abs.ListEmpty a
_ -> 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
"]")])
BNFC.Abs.ListCons a
_ -> 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
")")])
BNFC.Abs.ListOne a
_ -> 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' a) where
prt :: Int -> Arg' a -> Doc
prt Int
i = \case
BNFC.Abs.Arg a
_ 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])
instance Print [BNFC.Abs.Arg' a] where
prt :: Int -> [Arg' a] -> Doc
prt Int
_ [] = [Doc] -> Doc
concatD []
prt Int
_ (Arg' a
x:[Arg' a]
xs) = [Doc] -> Doc
concatD [Int -> Arg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Arg' a
x, Int -> [Arg' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Arg' a]
xs]
instance Print (BNFC.Abs.Separation' a) where
prt :: Int -> Separation' a -> Doc
prt Int
i = \case
BNFC.Abs.SepNone a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [])
BNFC.Abs.SepTerm a
_ String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"terminator"), String -> Doc
printString String
str])
BNFC.Abs.SepSepar a
_ String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"separator"), String -> Doc
printString String
str])
instance Print [String] where
prt :: Int -> [String] -> Doc
prt Int
_ [String
x] = [Doc] -> Doc
concatD [String -> Doc
printString String
x]
prt Int
_ (String
x:[String]
xs) = [Doc] -> Doc
concatD [String -> Doc
printString String
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [String] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [String]
xs]
instance Print (BNFC.Abs.Exp' a) where
prt :: Int -> Exp' a -> Doc
prt Int
i = \case
BNFC.Abs.Cons a
_ Exp' a
exp1 Exp' a
exp2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Exp' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Exp' a
exp1, ShowS -> Doc
doc (String -> ShowS
showString String
":"), Int -> Exp' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Exp' a
exp2])
BNFC.Abs.App a
_ Identifier
identifier [Exp' a]
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' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 [Exp' a]
exps])
BNFC.Abs.Var a
_ 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.LitInteger a
_ 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 a
_ 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 a
_ String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [String -> Doc
printString String
str])
BNFC.Abs.LitDouble a
_ 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 a
_ [Exp' a]
exps -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"["), Int -> [Exp' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Exp' a]
exps, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])
instance Print [BNFC.Abs.Exp' a] where
prt :: Int -> [Exp' a] -> Doc
prt Int
2 [Exp' a
x] = [Doc] -> Doc
concatD [Int -> Exp' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Exp' a
x]
prt Int
2 (Exp' a
x:[Exp' a]
xs) = [Doc] -> Doc
concatD [Int -> Exp' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Exp' a
x, Int -> [Exp' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 [Exp' a]
xs]
prt Int
_ [] = [Doc] -> Doc
concatD []
prt Int
_ [Exp' a
x] = [Doc] -> Doc
concatD [Int -> Exp' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Exp' a
x]
prt Int
_ (Exp' a
x:[Exp' a]
xs) = [Doc] -> Doc
concatD [Int -> Exp' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Exp' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
","), Int -> [Exp' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Exp' a]
xs]
instance Print (BNFC.Abs.RHS' a) where
prt :: Int -> RHS' a -> Doc
prt Int
i = \case
BNFC.Abs.RHS a
_ [Item' a]
items -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> [Item' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [Item' a]
items])
instance Print [BNFC.Abs.RHS' a] where
prt :: Int -> [RHS' a] -> Doc
prt Int
_ [RHS' a
x] = [Doc] -> Doc
concatD [Int -> RHS' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 RHS' a
x]
prt Int
_ (RHS' a
x:[RHS' a]
xs) = [Doc] -> Doc
concatD [Int -> RHS' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 RHS' a
x, ShowS -> Doc
doc (String -> ShowS
showString String
"|"), Int -> [RHS' a] -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 [RHS' a]
xs]
instance Print (BNFC.Abs.MinimumSize' a) where
prt :: Int -> MinimumSize' a -> Doc
prt Int
i = \case
BNFC.Abs.MNonEmpty a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"nonempty")])
BNFC.Abs.MEmpty a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [])
instance Print (BNFC.Abs.Reg' a) where
prt :: Int -> Reg' a -> Doc
prt Int
i = \case
BNFC.Abs.RAlt a
_ Reg' a
reg1 Reg' a
reg2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
0 ([Doc] -> Doc
concatD [Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
0 Reg' a
reg1, ShowS -> Doc
doc (String -> ShowS
showString String
"|"), Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Reg' a
reg2])
BNFC.Abs.RMinus a
_ Reg' a
reg1 Reg' a
reg2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
1 ([Doc] -> Doc
concatD [Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
1 Reg' a
reg1, ShowS -> Doc
doc (String -> ShowS
showString String
"-"), Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Reg' a
reg2])
BNFC.Abs.RSeq a
_ Reg' a
reg1 Reg' a
reg2 -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
2 ([Doc] -> Doc
concatD [Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
2 Reg' a
reg1, Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Reg' a
reg2])
BNFC.Abs.RStar a
_ Reg' a
reg -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Reg' a
reg, ShowS -> Doc
doc (String -> ShowS
showString String
"*")])
BNFC.Abs.RPlus a
_ Reg' a
reg -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Reg' a
reg, ShowS -> Doc
doc (String -> ShowS
showString String
"+")])
BNFC.Abs.ROpt a
_ Reg' a
reg -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [Int -> Reg' a -> Doc
forall a. Print a => Int -> a -> Doc
prt Int
3 Reg' a
reg, ShowS -> Doc
doc (String -> ShowS
showString String
"?")])
BNFC.Abs.REps a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"eps")])
BNFC.Abs.RChar a
_ 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 a
_ String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"["), String -> Doc
printString String
str, ShowS -> Doc
doc (String -> ShowS
showString String
"]")])
BNFC.Abs.RSeqs a
_ String
str -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"{"), String -> Doc
printString String
str, ShowS -> Doc
doc (String -> ShowS
showString String
"}")])
BNFC.Abs.RDigit a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"digit")])
BNFC.Abs.RLetter a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"letter")])
BNFC.Abs.RUpper a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"upper")])
BNFC.Abs.RLower a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"lower")])
BNFC.Abs.RAny a
_ -> Int -> Int -> Doc -> Doc
prPrec Int
i Int
3 ([Doc] -> Doc
concatD [ShowS -> Doc
doc (String -> ShowS
showString String
"char")])