From 6b2cf62bbab9beaff3c1996ef370ed04c9a8cd49 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Fri, 14 Apr 2006 12:19:07 +0000 Subject: [PATCH] Allow $x, as well as $(x), at top level in TH Bulat pointed out that in Template Haskell $x is allowed instead of $(x) in expressions, but not at the top level of modules. This commit fixes the omission. Now you can say f x = x $h data T = T and the $h will run Template Haskell just as you'd expect. --- compiler/parser/Parser.y.pp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp index 3066a0f..ff230e9 100644 --- a/compiler/parser/Parser.y.pp +++ b/compiler/parser/Parser.y.pp @@ -439,9 +439,14 @@ topdecl :: { OrdList (LHsDecl RdrName) } | 'foreign' fdecl { unitOL (LL (unLoc $2)) } | '{-# DEPRECATED' deprecations '#-}' { $2 } | '{-# RULES' rules '#-}' { $2 } - | '$(' exp ')' { unitOL (LL $ SpliceD (SpliceDecl $2)) } | decl { unLoc $1 } + -- Template Haskell Extension + | '$(' exp ')' { unitOL (LL $ SpliceD (SpliceDecl $2)) } + | TH_ID_SPLICE { unitOL (LL $ SpliceD (SpliceDecl $ + L1 $ HsVar (mkUnqual varName (getTH_ID_SPLICE $1)) + )) } + tycl_decl :: { LTyClDecl RdrName } : 'type' type '=' ctype -- Note type on the left of the '='; this allows @@ -1099,7 +1104,7 @@ aexp2 :: { LHsExpr RdrName } | '(' qopm infixexp ')' { LL $ SectionR $2 $3 } | '_' { L1 EWildPat } - -- MetaHaskell Extension + -- Template Haskell Extension | TH_ID_SPLICE { L1 $ HsSpliceE (mkHsSplice (L1 $ HsVar (mkUnqual varName (getTH_ID_SPLICE $1)))) } -- $x -- 1.7.10.4