{-# LANGUAGE CPP             #-}
{-# LANGUAGE PatternSynonyms #-}

-- | Parser compatibility module.
module Development.IDE.GHC.Compat.Parser (
    initParserOpts,
    initParserState,
    ApiAnns,
    PsSpan(..),
    pattern HsParsedModule,
    type GHC.HsParsedModule,
    Development.IDE.GHC.Compat.Parser.hpm_module,
    Development.IDE.GHC.Compat.Parser.hpm_src_files,
    Development.IDE.GHC.Compat.Parser.hpm_annotations,
    pattern ParsedModule,
    Development.IDE.GHC.Compat.Parser.pm_parsed_source,
    type GHC.ParsedModule,
    Development.IDE.GHC.Compat.Parser.pm_mod_summary,
    Development.IDE.GHC.Compat.Parser.pm_extra_src_files,
    Development.IDE.GHC.Compat.Parser.pm_annotations,
    mkApiAnns,
    -- * API Annotations
    Anno.AnnKeywordId(..),
    pattern EpaLineComment,
    pattern EpaBlockComment
    ) where

import           Development.IDE.GHC.Compat.Core
import           Development.IDE.GHC.Compat.Util

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]

import qualified GHC.Parser.Annotation           as Anno
import qualified GHC.Parser.Lexer                as Lexer
import           GHC.Types.SrcLoc                (PsSpan (..))



import           GHC                             (EpaCommentTok (..),
                                                  pm_extra_src_files,
                                                  pm_mod_summary,
                                                  pm_parsed_source)
import qualified GHC
import           GHC.Hs                          (hpm_module, hpm_src_files)

#if !MIN_VERSION_ghc(9,3,0)
import qualified GHC.Driver.Config               as Config
#endif

#if MIN_VERSION_ghc(9,3,0)
import qualified GHC.Driver.Config.Parser        as Config
#endif



initParserOpts :: DynFlags -> ParserOpts
initParserOpts :: DynFlags -> ParserOpts
initParserOpts =
  DynFlags -> ParserOpts
Config.initParserOpts

initParserState :: ParserOpts -> StringBuffer -> RealSrcLoc -> PState
initParserState :: ParserOpts -> StringBuffer -> RealSrcLoc -> PState
initParserState =
  ParserOpts -> StringBuffer -> RealSrcLoc -> PState
Lexer.initParserState

-- GHC 9.2 does not have ApiAnns anymore packaged in ParsedModule. Now the
-- annotations are found in the ast.
type ApiAnns = ()

#if MIN_VERSION_ghc(9,5,0)
pattern HsParsedModule :: Located (HsModule GhcPs) -> [FilePath] -> ApiAnns -> GHC.HsParsedModule
#else
pattern HsParsedModule :: Located HsModule -> [FilePath] -> ApiAnns -> GHC.HsParsedModule
#endif
pattern $mHsParsedModule :: forall {r}.
HsParsedModule
-> (Located (HsModule GhcPs) -> [FilePath] -> ApiAnns -> r)
-> ((# #) -> r)
-> r
$bHsParsedModule :: Located (HsModule GhcPs) -> [FilePath] -> ApiAnns -> HsParsedModule
HsParsedModule
    { HsParsedModule -> Located (HsModule GhcPs)
hpm_module
    , HsParsedModule -> [FilePath]
hpm_src_files
    , HsParsedModule -> ApiAnns
hpm_annotations
    } <- ( (,()) -> (GHC.HsParsedModule{..}, hpm_annotations))
    where
        HsParsedModule Located (HsModule GhcPs)
hpm_module [FilePath]
hpm_src_files ApiAnns
_hpm_annotations =
            Located (HsModule GhcPs) -> [FilePath] -> HsParsedModule
GHC.HsParsedModule Located (HsModule GhcPs)
hpm_module [FilePath]
hpm_src_files


pattern ParsedModule :: ModSummary -> ParsedSource -> [FilePath] -> ApiAnns -> GHC.ParsedModule
pattern $mParsedModule :: forall {r}.
ParsedModule
-> (ModSummary
    -> Located (HsModule GhcPs) -> [FilePath] -> ApiAnns -> r)
-> ((# #) -> r)
-> r
$bParsedModule :: ModSummary
-> Located (HsModule GhcPs)
-> [FilePath]
-> ApiAnns
-> ParsedModule
ParsedModule
    { ParsedModule -> ModSummary
pm_mod_summary
    , ParsedModule -> Located (HsModule GhcPs)
pm_parsed_source
    , ParsedModule -> [FilePath]
pm_extra_src_files
    , ParsedModule -> ApiAnns
pm_annotations
    } <- ( (,()) -> (GHC.ParsedModule{..}, pm_annotations))
    where
        ParsedModule ModSummary
ms Located (HsModule GhcPs)
parsed [FilePath]
extra_src_files ApiAnns
_anns =
            GHC.ParsedModule
             { pm_mod_summary :: ModSummary
pm_mod_summary = ModSummary
ms
             , pm_parsed_source :: Located (HsModule GhcPs)
pm_parsed_source = Located (HsModule GhcPs)
parsed
             , pm_extra_src_files :: [FilePath]
pm_extra_src_files = [FilePath]
extra_src_files
             }
{-# COMPLETE ParsedModule :: GHC.ParsedModule #-}

mkApiAnns :: PState -> ApiAnns
mkApiAnns :: PState -> ApiAnns
mkApiAnns = ApiAnns -> PState -> ApiAnns
forall a b. a -> b -> a
const ()