module HIndent
(
reformat
,prettyPrint
,parseMode
,styles
,chrisDone
,michaelSnoyman
,johanTibell
,fundamental
,test)
where
import HIndent.Styles.ChrisDone
import HIndent.Styles.MichaelSnoyman
import HIndent.Styles.JohanTibell
import HIndent.Styles.Fundamental
import HIndent.Instances ()
import HIndent.Types
import Control.Monad.State
import Data.Monoid
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import Data.Text.Lazy.Builder (Builder)
import qualified Data.Text.Lazy.Builder as T
import Language.Haskell.Exts.Extension
import Language.Haskell.Exts.Parser
reformat :: Config -> Style -> Text -> Either String Builder
reformat config style x =
case parseDeclWithComments parseMode
(T.unpack x) of
ParseOk (v,_comments) ->
Right (prettyPrint config style v)
ParseFailed _ e -> Left e
prettyPrint :: Pretty a => Config -> Style -> a -> Builder
prettyPrint config style a =
psOutput (execState (runPrinter (pretty a))
(case style of
Style _name _author _desc st extenders _defconfig ->
PrintState 0 mempty False 0 1 st extenders config))
parseMode :: ParseMode
parseMode =
defaultParseMode {extensions = allExtensions
,fixities = Nothing}
where allExtensions =
filter isDisabledExtention knownExtensions
isDisabledExtention (DisableExtension _) = False
isDisabledExtention _ = True
test :: Config -> Style -> Text -> IO ()
test config style =
either error (T.putStrLn . T.toLazyText) .
reformat config style
styles :: [Style]
styles =
[fundamental,chrisDone,michaelSnoyman,johanTibell]