[project @ 2000-12-12 12:10:08 by simonmar]
[ghc-hetmet.git] / ghc / compiler / parser / Parser.y
index 6e7fbf6..dbc68a2 100644 (file)
@@ -1,6 +1,6 @@
 {-
 -----------------------------------------------------------------------------
-$Id: Parser.y,v 1.45 2000/10/26 16:51:44 sewardj Exp $
+$Id: Parser.y,v 1.49 2000/11/24 17:02:03 simonpj Exp $
 
 Haskell grammar.
 
@@ -9,7 +9,7 @@ Author(s): Simon Marlow, Sven Panne 1997, 1998, 1999
 -}
 
 {
-module Parser ( parse ) where
+module Parser ( ParseStuff(..), parse ) where
 
 import HsSyn
 import HsTypes         ( mkHsTupCon )
@@ -19,7 +19,7 @@ import RdrHsSyn
 import Lex
 import ParseUtil
 import RdrName
-import PrelInfo                ( mAIN_Name )
+import PrelNames
 import OccName         ( UserFS, varName, ipName, tcName, dataName, tcClsName, tvName )
 import SrcLoc          ( SrcLoc )
 import Module
@@ -113,6 +113,8 @@ Conflicts: 14 shift/reduce
  '{-# DEPRECATED'  { ITdeprecated_prag }
  '#-}'            { ITclose_prag }
 
+ '__expr'      { ITexpr }
+
 {-
  '__interface' { ITinterface }                 -- interface keywords
  '__export'    { IT__export }
@@ -202,6 +204,13 @@ Conflicts: 14 shift/reduce
 %%
 
 -----------------------------------------------------------------------------
+-- Entry points
+
+parse   :: { ParseStuff }
+       :  module                               { PModule $1 }
+       |  '__expr' exp                         { PExpr   $2 }
+
+-----------------------------------------------------------------------------
 -- Module Header
 
 -- The place for module deprecation is really too restrictive, but if it
@@ -344,7 +353,7 @@ topdecl :: { RdrBinding }
                        (binds,sigs) = cvMonoBindsAndSigs cvClassOpSig (groupBindings $5) 
                   in
                   returnP (RdrHsDecl (TyClD
-                     (mkClassDecl cs c ts $4 sigs binds $1))) }
+                     (mkClassDecl cs c ts $4 sigs (Just binds) $1))) }
 
        | srcloc 'instance' inst_type where
                { let (binds,sigs) 
@@ -732,8 +741,8 @@ aexp1       :: { RdrNameHsExpr }
        : ipvar                         { HsIPVar $1 }
        | var_or_con                    { $1 }
        | literal                       { HsLit $1 }
-       | INTEGER                       { HsOverLit (mkHsIntegralLit $1) }
-       | RATIONAL                      { HsOverLit (mkHsFractionalLit $1) }
+       | INTEGER                       { HsOverLit (HsIntegral   $1 fromInteger_RDR) }
+       | RATIONAL                      { HsOverLit (HsFractional $1 fromRational_RDR) }
        | '(' exp ')'                   { HsPar $2 }
        | '(' exp ',' texps ')'         { ExplicitTuple ($2 : reverse $4) Boxed}
        | '(#' texps '#)'               { ExplicitTuple (reverse $2)      Unboxed }
@@ -762,8 +771,14 @@ list :: { RdrNameHsExpr }
        | exp ',' exp '..'              { ArithSeqIn (FromThen $1 $3) }
        | exp '..' exp                  { ArithSeqIn (FromTo $1 $3) }
        | exp ',' exp '..' exp          { ArithSeqIn (FromThenTo $1 $3 $5) }
-       | exp srcloc '|' quals                  { HsDo ListComp (reverse 
-                                               (ReturnStmt $1 : $4)) $2 }
+       | exp srcloc pquals             {% let { body [qs] = qs;
+                                                body  qss = [ParStmt (map reverse qss)] }
+                                          in
+                                          returnP ( HsDo ListComp
+                                                          (reverse (ReturnStmt $1 : body $3))
+                                                          $2
+                                                 )
+                                       }
 
 lexps :: { [RdrNameHsExpr] }
        : lexps ',' exp                 { $3 : $1 }
@@ -772,6 +787,10 @@ lexps :: { [RdrNameHsExpr] }
 -----------------------------------------------------------------------------
 -- List Comprehensions
 
+pquals :: { [[RdrNameStmt]] }
+       : pquals '|' quals              { $3 : $1 }
+       | '|' quals                     { [$2] }
+
 quals :: { [RdrNameStmt] }
        : quals ',' qual                { $3 : $1 }
        | qual                          { [$1] }
@@ -1086,6 +1105,8 @@ commas :: { Int }
 -----------------------------------------------------------------------------
 
 {
+data ParseStuff = PModule RdrNameHsModule | PExpr RdrNameHsExpr
+
 happyError :: P a
 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)
 }