Allow $x, as well as $(x), at top level in TH
authorsimonpj@microsoft.com <unknown>
Fri, 14 Apr 2006 12:19:07 +0000 (12:19 +0000)
committersimonpj@microsoft.com <unknown>
Fri, 14 Apr 2006 12:19:07 +0000 (12:19 +0000)
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

index 3066a0f..ff230e9 100644 (file)
@@ -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