HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.Parser.Lexer

  • 7 types
  • 1 class
  • 38 values
  • Packageghc-9.10.3
  • Exports48
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceLexer.x
datadata Token
#

Constructors

Instances2Show, Outputable
valuemkParserOpts
  1. :: EnumSet Extension

    permitted language extensions enabled

  2. -> DiagOpts

    diagnostic options

  3. -> [String]

    Supported Languages and Extensions

  4. -> Bool

    are safe imports on?

  5. -> Bool

    keeping Haddock comment tokens

  6. -> Bool

    keep regular comment tokens

  7. -> Bool

    If this is enabled, '{-# LINE ... -#}' and '{-# COLUMN ... #-}' update the internal position kept by the parser. Otherwise, those pragmas are lexed as ITline_prag and ITcolumn_prag tokens.

  8. -> ParserOpts
#

Given exactly the information needed, set up the ParserOpts

datadata PState
#
newtypenewtype P a
#

The parsing monad, isomorphic to StateT PState Maybe.

Constructors

Instances4Monad, Functor, Applicative, MonadP
  • Monad PDefined in ghc-9.10.3 · GHC.Parser.Lexer
  • Functor PDefined in ghc-9.10.3 · GHC.Parser.Lexer
  • Applicative PDefined in ghc-9.10.3 · GHC.Parser.Lexer
  • MonadP PDefined in ghc-9.10.3 · GHC.Parser.Lexer
newtypenewtype ParseResult a
#

The result of running a parser.

patternpattern POk :: PState -> a -> ParseResult a
#

The parser has consumed a (possibly empty) prefix of the input and produced a result. Use getPsMessages to check for accumulated warnings and non-fatal errors.

The carried parsing state can be used to resume parsing.

patternpattern PFailed :: PState -> ParseResult a
#

The parser has consumed a (possibly empty) prefix of the input and failed.

The carried parsing state can be used to resume parsing. It is the state right before failure, including the fatal parse error. getPsMessages and getPsErrorMessages must return a non-empty bag of errors.

classclass Monad m => MonadP (m :: Type -> Type) where
#

An mtl-style class for monads that support parsing-related operations. For example, sometimes we make a second pass over the parsing results to validate, disambiguate, or rearrange them, and we do so in the PV monad which cannot consume input but can report parsing errors, check for extension bits, and accumulate parsing annotations. Both P and PV are instances of MonadP.

MonadP grants us convenient overloading. The other option is to have separate operations for each monad: addErrorP vs addErrorPV, getBitP vs getBitPV, and so on.

Methods

  • addError :: MsgEnvelope PsMessage -> m ()

    Add a non-fatal error. Use this when the parser can produce a result despite the error.

    For example, when GHC encounters a forall in a type, but -XExplicitForAll is disabled, the parser constructs ForAllTy as if -XExplicitForAll was enabled, adding a non-fatal error to the accumulator.

    Control flow wise, non-fatal errors act like warnings: they are added to the accumulator and parsing continues. This allows GHC to report more than one parse error per file.

  • addWarning :: MsgEnvelope PsMessage -> m ()

    Add a warning to the accumulator. Use getPsMessages to get the accumulated warnings.

  • addFatalError :: MsgEnvelope PsMessage -> m a

    Add a fatal error. This will be the last error reported by the parser, and the parser will not produce any result, ending in a PFailed state.

  • getBit :: ExtBits -> m Bool

    Check if a given flag is currently set in the bitmap.

  • allocateCommentsP :: RealSrcSpan -> m EpAnnComments

    Go through the comment_q in PState and remove all comments that belong within the given span

  • allocatePriorCommentsP :: RealSrcSpan -> m EpAnnComments

    Go through the comment_q in PState and remove all comments that come before or within the given span

  • allocateFinalCommentsP :: RealSrcSpan -> m EpAnnComments

    Go through the comment_q in PState and remove all comments that come after the given span

Instances2MonadP
  • MonadP PDefined in ghc-9.10.3 · GHC.Parser.Lexer
  • MonadP PVDefined in ghc-9.10.3 · GHC.Parser.PostProcess
datadata ExtBits
#
Instances1Enum