{-# LANGUAGE FlexibleContexts, DeriveDataTypeable #-}
{-# OPTIONS_HADDOCK prune #-}
module Language.Pads.PadsPrinter where
import qualified Data.ByteString as B
import qualified Language.Pads.Source as S
import qualified Data.List as List
import Language.Pads.Errors
import Data.Typeable
import Language.Pads.MetaData
import Data.Data
type PadsPrinter a = a -> FList
type FList = B.ByteString -> B.ByteString
(+++) :: FList -> FList -> FList
p +++ q = p . q
nil :: FList
nil = id
concatFL :: [FList] -> FList
concatFL fs = foldr (+++) nil fs
printNothing :: FList
printNothing ws = ws
addBString :: B.ByteString -> FList
addBString bs = B.append bs
addString :: String -> FList
addString s = B.append (S.strToByteString s)
fshow :: Show a => a -> FList
fshow x = B.append (S.strToByteString (show x))
printEOR :: FList
printEOR = addString ['\n']
printEOF :: FList
printEOF = addString []
endRecord :: FList -> FList
endRecord fst = fst +++ printEOR
printF :: FList -> IO ()
printF q = Prelude.print (B.unpack (q B.empty))
printList' (reps, (_,mds)) printItem printSep printTerm = (concatFL (List.intersperse printSep (map printItem (zip reps $ mds ++ repeat myempty))) ) +++ printTerm
printList :: (Data r,Data m) => (PadsPrinter (r,m)) -> FList -> FList -> ([r], (Base_md,[m])) -> FList
printList printItem printSep printTerm (reps, (_,mds)) =
(concatFL (List.intersperse printSep (map printItem (zip reps $ mds ++ repeat myempty))) )
+++ printTerm