{-# LANGUAGE NoImplicitPrelude #-}

module Language.Haskell.Brittany.Internal.ToBriDoc.Comment
  ( commentToDoc
  ) where

import           Language.Haskell.Brittany.Internal.Prelude

import           GHC                            ( EpaCommentTok
                                                  ( EpaBlockComment
                                                  , EpaDocCommentNamed
                                                  , EpaDocCommentNext
                                                  , EpaDocCommentPrev
                                                  , EpaDocOptions
                                                  , EpaDocSection
                                                  , EpaEofComment
                                                  , EpaLineComment
                                                  )
                                                )
import           Language.Haskell.Brittany.Internal.Types
import           Language.Haskell.Brittany.Internal.Components.BriDoc
import           Language.Haskell.Brittany.Internal.ToBriDocTools



commentToDoc :: (Int, EpaCommentTok) -> ToBriDocM BriDocNumbered
commentToDoc (indent, c) = case c of
  GHC.EpaDocCommentNext  str -> handle str
  GHC.EpaDocCommentPrev  str -> handle str
  GHC.EpaDocCommentNamed str -> handle str
  GHC.EpaDocSection _ str    -> handle str
  GHC.EpaDocOptions   str    -> handle str
  GHC.EpaLineComment  str    -> handle str
  GHC.EpaBlockComment str    -> handle str
  GHC.EpaEofComment          -> docEmpty
 where
  handle str = if indent == 0
    then docLitS str
    else docSeq [docSeparator, docLitS $ (replicate (indent - 1) ' ') ++ str ]
