module HIndent.Types
(Printer(..)
,PrintState(..)
,Config(..)
,defaultConfig
,NodeInfo(..)
,NodeComment(..)
) where
import Control.Applicative
import Control.Monad
import Control.Monad.State.Strict (MonadState(..),StateT)
import Control.Monad.Trans.Maybe
import Data.ByteString.Builder
import Data.Functor.Identity
import Data.Int (Int64)
import Language.Haskell.Exts.SrcLoc
newtype Printer a =
Printer {runPrinter :: StateT PrintState (MaybeT Identity) a}
deriving (Applicative,Monad,Functor,MonadState PrintState,MonadPlus,Alternative)
data PrintState = PrintState
{ psIndentLevel :: !Int64
, psOutput :: !Builder
, psNewline :: !Bool
, psColumn :: !Int64
, psLine :: !Int64
, psConfig :: !Config
, psInsideCase :: !Bool
, psHardLimit :: !Bool
, psEolComment :: !Bool
}
data Config = Config
{ configMaxColumns :: !Int64
, configIndentSpaces :: !Int64
, configTrailingNewline :: !Bool
}
defaultConfig :: Config
defaultConfig =
Config
{ configMaxColumns = 80
, configIndentSpaces = 4
, configTrailingNewline = True
}
data NodeComment
= CommentSameLine String
| CommentAfterLine String
| CommentBeforeLine String
deriving (Show,Ord,Eq)
data NodeInfo = NodeInfo
{ nodeInfoSpan :: !SrcSpanInfo
, nodeInfoComments :: ![NodeComment]
}
instance Show NodeInfo where
show (NodeInfo _ []) = ""
show (NodeInfo _ s) =
"{- " ++ show s ++ " -}"