{-# LANGUAGE RecordWildCards #-}

-- | A type for result of parsing.
module Ormolu.Parser.Result
  ( ParseResult (..),
    prettyPrintParseResult,
  )
where

import GHC
import Ormolu.Parser.Anns
import Ormolu.Parser.CommentStream
import Ormolu.Parser.Pragma (Pragma)

-- | A collection of data that represents a parsed module in Ormolu.
data ParseResult
  = ParseResult
      { -- | 'ParsedSource' from GHC
        ParseResult -> ParsedSource
prParsedSource :: ParsedSource,
        -- | Ormolu-specfic representation of annotations
        ParseResult -> Anns
prAnns :: Anns,
        -- | Comment stream
        ParseResult -> CommentStream
prCommentStream :: CommentStream,
        -- | Extensions enabled in that module
        ParseResult -> [Pragma]
prExtensions :: [Pragma],
        -- | Shebangs found in the input
        ParseResult -> [Located String]
prShebangs :: [Located String],
        -- | Whether or not record dot syntax is enabled
        ParseResult -> Bool
prUseRecordDot :: Bool
      }

-- | Pretty-print a 'ParseResult'.
prettyPrintParseResult :: ParseResult -> String
prettyPrintParseResult :: ParseResult -> String
prettyPrintParseResult ParseResult {..} =
  [String] -> String
unlines
    [ "parse result:",
      "  comment stream:",
      CommentStream -> String
showCommentStream CommentStream
prCommentStream
      -- XXX extend as needed
    ]