GHC.Parser

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

Safe Haskell | Ignore
Language | GHC2021

GHC.Parser

Description

This module provides the generated Happy parser for Haskell. It exports a number of parsers which may be used in any library that uses the GHC API. A common usage pattern is to initialize the parser state with a given string and then parse that string:

        runParser :: ParserOpts -> String -> P a -> ParseResult a
        runParser opts str parser = unP parser parseState
        where
          filename = "<interactive>"
          location = mkRealSrcLoc (mkFastString filename) 1 1
          buffer = stringToStringBuffer str
          parseState = initParserState opts buffer location

Synopsis

- parseModule :: P (Located (HsModule GhcPs))
- parseSignature :: P (Located (HsModule GhcPs))
- parseImport :: P (GenLocated SrcSpanAnnA (ImportDecl GhcPs))
- parseStatement :: P (GenLocated SrcSpanAnnA (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
- parseBackpack :: P [LHsUnit PackageName]
- parseDeclaration :: P (GenLocated SrcSpanAnnA (HsDecl GhcPs))
- parseExpression :: P ECP
- parsePattern :: P (GenLocated SrcSpanAnnA (Pat GhcPs))
- parseTypeSignature :: P (GenLocated SrcSpanAnnA (HsDecl GhcPs))
- parseStmt :: P (Maybe (GenLocated SrcSpanAnnA (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))))
- parseIdentifier :: P (LocatedN RdrName)
- parseType :: P (GenLocated SrcSpanAnnA (HsType GhcPs))
- parseHeader :: P (Located (HsModule GhcPs))
- parseModuleNoHaddock :: P (Located (HsModule GhcPs))

# Documentation

parseModule :: P (Located (HsModule GhcPs)) #

Parse a Haskell module with Haddock comments. This is done in two steps:

- `parseModuleNoHaddock` to build the AST
- `addHaddockToModule` to insert Haddock comments into it

This and the signature module parser are the only parser entry points that deal with Haddock comments. The other entry points (`parseDeclaration`, `parseExpression`, etc) do not insert them into the AST.

parseSignature :: P (Located (HsModule GhcPs)) #

Parse a Haskell signature module with Haddock comments. This is done in two steps:

- `parseSignatureNoHaddock` to build the AST
- `addHaddockToModule` to insert Haddock comments into it

This and the module parser are the only parser entry points that deal with Haddock comments. The other entry points (`parseDeclaration`, `parseExpression`, etc) do not insert them into the AST.

parseImport :: P (GenLocated SrcSpanAnnA (ImportDecl GhcPs)) #

parseStatement :: P (GenLocated SrcSpanAnnA (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))) #

parseBackpack :: P [LHsUnit PackageName] #

parseDeclaration :: P (GenLocated SrcSpanAnnA (HsDecl GhcPs)) #

parseExpression :: P ECP #

parsePattern :: P (GenLocated SrcSpanAnnA (Pat GhcPs)) #

parseTypeSignature :: P (GenLocated SrcSpanAnnA (HsDecl GhcPs)) #

parseStmt :: P (Maybe (GenLocated SrcSpanAnnA (StmtLR GhcPs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))) #

parseIdentifier :: P (LocatedN RdrName) #

parseType :: P (GenLocated SrcSpanAnnA (HsType GhcPs)) #

parseHeader :: P (Located (HsModule GhcPs)) #

parseModuleNoHaddock :: P (Located (HsModule GhcPs)) #