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, Located (HsModule RdrName)))
- parseModuleWithCpp :: CppOptions -> FilePath -> IO (Either (SrcSpan, String) (Anns, Located (HsModule RdrName)))
- 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)
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)
Module Parsers
parseModule :: FilePath -> IO (Either (SrcSpan, String) (Anns, Located (HsModule RdrName))) 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
)
parseModuleWithCpp :: CppOptions -> FilePath -> IO (Either (SrcSpan, String) (Anns, Located (HsModule RdrName))) Source
Parse a module with specific instructions for the C pre-processor.
Basic Parsers
parsePattern :: Parser (LPat RdrName) Source