{-# LANGUAGE RecordWildCards #-}

-- | Pretty-printer for Haskell AST.
module Ormolu.Printer
  ( printModule,
  )
where

import Data.Text (Text)
import Ormolu.Parser.Result
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Module
import Ormolu.Printer.SpanStream
import Ormolu.Processing.Postprocess (postprocess)

-- | Render a module.
printModule ::
  -- | Result of parsing
  ParseResult ->
  -- | Resulting rendition
  Text
printModule :: ParseResult -> Text
printModule ParseResult {Bool
Int
[([RealLocated Comment], Pragma)]
[Shebang]
Maybe (RealLocated Comment)
HsModule
EnumSet Extension
Text
Anns
CommentStream
prIndent :: ParseResult -> Int
prLiteralSuffix :: ParseResult -> Text
prLiteralPrefix :: ParseResult -> Text
prExtensions :: ParseResult -> EnumSet Extension
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
prIndent :: Int
prLiteralSuffix :: Text
prLiteralPrefix :: Text
prExtensions :: EnumSet Extension
prUseRecordDot :: Bool
prCommentStream :: CommentStream
prPragmas :: [([RealLocated Comment], Pragma)]
prShebangs :: [Shebang]
prStackHeader :: Maybe (RealLocated Comment)
prAnns :: Anns
prParsedSource :: HsModule
..} =
  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
-> Bool
-> EnumSet Extension
-> Text
runR
          ( Maybe (RealLocated Comment)
-> [Shebang]
-> [([RealLocated Comment], Pragma)]
-> HsModule
-> R ()
p_hsModule
              Maybe (RealLocated Comment)
prStackHeader
              [Shebang]
prShebangs
              [([RealLocated Comment], Pragma)]
prPragmas
              HsModule
prParsedSource
          )
          (HsModule -> SpanStream
forall a. Data a => a -> SpanStream
mkSpanStream HsModule
prParsedSource)
          CommentStream
prCommentStream
          Anns
prAnns
          Bool
prUseRecordDot
          EnumSet Extension
prExtensions