{-# LANGUAGE DefaultSignatures, FlexibleInstances #-}

module Little.Earley.Internal.Pretty where


-- | A class for ad hoc pretty-printers.
class PrettyPrint a where
  prettyPrint :: a -> String

  default prettyPrint :: Show a => a -> String
  prettyPrint = a -> String
forall a. Show a => a -> String
show

-- | Display the character without quotes.
instance PrettyPrint Char where
  prettyPrint :: Char -> String
prettyPrint = (Char -> String -> String
forall a. a -> [a] -> [a]
: [])

-- | Display the string without quotes.
instance PrettyPrint String where
  prettyPrint :: String -> String
prettyPrint = String -> String
forall a. a -> a
id


-- | Wrapper whose 'Show' instance uses 'PrettyPrint'.
--
-- This provides a convenient and explicit way to display results nicely in the
-- REPL. See also 'Little.Earley.pparse'.
newtype Pretty a = Pretty a

instance PrettyPrint a => Show (Pretty a) where
  show :: Pretty a -> String
show (Pretty a
a) = a -> String
forall a. PrettyPrint a => a -> String
prettyPrint a
a