GHC.Parser.Header

ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Parser.Header

Description

Parsing the top of a Haskell source file to get its module name, imports and options.

(c) Simon Marlow 2005 (c) Lemmih 2006

Synopsis

- getImports :: ParserOpts -> Bool -> StringBuffer -> FilePath -> FilePath -> IO (Either (Messages PsMessage) ([Located ModuleName], [(ImportLevel, RawPkgQual, Located ModuleName)], Located ModuleName))
- mkPrelImports :: ModuleName -> SrcSpan -> Bool -> [LImportDecl GhcPs] -> [LImportDecl GhcPs]
- getOptionsFromFile :: ParserOpts -> [String] -> FilePath -> IO (Messages PsMessage, [Located String])
- getOptions :: ParserOpts -> [String] -> StringBuffer -> FilePath -> (Messages PsMessage, [Located String])
- toArgs :: RealSrcLoc -> String -> Either String [Located String]
- checkProcessArgsResult :: MonadIO m => [Located String] -> m ()

# Documentation

getImports #

Arguments

:: ParserOpts | Parser options
-> Bool | Implicit Prelude?
-> StringBuffer | Parse this.
-> FilePath | Filename the buffer came from. Used for reporting parse error locations.
-> FilePath | The original source filename (used for locations in the function result)
-> IO (Either (Messages PsMessage) ([Located ModuleName], [(ImportLevel, RawPkgQual, Located ModuleName)], Located ModuleName)) | The source imports and normal imports (with optional package names from -XPackageImports), and the module name.

Parse the imports of a source file.

Throws a `SourceError` if parsing fails.

mkPrelImports :: ModuleName -> SrcSpan -> Bool -> [LImportDecl GhcPs] -> [LImportDecl GhcPs] #

getOptionsFromFile #

Arguments

:: ParserOpts |
-> [String] | Supported LANGUAGE pragmas
-> FilePath | Input file
-> IO (Messages PsMessage, [Located String]) | Parsed options, if any.

Parse OPTIONS and LANGUAGE pragmas of the source file.

Throws a `SourceError` if flag parsing fails (including unsupported flags.)

getOptions #

Arguments

:: ParserOpts |
-> [String] | Supported LANGUAGE pragmas
-> StringBuffer | Input Buffer
-> FilePath | Source filename. Used for location info.
-> (Messages PsMessage, [Located String]) | warnings and parsed options.

Parse OPTIONS and LANGUAGE pragmas of the source file.

Throws a `SourceError` if flag parsing fails (including unsupported flags.)

toArgs :: RealSrcLoc -> String -> Either String [Located String] #

checkProcessArgsResult :: MonadIO m => [Located String] -> m () #

Complain about non-dynamic flags in OPTIONS pragmas.

Throws a `SourceError` if the input list is non-empty claiming that the input flags are unknown.