Moduleghc-9.10.3GHC2021
GHC.Parser.PostProcess
- 11 types
- 3 classes
- 88 values
- Packageghc-9.10.3
- Exports103
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceUtils.hs
A useful function for building OpApps. The operator is always a
variable, and we don't know the fixity yet.
mkClassDecl builds a RdrClassDecl, filling in the names for tycon and datacon by deriving them from the name of the class. We fill in the names for the tycon and datacon corresponding to the class, by deriving them from the name of the class itself. This saves recording the names in the interface file (which would be equally good).
This rather gruesome function is used mainly by the parser. When parsing:
data T a = T | T1 Intwe parse the data constructors as types because of parser ambiguities, so then we need to change the type constr to a data constr
The exact-name case can occur when parsing:
data [] a = [] | a : [a]For the exact-name case we return an original name.
Converts LHsTyVarBndr annotated with its Specificity to one without annotations. Only accepts specified variables, and errors if the provided binder has an InferredSpec annotation.
Converts a list of LHsTyVarBndrs annotated with their Specificity to binders without annotations. Only accepts specified variables, and errors if any of the provided binders has an InferredSpec annotation.
Add the annotation for a where keyword to existing HsLocalBinds
The Anchor for a stmtlist is based on either the location or the first semicolon annotion.
Function definitions are restructured here. Each is assumed to be recursive initially, and non recursive definitions are discovered by the dependency analyser.
Construct a GADT-style data constructor from the constructor names and their type. Some interesting aspects of this function:
This splits up the constructor type into its quantified type variables (if provided), context (if provided), argument types, and result type, and records whether this is a prefix or record GADT constructor. See Note [GADT abstract syntax] in GHC.Hs.Decls for more details.
Yield a parse error if we have a function applied directly to a do block etc. and BlockArguments is not enabled.
checkPrecP Check if a fixity is valid. We support bypassing the usual bound checks for some special operators.
Validate the context constraints and break up a context into a list of predicates.
(Eq a, Ord b) --> [Eq a, Ord b]
Eq a --> [Eq a]
(Eq a) --> [Eq a]
(((Eq a))) --> [Eq a]
Extra information for the expression GHC is currently inspecting/parsing. It can be used to generate more informative parser diagnostics and hints.
Constructors
ParseContextis_infix :: !Maybe RdrNameIf Just, this is an infix pattern with the bound operator name
incomplete_do_block :: !PatIncompleteDoBlockDid the parser likely fail due to an incomplete do block?
Instances1Eq
Eq ParseContextDefined in ghc-9.10.3 · GHC.Parser.Errors.Types
Check if the gadt_constrlist is empty. Only raise parse error for `data T where` to avoid affecting existing error message, see #8258.
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.
Hint about bang patterns, assuming BangPatterns is off.
Result of parsing {-# UNPACK #-} or {-# NOUNPACK #-}.
Constructors
Constructors
Disambiguate infix operators. See Note [Ambiguous syntactic categories]
Instances2DisambInfixOp
DisambInfixOp RdrNameDefined in ghc-9.10.3 · GHC.Parser.PostProcessDisambInfixOp (HsExpr GhcPs)Defined in ghc-9.10.3 · GHC.Parser.PostProcess
Disambiguate constructs that may appear when we do not know ahead of time whether we are parsing an expression, a command, or a pattern. See Note [Ambiguous syntactic categories]
Associated types
Methods
ecpFromCmd' :: LHsCmd GhcPs -> PV (LocatedA b)Return a command without ambiguity, or fail in a non-command context.
ecpFromExp' :: LHsExpr GhcPs -> PV (LocatedA b)Return an expression without ambiguity, or fail in a non-expression context.
mkHsProjUpdatePV :: SrcSpan -> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)] -> LocatedA b -> Bool -> [AddEpAnn] -> PV (LHsRecProj GhcPs (LocatedA b))mkHsLetPV :: SrcSpan -> EpToken"let"
-> HsLocalBinds GhcPs -> EpToken"in"
-> LocatedA b -> PV (LocatedA b)Disambiguate "let ... in ..."
superInfixOp :: (DisambInfixOp (InfixOp b) => PV (LocatedA b)) -> PV (LocatedA b)Bring superclass constraints on InfixOp into scope. See Note [UndecidableSuperClasses for associated types]
mkHsOpAppPV :: SrcSpan -> LocatedA b -> LocatedN (InfixOp b) -> LocatedA b -> PV (LocatedA b)Disambiguate "f # x" (infix operator)
mkHsCasePV :: SrcSpan -> LHsExpr GhcPs -> LocatedL [LMatch GhcPs (LocatedA b)] -> EpAnnHsCase -> PV (LocatedA b)Disambiguate "case ... of ..."
mkHsLamPV :: SrcSpan -> HsLamVariant -> LocatedL [LMatch GhcPs (LocatedA b)] -> [AddEpAnn] -> PV (LocatedA b)Disambiguate "... -> ..." (lambda), "case" and "cases"
superFunArg :: (DisambECP (FunArg b) => PV (LocatedA b)) -> PV (LocatedA b)Bring superclass constraints on FunArg into scope. See Note [UndecidableSuperClasses for associated types]
mkHsAppPV :: SrcSpanAnnA -> LocatedA b -> LocatedA (FunArg b) -> PV (LocatedA b)Disambiguate "f x" (function application)
mkHsAppTypePV :: SrcSpanAnnA -> LocatedA b -> EpToken"@"
-> LHsType GhcPs -> PV (LocatedA b)Disambiguate "f @t" (visible type application)
mkHsIfPV :: SrcSpan -> LHsExpr GhcPs -> Bool -> LocatedA b -> Bool -> LocatedA b -> AnnsIf -> PV (LocatedA b)Disambiguate "if ... then ... else ..."
mkHsDoPV :: SrcSpan -> Maybe ModuleName -> LocatedL [LStmt GhcPs (LocatedA b)] -> AnnList -> PV (LocatedA b)Disambiguate "do { ... }" (do notation)
mkHsParPV :: SrcSpan -> EpToken"("
-> LocatedA b -> EpToken")"
-> PV (LocatedA b)Disambiguate "( ... )" (parentheses)
mkHsVarPV :: LocatedN RdrName -> PV (LocatedA b)Disambiguate a variable "f" or a data constructor
MkF.mkHsLitPV :: Located (HsLit GhcPs) -> PV (LocatedA b)Disambiguate a monomorphic literal
mkHsOverLitPV :: LocatedAn a (HsOverLit GhcPs) -> PV (LocatedAn a b)Disambiguate an overloaded literal
mkHsWildCardPV :: NoAnn a => SrcSpan -> PV (LocatedAn a b)Disambiguate a wildcard
mkHsTySigPV :: SrcSpanAnnA -> LocatedA b -> LHsType GhcPs -> [AddEpAnn] -> PV (LocatedA b)Disambiguate "a :: t" (type annotation)
mkHsExplicitListPV :: SrcSpan -> [LocatedA b] -> AnnList -> PV (LocatedA b)Disambiguate "[a,b,c]" (list syntax)
mkHsSplicePV :: Located (HsUntypedSplice GhcPs) -> PV (LocatedA b)Disambiguate "$(...)" and "[quasi|...|]" (TH splices)
mkHsRecordPV :: Bool -> SrcSpan -> SrcSpan -> LocatedA b -> ([Fbind b], Maybe SrcSpan) -> [AddEpAnn] -> PV (LocatedA b)Disambiguate "f { a = b, ... }" syntax (record construction and record updates)
mkHsNegAppPV :: SrcSpan -> LocatedA b -> [AddEpAnn] -> PV (LocatedA b)Disambiguate "-a" (negation)
mkHsSectionR_PV :: SrcSpan -> LocatedA (InfixOp b) -> LocatedA b -> PV (LocatedA b)Disambiguate "(# a)" (right operator section)
mkHsViewPatPV :: SrcSpan -> LHsExpr GhcPs -> LocatedA b -> [AddEpAnn] -> PV (LocatedA b)Disambiguate "(a -> b)" (view pattern)
mkHsAsPatPV :: SrcSpan -> LocatedN RdrName -> EpToken"@"
-> LocatedA b -> PV (LocatedA b)Disambiguate "a@b" (as-pattern)
mkHsLazyPatPV :: SrcSpan -> LocatedA b -> [AddEpAnn] -> PV (LocatedA b)Disambiguate "~a" (lazy pattern)
mkHsBangPatPV :: SrcSpan -> LocatedA b -> [AddEpAnn] -> PV (LocatedA b)Disambiguate "!a" (bang pattern)
mkSumOrTuplePV :: SrcSpanAnnA -> Boxity -> SumOrTuple b -> [AddEpAnn] -> PV (LocatedA b)Disambiguate tuple sections and unboxed sums
mkHsEmbTyPV :: SrcSpan -> EpToken"type"
-> LHsType GhcPs -> PV (LocatedA b)Disambiguate "type t" (embedded type)
rejectPragmaPV :: LocatedA b -> PV ()Validate infixexp LHS to reject unwanted {-# SCC ... #-} pragmas
See Note [Ambiguous syntactic categories] and Note [PatBuilder]
Instances10Outputable, DisambECP, Anno, Body, FunArg, InfixOp, …
Outputable (PatBuilder GhcPs)Defined in ghc-9.10.3 · GHC.Parser.TypesDisambECP (PatBuilder GhcPs)Defined in ghc-9.10.3 · GHC.Parser.PostProcesstype Anno (GRHS GhcPs (LocatedA (PatBuilder GhcPs))) = EpAnnCODefined in ghc-9.10.3 · GHC.Parser.Typestype Anno (Match GhcPs (LocatedA (PatBuilder GhcPs))) = SrcSpanAnnADefined in ghc-9.10.3 · GHC.Parser.Typestype Anno (StmtLR GhcPs GhcPs (LocatedA (PatBuilder GhcPs))) = SrcSpanAnnADefined in ghc-9.10.3 · GHC.Parser.Typestype Anno [LocatedA (Match GhcPs (LocatedA (PatBuilder GhcPs)))] = SrcSpanAnnLDefined in ghc-9.10.3 · GHC.Parser.Typestype Anno [LocatedA (StmtLR GhcPs GhcPs (LocatedA (PatBuilder GhcPs)))] = SrcSpanAnnLDefined in ghc-9.10.3 · GHC.Parser.Typestype Body (PatBuilder GhcPs) = PatBuilderDefined in ghc-9.10.3 · GHC.Parser.PostProcesstype FunArg (PatBuilder GhcPs) = PatBuilder GhcPsDefined in ghc-9.10.3 · GHC.Parser.PostProcesstype InfixOp (PatBuilder GhcPs) = RdrNameDefined in ghc-9.10.3 · GHC.Parser.PostProcess
Disambiguate constructs that may appear when we do not know ahead of time whether we are parsing a type or a newtype/data constructor.
See Note [Ambiguous syntactic categories] for the general idea.
See Note [Parsing data constructors is hard] for the specific issue this particular class is solving.
Methods
mkHsAppTyHeadPV :: LHsType GhcPs -> PV (LocatedA b)Process the head of a type-level function/constructor application, i.e. the
HinH a b c.mkHsAppTyPV :: LocatedA b -> LHsType GhcPs -> PV (LocatedA b)Disambiguate
f x(function application or prefix data constructor).mkHsAppKindTyPV :: LocatedA b -> EpToken"@"
-> LHsType GhcPs -> PV (LocatedA b)Disambiguate
f @t(visible kind application)mkHsOpTyPV :: PromotionFlag -> LHsType GhcPs -> LocatedN RdrName -> LHsType GhcPs -> PV (LocatedA b)Disambiguate
f # x(infix operator)mkUnpackednessPV :: Located UnpackednessPragma -> LocatedA b -> PV (LocatedA b)Disambiguate
{-# UNPACK #-} t(unpack/nounpack pragma)
Instances2DisambTD
DisambTD DataConBuilderDefined in ghc-9.10.3 · GHC.Parser.PostProcessDisambTD (HsType GhcPs)Defined in ghc-9.10.3 · GHC.Parser.PostProcess
Annotate a type with either an {-# UNPACK #-} or a {-# NOUNPACK #-} pragma.
Decide whether to parse tuple syntax (Int, Double) in a type as a
type or data constructor, based on the extension ListTuplePuns.
The case with an explicit promotion quote, '(Int, Double), is handled
by mkExplicitTupleTy.
Decide whether to parse tuple con syntax (,) in a type as a
type or data constructor, based on the extension ListTuplePuns.
The case with an explicit promotion quote, '(,), is handled
by the rule SIMPLEQUOTE sysdcon_nolist in atype.
Decide whether to parse list tycon syntax [] in a type as a type or data
constructor, based on the extension ListTuplePuns.
The case with an explicit promotion quote, '[], is handled by
mkExplicitListTy.
Decide whether to parse list type syntax [Int] in a type as a
type or data constructor, based on the extension ListTuplePuns.
The case with an explicit promotion quote, '[Int], is handled
by mkExplicitListTy.
Call a parser with a span and its comments given by a start and end token.
Emit an error of type PsErrInvalidPun with a location from start to
end if the extension ListTuplePuns is disabled.
This is used in Parser.y to guard rules that require punning.