{-# LANGUAGE PolyKinds #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Language.Symantic.Typing.Show where

import Data.Semigroup ((<>))
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TLB

import qualified Language.Symantic.Document as D
import Language.Symantic.Grammar
import Language.Symantic.Typing.Type
import Language.Symantic.Typing.Document

showType :: Config_Doc_Type -> Type src vs t -> String
showType conf ty = TL.unpack $ TLB.toLazyText $ D.plain $ docType conf 0 ty

showTypeS :: Config_Doc_Type -> Precedence -> Type src vs t -> ShowS
showTypeS conf pr ty s = s <> TL.unpack (TLB.toLazyText $ D.plain $ docType conf pr ty)

showTypes :: Config_Doc_Type -> Types src vs ts -> String
showTypes conf tys = TL.unpack (TLB.toLazyText $ D.plain $ docTypes conf tys)

showTypesS :: Config_Doc_Type -> Types src vs ts -> ShowS
showTypesS conf tys s = s <> TL.unpack (TLB.toLazyText $ D.plain $ docTypes conf tys)

instance Source src => Show (Type src vs t) where
	showsPrec = showTypeS config_doc_type
instance Source src => Show (TypeK src vs kt) where
	showsPrec p (TypeK t) = showsPrec p t
instance Source src => Show (TypeVT src) where
	showsPrec p (TypeVT t) = showsPrec p t
instance Source src => Show (TypeT src vs) where
	showsPrec p (TypeT t) = showsPrec p t
instance Source src => Show (Types src vs ts) where
	showsPrec _ = showTypesS config_doc_type