RdrHsSyn

ghc-8.8.0.20190721: The GHC API

Safe Haskell | None
Language | Haskell2010

RdrHsSyn

Synopsis

- mkHsOpApp :: LHsExpr GhcPs -> IdP GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs
- mkHsIntegral :: IntegralLit -> HsOverLit GhcPs
- mkHsFractional :: FractionalLit -> HsOverLit GhcPs
- mkHsIsString :: SourceText -> FastString -> HsOverLit GhcPs
- mkHsDo :: HsStmtContext Name -> [ExprLStmt GhcPs] -> HsExpr GhcPs
- mkSpliceDecl :: LHsExpr GhcPs -> HsDecl GhcPs
- mkRoleAnnotDecl :: SrcSpan -> Located RdrName -> [Located (Maybe FastString)] -> P (LRoleAnnotDecl GhcPs)
- mkClassDecl :: SrcSpan -> Located (Maybe (LHsContext GhcPs), LHsType GhcPs) -> Located (a, [LHsFunDep GhcPs]) -> OrdList (LHsDecl GhcPs) -> P (LTyClDecl GhcPs)
- mkTyData :: SrcSpan -> NewOrData -> Maybe (Located CType) -> Located (Maybe (LHsContext GhcPs), LHsType GhcPs) -> Maybe (LHsKind GhcPs) -> [LConDecl GhcPs] -> HsDeriving GhcPs -> P (LTyClDecl GhcPs)
- mkDataFamInst :: SrcSpan -> NewOrData -> Maybe (Located CType) -> (Maybe (LHsContext GhcPs), Maybe [LHsTyVarBndr GhcPs], LHsType GhcPs) -> Maybe (LHsKind GhcPs) -> [LConDecl GhcPs] -> HsDeriving GhcPs -> P (LInstDecl GhcPs)
- mkTySynonym :: SrcSpan -> LHsType GhcPs -> LHsType GhcPs -> P (LTyClDecl GhcPs)
- mkTyFamInstEqn :: Maybe [LHsTyVarBndr GhcPs] -> LHsType GhcPs -> LHsType GhcPs -> P (TyFamInstEqn GhcPs, [AddAnn])
- mkTyFamInst :: SrcSpan -> TyFamInstEqn GhcPs -> P (LInstDecl GhcPs)
- mkFamDecl :: SrcSpan -> FamilyInfo GhcPs -> LHsType GhcPs -> Located (FamilyResultSig GhcPs) -> Maybe (LInjectivityAnn GhcPs) -> P (LTyClDecl GhcPs)
- mkLHsSigType :: LHsType GhcPs -> LHsSigType GhcPs
- mkInlinePragma :: SourceText -> (InlineSpec, RuleMatchInfo) -> Maybe Activation -> InlinePragma
- mkPatSynMatchGroup :: Located RdrName -> Located (OrdList (LHsDecl GhcPs)) -> P (MatchGroup GhcPs (LHsExpr GhcPs))
- mkRecConstrOrUpdate :: LHsExpr GhcPs -> SrcSpan -> ([LHsRecField GhcPs (LHsExpr GhcPs)], Bool) -> P (HsExpr GhcPs)
- mkTyClD :: LTyClDecl (GhcPass p) -> LHsDecl (GhcPass p)
- mkInstD :: LInstDecl (GhcPass p) -> LHsDecl (GhcPass p)
- mkRdrRecordCon :: Located RdrName -> HsRecordBinds GhcPs -> HsExpr GhcPs
- mkRdrRecordUpd :: LHsExpr GhcPs -> [LHsRecUpdField GhcPs] -> HsExpr GhcPs
- setRdrNameSpace :: RdrName -> NameSpace -> RdrName
- filterCTuple :: RdrName -> RdrName
- cvBindGroup :: OrdList (LHsDecl GhcPs) -> P (HsValBinds GhcPs)
- cvBindsAndSigs :: OrdList (LHsDecl GhcPs) -> P (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs], [LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl])
- cvTopDecls :: OrdList (LHsDecl GhcPs) -> [LHsDecl GhcPs]
- placeHolderPunRhs :: LHsExpr GhcPs
- mkImport :: Located CCallConv -> Located Safety -> (Located StringLiteral, Located RdrName, LHsSigType GhcPs) -> P (HsDecl GhcPs)
- parseCImport :: Located CCallConv -> Located Safety -> FastString -> String -> Located SourceText -> Maybe ForeignImport
- mkExport :: Located CCallConv -> (Located StringLiteral, Located RdrName, LHsSigType GhcPs) -> P (HsDecl GhcPs)
- mkExtName :: RdrName -> CLabelString
- mkGadtDecl :: [Located RdrName] -> LHsType GhcPs -> (ConDecl GhcPs, [AddAnn])
- mkConDeclH98 :: Located RdrName -> Maybe [LHsTyVarBndr GhcPs] -> Maybe (LHsContext GhcPs) -> HsConDeclDetails GhcPs -> ConDecl GhcPs
- mkATDefault :: LTyFamInstDecl GhcPs -> Either (SrcSpan, SDoc) (LTyFamDefltEqn GhcPs, P ())
- checkBlockArguments :: LHsExpr GhcPs -> P ()
- checkPrecP :: Located (SourceText, Int) -> Located (OrdList (Located RdrName)) -> P ()
- checkContext :: LHsType GhcPs -> P ([AddAnn], LHsContext GhcPs)
- checkPattern :: SDoc -> LHsExpr GhcPs -> P (LPat GhcPs)
- bang_RDR :: RdrName
- isBangRdr :: RdrName -> Bool
- checkPatterns :: SDoc -> [LHsExpr GhcPs] -> P [LPat GhcPs]
- checkMonadComp :: P (HsStmtContext Name)
- checkCommand :: LHsExpr GhcPs -> P (LHsCmd GhcPs)
- checkValDef :: SDoc -> SrcStrictness -> LHsExpr GhcPs -> Maybe (LHsType GhcPs) -> Located (a, GRHSs GhcPs (LHsExpr GhcPs)) -> P ([AddAnn], HsBind GhcPs)
- checkValSigLhs :: LHsExpr GhcPs -> P (Located RdrName)
- checkDoAndIfThenElse :: LHsExpr GhcPs -> Bool -> LHsExpr GhcPs -> Bool -> LHsExpr GhcPs -> P ()
- type LRuleTyTmVar = Located RuleTyTmVar
- data RuleTyTmVar = RuleTyTmVar (Located RdrName) (Maybe (LHsType GhcPs))
- mkRuleBndrs :: [LRuleTyTmVar] -> [LRuleBndr GhcPs]
- mkRuleTyVarBndrs :: [LRuleTyTmVar] -> [LHsTyVarBndr GhcPs]
- checkRuleTyVarBndrNames :: [LHsTyVarBndr GhcPs] -> P ()
- checkRecordSyntax :: Outputable a => Located a -> P (Located a)
- checkEmptyGADTs :: Located ([AddAnn], [LConDecl GhcPs]) -> P (Located ([AddAnn], [LConDecl GhcPs]))
- parseErrorSDoc :: SrcSpan -> SDoc -> P a
- hintBangPat :: SrcSpan -> HsExpr GhcPs -> P ()
- data TyEl
  - = TyElOpr RdrName
  - | TyElOpd (HsType GhcPs)
  - | TyElKindApp SrcSpan (LHsType GhcPs)
  - | TyElTilde
  - | TyElBang
  - | TyElUnpackedness ([AddAnn], SourceText, SrcUnpackedness)
  - | TyElDocPrev HsDocString
