A couple more parser tweaks
[ghc-hetmet.git] / compiler / parser / Parser.y.pp
index 6de95f8..418f0a1 100644 (file)
@@ -27,6 +27,7 @@ import HscTypes               ( IsBootInterface, DeprecTxt )
 import Lexer
 import RdrName
 import TysWiredIn      ( unitTyCon, unitDataCon, tupleTyCon, tupleCon, nilDataCon,
+                         unboxedSingletonTyCon, unboxedSingletonDataCon,
                          listTyCon_RDR, parrTyCon_RDR, consDataCon_RDR )
 import Type            ( funTyCon )
 import ForeignCall     ( Safety(..), CExportSpec(..), CLabelString,
@@ -336,6 +337,7 @@ TH_ID_SPLICE    { L _ (ITidEscape _)  }     -- $x
 '$('           { L _ ITparenEscape   }     -- $( exp )
 TH_VAR_QUOTE   { L _ ITvarQuote      }     -- 'x
 TH_TY_QUOTE    { L _ ITtyQuote       }      -- ''T
+TH_QUASIQUOTE  { L _ (ITquasiQuote _) }
 
 %monad { P } { >>= } { return }
 %lexer { lexer } { L _ ITeof }
@@ -820,7 +822,11 @@ where_inst :: { Located (OrdList (LHsDecl RdrName)) }      -- Reversed
 -- Declarations in binding groups other than classes and instances
 --
 decls  :: { Located (OrdList (LHsDecl RdrName)) }      
-       : decls ';' decl                { LL (unLoc $1 `appOL` unLoc $3) }
+       : decls ';' decl                { let { this = unLoc $3;
+                                    rest = unLoc $1;
+                                    these = rest `appOL` this }
+                              in rest `seq` this `seq` these `seq`
+                                    LL these }
        | decls ';'                     { LL (unLoc $1) }
        | decl                          { $1 }
        | {- empty -}                   { noLoc nilOL }
@@ -1219,8 +1225,9 @@ decl      :: { Located (OrdList (LHsDecl RdrName)) }
                                                return (LL $ unitOL $ LL $ ValD ( 
                                                        PatBind (LL $ BangPat pat) (unLoc $3)
                                                                placeHolderType placeHolderNames)) } }
-       | infixexp opt_sig rhs          {% do { r <- checkValDef $1 $2 $3;
-                                               return (LL $ unitOL (LL $ ValD r)) } }
+        | infixexp opt_sig rhs          {% do { r <- checkValDef $1 $2 $3;
+                                                let { l = comb2 $1 $> };
+                                                return $! (sL l (unitOL $! (sL l $ ValD r))) } }
         | docdecl                       { LL $ unitOL $1 }
 
 rhs    :: { Located (GRHSs RdrName) }
@@ -1367,6 +1374,11 @@ aexp2    :: { LHsExpr RdrName }
                                                        (getTH_ID_SPLICE $1)))) } -- $x
        | '$(' exp ')'          { LL $ HsSpliceE (mkHsSplice $2) }               -- $( exp )
 
+       | TH_QUASIQUOTE         { let { loc = getLoc $1
+                                      ; ITquasiQuote (quoter, quote, quoteSpan) = unLoc $1
+                                      ; quoterId = mkUnqual varName quoter
+                                      }
+                                  in sL loc $ HsQuasiQuoteE (mkHsQuasiQuote quoterId quoteSpan quote) }
        | TH_VAR_QUOTE qvar     { LL $ HsBracket (VarBr (unLoc $2)) }
        | TH_VAR_QUOTE qcon     { LL $ HsBracket (VarBr (unLoc $2)) }
        | TH_TY_QUOTE tyvar     { LL $ HsBracket (VarBr (unLoc $2)) }
@@ -1617,9 +1629,10 @@ fbind    :: { HsRecField RdrName (LHsExpr RdrName) }
 -- Implicit Parameter Bindings
 
 dbinds         :: { Located [LIPBind RdrName] }
