module HIndent.Types
(Printer(..)
,PrintState(..)
,Extender(..)
,Style(..)
,Config(..)
,NodeInfo(..)
,ComInfo(..))
where
import Control.Applicative
import Control.Monad.State.Strict (MonadState(..),State)
import Data.Data
import Data.Default
import Data.Int (Int64)
import Data.Text (Text)
import Data.Text.Lazy.Builder (Builder)
import Language.Haskell.Exts.Comments
import Language.Haskell.Exts.SrcLoc
newtype Printer a =
Printer {runPrinter :: State PrintState a}
deriving (Applicative,Monad,Functor,MonadState PrintState)
data PrintState =
forall s. PrintState {psIndentLevel :: !Int64
,psOutput :: !Builder
,psNewline :: !Bool
,psColumn :: !Int64
,psLine :: !Int64
,psUserState :: !s
,psExtenders :: ![Extender s]
,psConfig :: !Config
,psEolComment :: !Bool
}
instance Eq PrintState where
PrintState ilevel out newline col line _ _ _ eolc == PrintState ilevel' out' newline' col' line' _ _ _ eolc' =
(ilevel,out,newline,col,line,eolc) == (ilevel',out',newline',col',line',eolc')
data Extender s where
Extender :: forall s a. (Typeable a) => (s -> a -> Printer ()) -> Extender s
CatchAll :: forall s. (forall a. Typeable a => s -> a -> Maybe (Printer ())) -> Extender s
data Style =
forall s. Style {styleName :: !Text
,styleAuthor :: !Text
,styleDescription :: !Text
,styleInitialState :: !s
,styleExtenders :: ![Extender s]
,styleDefConfig :: !Config
}
data Config =
Config {configMaxColumns :: !Int64
,configIndentSpaces :: !Int64
}
instance Default Config where
def =
Config {configMaxColumns = 80
,configIndentSpaces = 2}
data NodeInfo =
NodeInfo {nodeInfoSpan :: !SrcSpanInfo
,nodeInfoComments :: ![ComInfo]
}
deriving (Typeable,Show,Data)
data ComInfo =
ComInfo {comInfoComment :: !Comment
,comInfoOwnLine :: !Bool
}
deriving (Show,Typeable,Data)