- mergeOps :: [Located TyEl] -> P (LHsType GhcPs)
- mergeDataCon :: [Located TyEl] -> P (Located RdrName, HsConDeclDetails GhcPs, Maybe LHsDocString)
- data ImpExpSubSpec
  - = ImpExpAbs
  - | ImpExpAll
  - | ImpExpList [Located ImpExpQcSpec]
  - | ImpExpAllWith [Located ImpExpQcSpec]
- data ImpExpQcSpec
  - = ImpExpQcName (Located RdrName)
  - | ImpExpQcType (Located RdrName)
  - | ImpExpQcWildcard
- mkModuleImpExp :: Located ImpExpQcSpec -> ImpExpSubSpec -> P (IE GhcPs)
- mkTypeImpExp :: Located RdrName -> P (Located RdrName)
- mkImpExpSubSpec :: [Located ImpExpQcSpec] -> P ([AddAnn], ImpExpSubSpec)
- checkImportSpec :: Located [LIE GhcPs] -> P (Located [LIE GhcPs])
- forallSym :: Bool -> String
- starSym :: Bool -> String
- warnStarIsType :: SrcSpan -> P ()
- failOpFewArgs :: Located RdrName -> P a
- data SumOrTuple
  - = Sum ConTag Arity (LHsExpr GhcPs)
  - | Tuple [LHsTupArg GhcPs]
