summaryrefslogtreecommitdiff
path: root/compiler/parser
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2013-11-25 16:58:28 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2013-11-25 16:58:43 +0000
commit51deeb0db3abac9f4369d3f8a3744e1313ecebf4 (patch)
treefde7b556b53bdbf5f6f0adaecdd14e723acb27af /compiler/parser
parentf8b25c30fe593a1195a4f4840b8773595dd0f2e0 (diff)
downloadhaskell-51deeb0db3abac9f4369d3f8a3744e1313ecebf4.tar.gz
Another raft of Template Haskell clean-up
The handling of typed and untyped brackets was extremely convoluted, partly because of the evolutionary history. I've tidied it all up. See Note [How brackets and nested splices are handled] in TcSplice for the full story Main changes: * Untyped brackets: after the renamer, HsRnBracketOut carries PendingRnSplices for splices in untyped brackets. In the typechecker, these pending splices are typechecked quite straigtforwardly, with no ps_var nonsense. * Typed brackets: after the renamer typed brackest still look like HsBracket. The type checker does the ps_var thing. * In TcRnTypes.ThStage, the Brack constructor, we distinguish the renaming from typehecking pending-stuff. Much more perspicuous! * The "typed" flag is in HsSpliceE, not in HsSplice, because only expressions can be typed. Patterns, types, declarations cannot. There is further improvement to be done to make the handling of declaration splices more uniform.
Diffstat (limited to 'compiler/parser')
-rw-r--r--compiler/parser/RdrHsSyn.lhs23
1 files changed, 13 insertions, 10 deletions
diff --git a/compiler/parser/RdrHsSyn.lhs b/compiler/parser/RdrHsSyn.lhs
index 46a694b42b..79e53b26ae 100644
--- a/compiler/parser/RdrHsSyn.lhs
+++ b/compiler/parser/RdrHsSyn.lhs
@@ -1,4 +1,4 @@
-%
+o%
% (c) The University of Glasgow, 1996-2003
Functions over HsSyn specialised to RdrName.
@@ -235,11 +235,13 @@ mkSpliceDecl :: LHsExpr RdrName -> HsDecl RdrName
-- but if she wrote, say,
-- f x then behave as if she'd written $(f x)
-- ie a SpliceD
-mkSpliceDecl (L _ (HsQuasiQuoteE qq)) = QuasiQuoteD qq
-mkSpliceDecl (L loc (HsSpliceE splice)) = SpliceD (SpliceDecl (L loc splice) Explicit)
-mkSpliceDecl other_expr = SpliceD (SpliceDecl (L (getLoc other_expr) splice) Implicit)
+mkSpliceDecl lexpr@(L loc expr)
+ | HsQuasiQuoteE qq <- expr = QuasiQuoteD qq
+ | HsSpliceE is_typed splice <- expr = ASSERT( not is_typed )
+ SpliceD (SpliceDecl (L loc splice) Explicit)
+ | otherwise = SpliceD (SpliceDecl (L loc splice) Implicit)
where
- HsSpliceE splice = mkHsSpliceE other_expr
+ splice = mkHsSplice lexpr
mkTyLit :: Located (HsTyLit) -> P (LHsType RdrName)
mkTyLit l =
@@ -675,11 +677,12 @@ checkAPat msg loc e0 = do
| otherwise -> parseErrorSDoc loc (text "Illegal tuple section in pattern:" $$ ppr e0)
RecordCon c _ (HsRecFields fs dd)
- -> do fs <- mapM (checkPatField msg) fs
- return (ConPatIn c (RecCon (HsRecFields fs dd)))
- HsSpliceE s -> return (SplicePat s)
- HsQuasiQuoteE q -> return (QuasiQuotePat q)
- _ -> patFail msg loc e0
+ -> do fs <- mapM (checkPatField msg) fs
+ return (ConPatIn c (RecCon (HsRecFields fs dd)))
+ HsSpliceE is_typed s | not is_typed
+ -> return (SplicePat s)
+ HsQuasiQuoteE q -> return (QuasiQuotePat q)
+ _ -> patFail msg loc e0
placeHolderPunRhs :: LHsExpr RdrName
-- The RHS of a punned record field will be filled in by the renamer