module HIndent.Types
(Printer(..)
,PrintState(..)
,Extender(..)
,Style(..)
,Config(..)
,defaultConfig
,NodeInfo(..)
,ComInfo(..)
,ComInfoLocation(..)
) 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 s a =
Printer {runPrinter :: State (PrintState s) a}
deriving (Applicative,Monad,Functor,MonadState (PrintState s))
data PrintState s =
PrintState {psIndentLevel :: !Int64
,psOutput :: !Builder
,psNewline :: !Bool
,psColumn :: !Int64
,psLine :: !Int64
,psUserState :: !s
,psExtenders :: ![Extender s]
,psConfig :: !Config
,psEolComment :: !Bool
,psInsideCase :: !Bool
}
instance Eq (PrintState s) where
PrintState ilevel out newline col line _ _ _ eolc inc == PrintState ilevel' out' newline' col' line' _ _ _ eolc' inc' =
(ilevel,out,newline,col,line,eolc, inc) == (ilevel',out',newline',col',line',eolc', inc')
data Extender s where
Extender :: forall s a. (Typeable a) => (a -> Printer s ()) -> Extender s
CatchAll :: forall s. (forall a. Typeable a => s -> a -> Maybe (Printer s ())) -> 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
,configClearEmptyLines :: !Bool
}
instance Default Config where
def =
Config {configMaxColumns = 80
,configIndentSpaces = 2
,configClearEmptyLines = False}
defaultConfig :: Config
defaultConfig = def
data NodeInfo =
NodeInfo {nodeInfoSpan :: !SrcSpanInfo
,nodeInfoComments :: ![ComInfo]
}
deriving (Typeable,Show,Data)
data ComInfoLocation = Before | After
deriving (Show,Typeable,Data,Eq)
data ComInfo =
ComInfo {comInfoComment :: !Comment
,comInfoLocation :: !(Maybe ComInfoLocation)
}
deriving (Show,Typeable,Data)