- mkSumOrTuple :: Boxity -> SrcSpan -> SumOrTuple -> P (HsExpr GhcPs)

# Documentation

mkHsOpApp :: LHsExpr GhcPs -> IdP GhcPs -> LHsExpr GhcPs -> HsExpr GhcPs Source #

mkHsIntegral :: IntegralLit -> HsOverLit GhcPs Source #

mkHsFractional :: FractionalLit -> HsOverLit GhcPs Source #

mkHsIsString :: SourceText -> FastString -> HsOverLit GhcPs Source #

mkHsDo :: HsStmtContext Name -> [ExprLStmt GhcPs] -> HsExpr GhcPs Source #

mkSpliceDecl :: LHsExpr GhcPs -> HsDecl GhcPs Source #

mkRoleAnnotDecl :: SrcSpan -> Located RdrName -> [Located (Maybe FastString)] -> P (LRoleAnnotDecl GhcPs) Source #

mkClassDecl :: SrcSpan -> Located (Maybe (LHsContext GhcPs), LHsType GhcPs) -> Located (a, [LHsFunDep GhcPs]) -> OrdList (LHsDecl GhcPs) -> P (LTyClDecl GhcPs) Source #

mkTyData :: SrcSpan -> NewOrData -> Maybe (Located CType) -> Located (Maybe (LHsContext GhcPs), LHsType GhcPs) -> Maybe (LHsKind GhcPs) -> [LConDecl GhcPs] -> HsDeriving GhcPs -> P (LTyClDecl GhcPs) Source #

mkDataFamInst :: SrcSpan -> NewOrData -> Maybe (Located CType) -> (Maybe (LHsContext GhcPs), Maybe [LHsTyVarBndr GhcPs], LHsType GhcPs) -> Maybe (LHsKind GhcPs) -> [LConDecl GhcPs] -> HsDeriving GhcPs -> P (LInstDecl GhcPs) Source #

mkTySynonym :: SrcSpan -> LHsType GhcPs -> LHsType GhcPs -> P (LTyClDecl GhcPs) Source #

mkTyFamInstEqn :: Maybe [LHsTyVarBndr GhcPs] -> LHsType GhcPs -> LHsType GhcPs -> P (TyFamInstEqn GhcPs, [AddAnn]) Source #

mkTyFamInst :: SrcSpan -> TyFamInstEqn GhcPs -> P (LInstDecl GhcPs) Source #

mkFamDecl :: SrcSpan -> FamilyInfo GhcPs -> LHsType GhcPs -> Located (FamilyResultSig GhcPs) -> Maybe (LInjectivityAnn GhcPs) -> P (LTyClDecl GhcPs) Source #

mkLHsSigType :: LHsType GhcPs -> LHsSigType GhcPs Source #

mkInlinePragma :: SourceText -> (InlineSpec, RuleMatchInfo) -> Maybe Activation -> InlinePragma Source #

mkPatSynMatchGroup :: Located RdrName -> Located (OrdList (LHsDecl GhcPs)) -> P (MatchGroup GhcPs (LHsExpr GhcPs)) Source #

mkRecConstrOrUpdate :: LHsExpr GhcPs -> SrcSpan -> ([LHsRecField GhcPs (LHsExpr GhcPs)], Bool) -> P (HsExpr GhcPs) Source #

mkTyClD :: LTyClDecl (GhcPass p) -> LHsDecl (GhcPass p) Source #

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).

