module HIndent.Types
(Printer(..)
,PrintState(..)
,Extender(..)
,Style(..)
,Config(..)
,defaultConfig
,NodeInfo(..)
,ComInfo(..)
,ComInfoLocation(..)
) where
import Control.Applicative
import Control.Monad
import Control.Monad.State.Strict (MonadState(..),StateT)
import Control.Monad.Trans.Maybe
import Data.Data
import Data.Default
import Data.Functor.Identity
import Data.Int (Int64)
import Data.Text (Text)
import Data.Text.Lazy.Builder (Builder)
import Language.Haskell.Exts.Comments
import Language.Haskell.Exts.Parser
import Language.Haskell.Exts.SrcLoc
newtype Printer s a =
Printer {runPrinter :: StateT (PrintState s) (MaybeT Identity) a}
deriving (Applicative,Monad,Functor,MonadState (PrintState s),MonadPlus,Alternative)
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
,psParseMode :: !ParseMode
}
instance Eq (PrintState s) where
PrintState ilevel out newline col line _ _ _ eolc inc pm == PrintState ilevel' out' newline' col' line' _ _ _ eolc' inc' pm' =
(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)