{- |
Description: Type class for pretty printing 'AST's.
License: GNU LGPLv3
Maintainer: paul.bittner@uni-ulm.de
Type class for pretty printing 'AST's.
-}
module ASTPrettyPrinter where
import AST
import Grammar
import Util
class Show g => ASTPrettyPrinter g where
prettyPrint :: (Monoid b) => b -> (Node g a -> Int -> b) -> (Node g a -> String -> b) -> (Node g a -> b) -> AST g a -> b
showCode :: (Show a, Grammar g, ASTPrettyPrinter g) => AST g a -> String
showCode :: AST g a -> String
showCode = String
-> (Node g a -> Int -> String)
-> (Node g a -> String -> String)
-> (Node g a -> String)
-> AST g a
-> String
forall b g a.
(Monoid b, ASTPrettyPrinter g) =>
b
-> (Node g a -> Int -> b)
-> (Node g a -> String -> b)
-> (Node g a -> b)
-> AST g a
-> b
showCodeAs "" (\_ i :: Int
i -> Int -> String
genIndent Int
i) (\_ s :: String
s -> String
s) Node g a -> String
forall a. Show a => a -> String
show
showCodeAs :: (Monoid b, ASTPrettyPrinter g) => b -> (Node g a -> Int -> b) -> (Node g a -> String -> b) -> (Node g a -> b) -> AST g a -> b
showCodeAs :: b
-> (Node g a -> Int -> b)
-> (Node g a -> String -> b)
-> (Node g a -> b)
-> AST g a
-> b
showCodeAs = b
-> (Node g a -> Int -> b)
-> (Node g a -> String -> b)
-> (Node g a -> b)
-> AST g a
-> b
forall g b a.
(ASTPrettyPrinter g, Monoid b) =>
b
-> (Node g a -> Int -> b)
-> (Node g a -> String -> b)
-> (Node g a -> b)
-> AST g a
-> b
prettyPrint