mkInstD :: LInstDecl (GhcPass p) -> LHsDecl (GhcPass p) Source #

mkRdrRecordCon :: Located RdrName -> HsRecordBinds GhcPs -> HsExpr GhcPs Source #

mkRdrRecordUpd :: LHsExpr GhcPs -> [LHsRecUpdField GhcPs] -> HsExpr GhcPs Source #

setRdrNameSpace :: RdrName -> NameSpace -> RdrName Source #

This rather gruesome function is used mainly by the parser. When parsing:

    data T a = T | T1 Int

we 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.

filterCTuple :: RdrName -> RdrName Source #

Replaces constraint tuple names with corresponding boxed ones.

cvBindGroup :: OrdList (LHsDecl GhcPs) -> P (HsValBinds GhcPs) Source #

cvBindsAndSigs :: OrdList (LHsDecl GhcPs) -> P (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs], [LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl]) Source #

cvTopDecls :: OrdList (LHsDecl GhcPs) -> [LHsDecl GhcPs] Source #

Function definitions are restructured here. Each is assumed to be recursive initially, and non recursive definitions are discovered by the dependency analyser.

placeHolderPunRhs :: LHsExpr GhcPs Source #

mkImport :: Located CCallConv -> Located Safety -> (Located StringLiteral, Located RdrName, LHsSigType GhcPs) -> P (HsDecl GhcPs) Source #

parseCImport :: Located CCallConv -> Located Safety -> FastString -> String -> Located SourceText -> Maybe ForeignImport Source #

mkExport :: Located CCallConv -> (Located StringLiteral, Located RdrName, LHsSigType GhcPs) -> P (HsDecl GhcPs) Source #

mkExtName :: RdrName -> CLabelString Source #

mkGadtDecl :: [Located RdrName] -> LHsType GhcPs -> (ConDecl GhcPs, [AddAnn]) Source #

mkConDeclH98 :: Located RdrName -> Maybe [LHsTyVarBndr GhcPs] -> Maybe (LHsContext GhcPs) -> HsConDeclDetails GhcPs -> ConDecl GhcPs Source #

mkATDefault :: LTyFamInstDecl GhcPs -> Either (SrcSpan, SDoc) (LTyFamDefltEqn GhcPs, P ()) Source #

Take a type-family instance declaration and turn it into a type-family default equation for a class declaration. We parse things as the former and use this function to convert to the latter

We use the Either monad because this also called from Convert.

The `P ()` we return corresponds represents an action which will add some necessary paren annotations to the parsing context. Naturally, this is not something that the Convert use cares about.

checkBlockArguments :: LHsExpr GhcPs -> P () Source #

Yield a parse error if we have a function applied directly to a do block etc. and BlockArguments is not enabled.

checkPrecP Source #

Arguments

:: Located (SourceText, Int) | precedence
-> Located (OrdList (Located RdrName)) | operators
-> P () |

Check if a fixity is valid. We support bypassing the usual bound checks for some special operators.

checkContext :: LHsType GhcPs -> P ([AddAnn], LHsContext GhcPs) Source #

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]

checkPattern :: SDoc -> LHsExpr GhcPs -> P (LPat GhcPs) Source #

bang_RDR :: RdrName Source #

isBangRdr :: RdrName -> Bool Source #

checkPatterns :: SDoc -> [LHsExpr GhcPs] -> P [LPat GhcPs] Source #

checkMonadComp :: P (HsStmtContext Name) Source #

Check for monad comprehensions

If the flag MonadComprehensions is set, return a `MonadComp` context, otherwise use the usual `ListComp` context

checkCommand :: LHsExpr GhcPs -> P (LHsCmd GhcPs) Source #

checkValDef :: SDoc -> SrcStrictness -> LHsExpr GhcPs -> Maybe (LHsType GhcPs) -> Located (a, GRHSs GhcPs (LHsExpr GhcPs)) -> P ([AddAnn], HsBind GhcPs) Source #

checkValSigLhs :: LHsExpr GhcPs -> P (Located RdrName) Source #

checkDoAndIfThenElse :: LHsExpr GhcPs -> Bool -> LHsExpr GhcPs -> Bool -> LHsExpr GhcPs -> P () Source #

