GHC.Parser.Lexer
Documentation
Constructors
data ParserOpts Source #
Parser options.
See mkParserOpts
to construct this.
Constructors
ParserOpts | |
Fields
|
Arguments
:: EnumSet Extension | permitted language extensions enabled |
-> DiagOpts | diagnostic options |
-> [String] | Supported Languages and Extensions |
-> Bool | are safe imports on? |
-> Bool | keeping Haddock comment tokens |
-> Bool | keep regular comment tokens |
-> Bool | If this is enabled, '{-# LINE ... -#}' and '{-# COLUMN ... #-}' update
the internal position kept by the parser. Otherwise, those pragmas are
lexed as |
-> ParserOpts |
Given exactly the information needed, set up the ParserOpts
Constructors
PState | |
Fields
|
initParserState :: ParserOpts -> StringBuffer -> RealSrcLoc -> PState Source #
Creates a parse state from a ParserOpts
value
initPragState :: ParserOpts -> StringBuffer -> RealSrcLoc -> PState Source #
Set parser options for parsing OPTIONS pragmas
The parsing monad, isomorphic to StateT PState Maybe
.
Constructors
P | |
Fields
|
Instances
Applicative P Source # | |
Functor P Source # | |
Monad P Source # | |
MonadP P Source # | |
Defined in GHC.Parser.Lexer Methods addError :: MsgEnvelope PsMessage -> P () Source # addWarning :: MsgEnvelope PsMessage -> P () Source # addFatalError :: MsgEnvelope PsMessage -> P a Source # getBit :: ExtBits -> P Bool Source # allocateCommentsP :: RealSrcSpan -> P EpAnnComments Source # allocatePriorCommentsP :: RealSrcSpan -> P EpAnnComments Source # allocateFinalCommentsP :: RealSrcSpan -> P EpAnnComments Source # |
data ParseResult a where Source #
The result of running a parser.
Bundled Patterns
pattern POk :: PState -> a -> ParseResult a | The parser has consumed a (possibly empty) prefix of the input and produced
a result. Use The carried parsing state can be used to resume parsing. |
pattern 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. |
allocateComments :: RealSrcSpan -> [LEpaComment] -> ([LEpaComment], [LEpaComment]) Source #
allocatePriorComments :: RealSrcSpan -> [LEpaComment] -> Maybe [LEpaComment] -> (Maybe [LEpaComment], [LEpaComment], [LEpaComment]) Source #
allocateFinalComments :: RealSrcSpan -> [LEpaComment] -> Maybe [LEpaComment] -> (Maybe [LEpaComment], [LEpaComment], [LEpaComment]) Source #
class Monad m => MonadP m where Source #
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 () Source #
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 () Source #
Add a warning to the accumulator.
Use getPsMessages
to get the accumulated warnings.
addFatalError :: MsgEnvelope PsMessage -> m a Source #
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 Source #
Check if a given flag is currently set in the bitmap.
allocateCommentsP :: RealSrcSpan -> m EpAnnComments Source #
Go through the comment_q
in PState
and remove all comments
that belong within the given span
allocatePriorCommentsP :: RealSrcSpan -> m EpAnnComments Source #
Go through the comment_q
in PState
and remove all comments
that come before or within the given span
allocateFinalCommentsP :: RealSrcSpan -> m EpAnnComments Source #
Go through the comment_q
in PState
and remove all comments
that come after the given span
Instances
MonadP P Source # | |
Defined in GHC.Parser.Lexer Methods addError :: MsgEnvelope PsMessage -> P () Source # addWarning :: MsgEnvelope PsMessage -> P () Source # addFatalError :: MsgEnvelope PsMessage -> P a Source # getBit :: ExtBits -> P Bool Source # allocateCommentsP :: RealSrcSpan -> P EpAnnComments Source # allocatePriorCommentsP :: RealSrcSpan -> P EpAnnComments Source # allocateFinalCommentsP :: RealSrcSpan -> P EpAnnComments Source # | |
MonadP PV Source # | |
Defined in GHC.Parser.PostProcess Methods addError :: MsgEnvelope PsMessage -> PV () Source # addWarning :: MsgEnvelope PsMessage -> PV () Source # addFatalError :: MsgEnvelope PsMessage -> PV a Source # getBit :: ExtBits -> PV Bool Source # allocateCommentsP :: RealSrcSpan -> PV EpAnnComments Source # allocatePriorCommentsP :: RealSrcSpan -> PV EpAnnComments Source # allocateFinalCommentsP :: RealSrcSpan -> PV EpAnnComments Source # |
failLocMsgP :: RealSrcLoc -> RealSrcLoc -> (SrcSpan -> MsgEnvelope PsMessage) -> P a Source #
srcParseFail :: P a Source #
getPsErrorMessages :: PState -> Messages PsMessage Source #
Get a bag of the errors that have been accumulated so far. Does not take -Werror into account.
getPsMessages :: PState -> (Messages PsMessage, Messages PsMessage) Source #
Get the warnings and errors accumulated so far. Does not take -Werror into account.
popContext :: P () Source #
pushModuleContext :: P () Source #
setSrcLoc :: RealSrcLoc -> P () Source #
activeContext :: P Bool Source #
getLexState :: P Int Source #
popLexState :: P Int Source #
pushLexState :: Int -> P () Source #
Various boolean flags, mostly language extensions, that impact lexing and parsing. Note that a handful of these can change during lexing/parsing.
Constructors
FfiBit | |
InterruptibleFfiBit | |
CApiFfiBit | |
ArrowsBit | |
ThBit | |
ThQuotesBit | |
IpBit | |
OverloadedLabelsBit | |
ExplicitForallBit | |
BangPatBit | |
PatternSynonymsBit | |
HaddockBit | |
MagicHashBit | |
RecursiveDoBit | |
QualifiedDoBit | |
UnicodeSyntaxBit | |
UnboxedParensBit | |
DatatypeContextsBit | |
MonadComprehensionsBit | |
TransformComprehensionsBit | |
QqBit | |
RawTokenStreamBit | |
AlternativeLayoutRuleBit | |
ALRTransitionalBit | |
RelaxedLayoutBit | |
NondecreasingIndentationBit | |
SafeHaskellBit | |
TraditionalRecordSyntaxBit | |
ExplicitNamespacesBit | |
LambdaCaseBit | |
BinaryLiteralsBit | |
NegativeLiteralsBit | |
HexFloatLiteralsBit | |
StaticPointersBit | |
NumericUnderscoresBit | |
StarIsTypeBit | |
BlockArgumentsBit | |
NPlusKPatternsBit | |
DoAndIfThenElseBit | |
MultiWayIfBit | |
GadtSyntaxBit | |
ImportQualifiedPostBit | |
LinearTypesBit | |
NoLexicalNegationBit | |
OverloadedRecordDotBit | |
OverloadedRecordUpdateBit | |
InRulePragBit | |
InNestedCommentBit | |
UsePosPragsBit | If this is enabled, '{-# LINE ... -#}' and '{-# COLUMN ... #-}' update the internal position. Otherwise, those pragmas are lexed as tokens of their own. |
Instances
Enum ExtBits Source # | |
Defined in GHC.Parser.Lexer Methods succ :: ExtBits -> ExtBits Source # pred :: ExtBits -> ExtBits Source # toEnum :: Int -> ExtBits Source # fromEnum :: ExtBits -> Int Source # enumFrom :: ExtBits -> [ExtBits] Source # enumFromThen :: ExtBits -> ExtBits -> [ExtBits] Source # enumFromTo :: ExtBits -> ExtBits -> [ExtBits] Source # enumFromThenTo :: ExtBits -> ExtBits -> ExtBits -> [ExtBits] Source # |
lexTokenStream :: ParserOpts -> StringBuffer -> RealSrcLoc -> ParseResult [Located Token] Source #
mkParensEpAnn :: RealSrcSpan -> (AddEpAnn, AddEpAnn) Source #
Given a RealSrcSpan
that surrounds a HsPar
or HsParTy
, generate
AddEpAnn
values for the opening and closing bordering on the start
and end of the span
getCommentsFor :: MonadP m => SrcSpan -> m EpAnnComments Source #
getPriorCommentsFor :: MonadP m => SrcSpan -> m EpAnnComments Source #
getFinalCommentsFor :: MonadP m => SrcSpan -> m EpAnnComments Source #
getEofPos :: P (Maybe (Pair RealSrcSpan RealSrcSpan)) Source #
data HdkComment Source #
Haddock comment as produced by the lexer. These are accumulated in PState
and then processed in GHC.Parser.PostProcess.Haddock. The location of the
HsDocString
s spans over the contents of the docstring - i.e. it does not
include the decorator ("-- |", "{-|" etc.)
Constructors
HdkCommentNext HsDocString | |
HdkCommentPrev HsDocString | |
HdkCommentNamed String HsDocString | |
HdkCommentSection Int HsDocString |
Instances
Show HdkComment Source # | |
Defined in GHC.Parser.Lexer |
warnopt :: WarningFlag -> ParserOpts -> Bool Source #
Test whether a WarningFlag
is set
adjustChar :: Char -> Word8 Source #