Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module rexposes wrapped parsers from the GHC API. Along with returning the parse result, the corresponding annotations are also returned such that it is then easy to modify the annotations and print the result.
- type Parser a = DynFlags -> FilePath -> String -> Either (SrcSpan, String) (Anns, a)
- withDynFlags :: (DynFlags -> a) -> IO a
- data CppOptions = CppOptions {}
- defaultCppOptions :: CppOptions
- parseModule :: FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource))
- parseModuleFromString :: FilePath -> String -> IO (Either (SrcSpan, String) (Anns, ParsedSource))
- parseModuleWithOptions :: DeltaOptions -> FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource))
- parseModuleWithCpp :: CppOptions -> DeltaOptions -> FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource))
- parseExpr :: Parser (LHsExpr RdrName)
- parseImport :: Parser (LImportDecl RdrName)
- parseType :: Parser (LHsType RdrName)
- parseDecl :: Parser (LHsDecl RdrName)
- parsePattern :: Parser (LPat RdrName)
- parseStmt :: Parser (ExprLStmt RdrName)
- parseWith :: Annotate w => DynFlags -> FilePath -> P (Located w) -> String -> Either (SrcSpan, String) (Anns, Located w)
- ghcWrapper :: Ghc a -> IO a
- initDynFlags :: GhcMonad m => FilePath -> m DynFlags
- initDynFlagsPure :: GhcMonad m => FilePath -> String -> m DynFlags
- parseModuleApiAnnsWithCpp :: CppOptions -> FilePath -> IO (Either (SrcSpan, String) (ApiAnns, [Comment], DynFlags, ParsedSource))
- parseModuleApiAnnsWithCppInternal :: GhcMonad m => CppOptions -> DynFlags -> FilePath -> m (Either (SrcSpan, String) (ApiAnns, [Comment], DynFlags, ParsedSource))
- postParseTransform :: Either a (ApiAnns, [Comment], DynFlags, ParsedSource) -> DeltaOptions -> Either a (Anns, ParsedSource)
Utility
withDynFlags :: (DynFlags -> a) -> IO a Source #
Provides a safe way to consume a properly initialised set of
DynFlags
.
myParser fname expr = withDynFlags (\d -> parseExpr d fname expr)
data CppOptions Source #
Module Parsers
parseModule :: FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource)) Source #
This entry point will also work out which language extensions are required and perform CPP processing if necessary.
parseModule = parseModuleWithCpp defaultCppOptions
Note: ParsedSource
is a synonym for Located
(HsModule
RdrName
)
parseModuleFromString :: FilePath -> String -> IO (Either (SrcSpan, String) (Anns, ParsedSource)) Source #
This entry point will work out which language extensions are
required but will _not_ perform CPP processing.
In contrast to parseModoule
the input source is read from the provided
string; the FilePath
parameter solely exists to provide a name
in source location annotations.
parseModuleWithOptions :: DeltaOptions -> FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource)) Source #
parseModuleWithCpp :: CppOptions -> DeltaOptions -> FilePath -> IO (Either (SrcSpan, String) (Anns, ParsedSource)) Source #
Parse a module with specific instructions for the C pre-processor.
Basic Parsers
parseWith :: Annotate w => DynFlags -> FilePath -> P (Located w) -> String -> Either (SrcSpan, String) (Anns, Located w) Source #
Wrapper function which returns Annotations along with the parsed element.
Internal
ghcWrapper :: Ghc a -> IO a Source #
Internal function. Default runner of GHC.Ghc action in IO.
initDynFlags :: GhcMonad m => FilePath -> m DynFlags Source #
Internal function. Initializes DynFlags value for parsing.
initDynFlagsPure :: GhcMonad m => FilePath -> String -> m DynFlags Source #
Requires GhcMonad constraint because there is
no pure variant of parseDynamicFilePragma
. Yet, in constrast to
initDynFlags
, it does not (try to) read the file at filepath, but
solely depends on the module source in the input string.
parseModuleApiAnnsWithCpp :: CppOptions -> FilePath -> IO (Either (SrcSpan, String) (ApiAnns, [Comment], DynFlags, ParsedSource)) Source #
Low level function which is used in the internal tests.
It is advised to use parseModule
or parseModuleWithCpp
instead of
this function.
parseModuleApiAnnsWithCppInternal :: GhcMonad m => CppOptions -> DynFlags -> FilePath -> m (Either (SrcSpan, String) (ApiAnns, [Comment], DynFlags, ParsedSource)) Source #
Internal function. Exposed if you want to muck with DynFlags before parsing.
postParseTransform :: Either a (ApiAnns, [Comment], DynFlags, ParsedSource) -> DeltaOptions -> Either a (Anns, ParsedSource) Source #
Internal function. Exposed if you want to much with DynFlags before parsing. Or after parsing.