-       : dbinds ';' dbind              { LL ($3 : unLoc $1) }
+       : dbinds ';' dbind              { let { this = $3; rest = unLoc $1 }
+                              in rest `seq` this `seq` LL (this : rest) }
        | dbinds ';'                    { LL (unLoc $1) }
-       | dbind                         { L1 [$1] }
+       | dbind                         { let this = $1 in this `seq` L1 [this] }
 --     | {- empty -}                   { [] }
 
 dbind  :: { LIPBind RdrName }
@@ -1655,6 +1668,8 @@ con       :: { Located RdrName }
 sysdcon        :: { Located DataCon }  -- Wired in data constructors
        : '(' ')'               { LL unitDataCon }
        | '(' commas ')'        { LL $ tupleCon Boxed $2 }
+       | '(#' '#)'             { LL $ unboxedSingletonDataCon }
+       | '(#' commas '#)'      { LL $ tupleCon Unboxed $2 }
        | '[' ']'               { LL nilDataCon }
 
 conop :: { Located RdrName }
@@ -1672,6 +1687,8 @@ gtycon    :: { Located RdrName }  -- A "general" qualified tycon
        : oqtycon                       { $1 }
        | '(' ')'                       { LL $ getRdrName unitTyCon }
        | '(' commas ')'                { LL $ getRdrName (tupleTyCon Boxed $2) }
+       | '(#' '#)'                     { LL $ getRdrName unboxedSingletonTyCon }
+       | '(#' commas '#)'              { LL $ getRdrName (tupleTyCon Unboxed $2) }
        | '(' '->' ')'                  { LL $ getRdrName funTyCon }
        | '[' ']'                       { LL $ listTyCon_RDR }
        | '[:' ':]'                     { LL $ parrTyCon_RDR }
@@ -1896,7 +1913,7 @@ docnamed :: { Located (String, (HsDoc RdrName)) }
         MyLeft  err -> parseError (getLoc $1) err;
         MyRight doc -> return (L1 (name, doc)) } }
 
-docsection :: { Located (n, HsDoc RdrName) }
+docsection :: { Located (Int, HsDoc RdrName) }
   : DOCSECTION {% let (n, doc) = getDOCSECTION $1 in
         case parseHaddockString (tokenise doc) of {
       MyLeft  err -> parseError (getLoc $1) err;
@@ -1954,19 +1971,21 @@ getDOCSECTION (L _ (ITdocSection n x)) = (n, x)
 
 -- Utilities for combining source spans
 comb2 :: Located a -> Located b -> SrcSpan
-comb2 = combineLocs
+comb2 a b = a `seq` b `seq` combineLocs a b
 
 comb3 :: Located a -> Located b -> Located c -> SrcSpan
-comb3 a b c = combineSrcSpans (getLoc a) (combineSrcSpans (getLoc b) (getLoc c))
+comb3 a b c = a `seq` b `seq` c `seq`
+    combineSrcSpans (getLoc a) (combineSrcSpans (getLoc b) (getLoc c))
 
 comb4 :: Located a -> Located b -> Located c -> Located d -> SrcSpan
-comb4 a b c d = combineSrcSpans (getLoc a) $ combineSrcSpans (getLoc b) $
-               combineSrcSpans (getLoc c) (getLoc d)
+comb4 a b c d = a `seq` b `seq` c `seq` d `seq`
+    (combineSrcSpans (getLoc a) $ combineSrcSpans (getLoc b) $
+               combineSrcSpans (getLoc c) (getLoc d))
 
 -- strict constructor version:
 {-# INLINE sL #-}
 sL :: SrcSpan -> a -> Located a
-sL span a = span `seq` L span a
+sL span a = span `seq` a `seq` L span a
 
 -- Make a source location for the file.  We're a bit lazy here and just
 -- make a point SrcSpan at line 1, column 0.  Strictly speaking we should