{-# LANGUAGE RecordWildCards #-}
module Ormolu.Printer
( printModule,
PrinterOpts (..),
)
where
import Data.Text (Text)
import Ormolu.Config
import Ormolu.Parser.Result
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Module
import Ormolu.Printer.SpanStream
import Ormolu.Processing.Postprocess (postprocess)
printModule ::
ParseResult ->
PrinterOptsTotal ->
Text
printModule :: ParseResult -> PrinterOptsTotal -> Text
printModule ParseResult {Bool
Int
[([RealLocated Comment], Pragma)]
[Shebang]
Maybe (RealLocated Comment)
Text
HsModule GhcPs
Anns
CommentStream
prIndent :: ParseResult -> Int
prLiteralSuffix :: ParseResult -> Text
prLiteralPrefix :: ParseResult -> Text
prImportQualifiedPost :: ParseResult -> Bool
prUseRecordDot :: ParseResult -> Bool
prCommentStream :: ParseResult -> CommentStream
prPragmas :: ParseResult -> [([RealLocated Comment], Pragma)]
prShebangs :: ParseResult -> [Shebang]
prStackHeader :: ParseResult -> Maybe (RealLocated Comment)
prAnns :: ParseResult -> Anns
prParsedSource :: ParseResult -> HsModule GhcPs
prIndent :: Int
prLiteralSuffix :: Text
prLiteralPrefix :: Text
prImportQualifiedPost :: Bool
prUseRecordDot :: Bool
prCommentStream :: CommentStream
prPragmas :: [([RealLocated Comment], Pragma)]
prShebangs :: [Shebang]
prStackHeader :: Maybe (RealLocated Comment)
prAnns :: Anns
prParsedSource :: HsModule GhcPs
..} PrinterOptsTotal
printerOpts =
Text
prLiteralPrefix Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
region Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
prLiteralSuffix
where
region :: Text
region =
Int -> Text -> Text
postprocess Int
prIndent (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$
R ()
-> SpanStream
-> CommentStream
-> Anns
-> PrinterOptsTotal
-> Bool
-> Text
runR
( Maybe (RealLocated Comment)
-> [Shebang]
-> [([RealLocated Comment], Pragma)]
-> Bool
-> HsModule GhcPs
-> R ()
p_hsModule
Maybe (RealLocated Comment)
prStackHeader
[Shebang]
prShebangs
[([RealLocated Comment], Pragma)]
prPragmas
Bool
prImportQualifiedPost
HsModule GhcPs
prParsedSource
)
(HsModule GhcPs -> SpanStream
forall a. Data a => a -> SpanStream
mkSpanStream HsModule GhcPs
prParsedSource)
CommentStream
prCommentStream
Anns
prAnns
PrinterOptsTotal
printerOpts
Bool
prUseRecordDot