type LRuleTyTmVar = Located RuleTyTmVar Source #

data RuleTyTmVar Source #

Essentially a wrapper for a `RuleBndr GhcPs`

Constructors

RuleTyTmVar (Located RdrName) (Maybe (LHsType GhcPs)) |

mkRuleBndrs :: [LRuleTyTmVar] -> [LRuleBndr GhcPs] Source #

mkRuleTyVarBndrs :: [LRuleTyTmVar] -> [LHsTyVarBndr GhcPs] Source #

checkRuleTyVarBndrNames :: [LHsTyVarBndr GhcPs] -> P () Source #

checkRecordSyntax :: Outputable a => Located a -> P (Located a) Source #

checkEmptyGADTs :: Located ([AddAnn], [LConDecl GhcPs]) -> P (Located ([AddAnn], [LConDecl GhcPs])) Source #

Check if the gadt_constrlist is empty. Only raise parse error for `data T where` to avoid affecting existing error message, see #8258.

parseErrorSDoc :: SrcSpan -> SDoc -> P a Source #

hintBangPat :: SrcSpan -> HsExpr GhcPs -> P () Source #

Hint about bang patterns, assuming `BangPatterns` is off.

data TyEl Source #

Either an operator or an operand.

Constructors

TyElOpr RdrName |
TyElOpd (HsType GhcPs) |
TyElKindApp SrcSpan (LHsType GhcPs) |
TyElTilde |
TyElBang |
TyElUnpackedness ([AddAnn], SourceText, SrcUnpackedness) |
TyElDocPrev HsDocString |

#### Instances

Instances details

Outputable TyEl # |
Instance details Defined in RdrHsSyn Methods ppr :: TyEl -> SDoc Source # pprPrec :: Rational -> TyEl -> SDoc Source #

mergeOps :: [Located TyEl] -> P (LHsType GhcPs) Source #

Merge a reversed and non-empty soup of operators and operands into a type.

User input: `F x y + G a b * X` Input to `mergeOps`: [X, *, b, a, G, +, y, x, F] Output corresponds to what the user wrote assuming all operators are of the same fixity and right-associative.

It's a bit silly that we're doing it at all, as the renamer will have to rearrange this, and it'd be easier to keep things separate.

See Note [Parsing data constructors is hard]

mergeDataCon :: [Located TyEl] -> P (Located RdrName, HsConDeclDetails GhcPs, Maybe LHsDocString) Source #

Merge a reversed and non-empty soup of operators and operands into a data constructor.

User input: `C !A B -- ^ doc` Input to `mergeDataCon`: ["doc", B, !, A, C] Output: (C, PrefixCon [!A, B], "doc")

See Note [Parsing data constructors is hard] See Note [isFunLhs vs mergeDataCon]

data ImpExpSubSpec Source #

Constructors

ImpExpAbs |
ImpExpAll |
ImpExpList [Located ImpExpQcSpec] |
ImpExpAllWith [Located ImpExpQcSpec] |

data ImpExpQcSpec Source #

Constructors

ImpExpQcName (Located RdrName) |
ImpExpQcType (Located RdrName) |
ImpExpQcWildcard |

mkModuleImpExp :: Located ImpExpQcSpec -> ImpExpSubSpec -> P (IE GhcPs) Source #

mkTypeImpExp :: Located RdrName -> P (Located RdrName) Source #

mkImpExpSubSpec :: [Located ImpExpQcSpec] -> P ([AddAnn], ImpExpSubSpec) Source #

checkImportSpec :: Located [LIE GhcPs] -> P (Located [LIE GhcPs]) Source #

forallSym :: Bool -> String Source #

starSym :: Bool -> String Source #

warnStarIsType :: SrcSpan -> P () Source #

failOpFewArgs :: Located RdrName -> P a Source #

data SumOrTuple Source #

Constructors

Sum ConTag Arity (LHsExpr GhcPs) |
Tuple [LHsTupArg GhcPs] |

mkSumOrTuple :: Boxity -> SrcSpan -> SumOrTuple -> P (HsExpr GhcPs) Source #