[project @ 2003-08-19 14:22:14 by panne]
[ghc-hetmet.git] / ghc / compiler / parser / Parser.y
index d434747..1802117 100644 (file)
@@ -1,6 +1,6 @@
 {-                                                             -*-haskell-*-
 -----------------------------------------------------------------------------
-$Id: Parser.y,v 1.112 2002/10/24 14:17:50 simonpj Exp $
+$Id: Parser.y,v 1.121 2003/07/16 08:49:05 ross Exp $
 
 Haskell grammar.
 
@@ -17,17 +17,18 @@ import HsSyn
 import HsTypes         ( mkHsTupCon )
 
 import RdrHsSyn
-import HscTypes                ( ParsedIface(..), IsBootInterface )
+import HscTypes                ( ParsedIface(..), IsBootInterface, noDependencies )
 import Lex
 import RdrName
 import PrelNames       ( mAIN_Name, funTyConName, listTyConName, 
-                         parrTyConName, consDataConName, nilDataConName )
-import TysWiredIn      ( unitTyCon, unitDataCon, tupleTyCon, tupleCon )
+                         parrTyConName, consDataConName )
+import TysWiredIn      ( unitTyCon, unitDataCon, tupleTyCon, tupleCon, nilDataCon )
 import ForeignCall     ( Safety(..), CExportSpec(..), 
                          CCallConv(..), CCallTarget(..), defaultCCallConv,
                        )
 import OccName         ( UserFS, varName, tcName, dataName, tcClsName, tvName )
 import TyCon           ( DataConDetails(..) )
+import DataCon         ( DataCon, dataConName )
 import SrcLoc          ( SrcLoc )
 import Module
 import CmdLineOpts     ( opt_SccProfilingOn, opt_InPackage )
@@ -129,6 +130,8 @@ Conflicts: 29 shift/reduce, [SDM 19/9/2002]
  'stdcall'      { ITstdcallconv }
  'ccall'        { ITccallconv }
  'dotnet'       { ITdotnet }
+ 'proc'                { ITproc }              -- for arrow notation extension
+ 'rec'         { ITrec }               -- for arrow notation extension
  '_ccall_'     { ITccall (False, False, PlayRisky) }
  '_ccall_GC_'  { ITccall (False, False, PlaySafe False) }
  '_casm_'      { ITccall (False, True,  PlayRisky) }
@@ -139,6 +142,7 @@ Conflicts: 29 shift/reduce, [SDM 19/9/2002]
  '{-# INLINE'      { ITinline_prag }
  '{-# NOINLINE'    { ITnoinline_prag }
  '{-# RULES'      { ITrules_prag }
+ '{-# CORE'        { ITcore_prag }              -- hdaume: annotated core
  '{-# SCC'        { ITscc_prag }
  '{-# DEPRECATED'  { ITdeprecated_prag }
  '#-}'            { ITclose_prag }
@@ -187,6 +191,10 @@ Conflicts: 29 shift/reduce, [SDM 19/9/2002]
  '-'           { ITminus }
  '!'           { ITbang }
  '*'           { ITstar }
+ '-<'          { ITlarrowtail }                -- for arrow notation
+ '>-'          { ITrarrowtail }                -- for arrow notation
+ '-<<'         { ITLarrowtail }                -- for arrow notation
+ '>>-'         { ITRarrowtail }                -- for arrow notation
  '.'           { ITdot }
 
  '{'           { ITocurly }                    -- special symbols
@@ -202,6 +210,8 @@ Conflicts: 29 shift/reduce, [SDM 19/9/2002]
  ')'           { ITcparen }
  '(#'          { IToubxparen }
  '#)'          { ITcubxparen }
+ '(|'          { IToparenbar }
+ '|)'          { ITcparenbar }
  ';'           { ITsemi }
  ','           { ITcomma }
  '`'           { ITbackquote }
@@ -263,10 +273,9 @@ REIFY_FIXITY       { ITreifyFixity }
 
 module         :: { RdrNameHsModule }
        : srcloc 'module' modid maybemoddeprec maybeexports 'where' body 
-               { HsModule (mkHomeModule $3) Nothing $5 (fst $7) (snd $7) $4 $1 }
+               { HsModule (Just (mkHomeModule $3)) $5 (fst $7) (snd $7) $4 $1 }
        | srcloc body
-               { HsModule (mkHomeModule mAIN_Name) Nothing Nothing 
-                          (fst $2) (snd $2) Nothing $1 }
+               { HsModule Nothing Nothing (fst $2) (snd $2) Nothing $1 }
 
 maybemoddeprec :: { Maybe DeprecTxt }
        : '{-# DEPRECATED' STRING '#-}'         { Just $2 }
@@ -295,7 +304,7 @@ iface   :: { ParsedIface }
                        pi_vers    = 1,                 -- Module version
                        pi_orphan  = False,
                        pi_exports = (1,[($2,mkIfaceExports $4)]),
-                       pi_deps    = ([],[]),
+                       pi_deps    = noDependencies,
                        pi_usages  = [],
                        pi_fixity  = [],
                        pi_insts   = [],
@@ -441,7 +450,7 @@ tycl_decl :: { RdrNameTyClDecl }
                { let 
                        (binds,sigs) = cvMonoBindsAndSigs $5 
                  in
-                 mkClassDecl $3 $4 (map cvClassOpSig sigs) (Just binds) $1 }
+                 mkClassDecl $3 $4 sigs (Just binds) $1 }
 
 syn_hdr :: { (RdrName, [RdrNameHsTyVar]) }     -- We don't retain the syntax of an infix
                                                -- type synonym declaration. Oh well.
@@ -926,6 +935,10 @@ sigdecl :: { RdrBinding }
 exp   :: { RdrNameHsExpr }
        : infixexp '::' sigtype         { ExprWithTySig $1 $3 }
        | infixexp 'with' dbinding      { HsLet (IPBinds $3 True{-not a let-}) $1 }
+       | fexp srcloc '-<' exp          { HsArrApp $1 $4 placeHolderType HsFirstOrderApp True $2 }
+       | fexp srcloc '>-' exp          { HsArrApp $4 $1 placeHolderType HsFirstOrderApp False $2 }
+       | fexp srcloc '-<<' exp         { HsArrApp $1 $4 placeHolderType HsHigherOrderApp True $2 }
+       | fexp srcloc '>>-' exp         { HsArrApp $4 $1 placeHolderType HsHigherOrderApp False $2 }
        | infixexp                      { $1 }
 
 infixexp :: { RdrNameHsExpr }
@@ -957,6 +970,12 @@ exp10 :: { RdrNameHsExpr }
                                                        then HsSCC $1 $2
                                                        else HsPar $2 }
 
+       | 'proc' srcloc aexp '->' srcloc exp    
+                       {% checkPattern $2 $3 `thenP` \ p -> 
+                          returnP (HsProc p (HsCmdTop $6 [] placeHolderType undefined) $5) }
+
+        | '{-# CORE' STRING '#-}' exp           { HsCoreAnn $2 $4 }    -- hdaume: core annotation
+
        | reifyexp                              { HsReify $1 }
        | fexp                                  { $1 }
 
@@ -1021,8 +1040,22 @@ aexp2    :: { RdrNameHsExpr }
        | srcloc '[t|' ctype '|]'       { HsBracket (TypBr $3) $1 }                       
        | srcloc '[p|' infixexp '|]'    {% checkPattern $1 $3 `thenP` \p ->
                                           returnP (HsBracket (PatBr p) $1) }
-       | srcloc '[d|' cvtopdecls '|]'  { HsBracket (DecBr (mkGroup $3)) $1 }
+       | srcloc '[d|' cvtopbody '|]'   { HsBracket (DecBr (mkGroup $3)) $1 }
+
+       -- arrow notation extension
+       | srcloc '(|' aexp2 cmdargs '|)'
+                                       { HsArrForm $3 Nothing (reverse $4) $1 }
+
+cmdargs        :: { [RdrNameHsCmdTop] }
+       : cmdargs acmd                  { $2 : $1 }
+       | {- empty -}                   { [] }
+
+acmd   :: { RdrNameHsCmdTop }
+       : aexp2                         { HsCmdTop $1 [] placeHolderType undefined }
 
+cvtopbody :: { [RdrNameHsDecl] }
+       :  '{'            cvtopdecls '}'                { $2 }
+       |      layout_on  cvtopdecls close              { $2 }
 
 texps :: { [RdrNameHsExpr] }
        : texps ',' exp                 { $3 : $1 }
@@ -1042,13 +1075,9 @@ list :: { RdrNameHsExpr }
        | exp ',' exp '..'              { ArithSeqIn (FromThen $1 $3) }
        | exp '..' exp                  { ArithSeqIn (FromTo $1 $3) }
        | exp ',' exp '..' exp          { ArithSeqIn (FromThenTo $1 $3 $5) }
-       | exp srcloc pquals             {% let { body [qs] = qs;
-                                                body  qss = [ParStmt (map reverse qss)] }
-                                          in
-                                          returnP ( mkHsDo ListComp
-                                                           (reverse (ResultStmt $1 $2 : body $3))
-                                                           $2
-                                                 )
+       | exp srcloc pquals             { mkHsDo ListComp
+                                                (reverse (ResultStmt $1 $2 : $3))
+                                                $2
                                        }
 
 lexps :: { [RdrNameHsExpr] }
@@ -1058,13 +1087,22 @@ lexps :: { [RdrNameHsExpr] }
 -----------------------------------------------------------------------------
 -- List Comprehensions
 
-pquals :: { [[RdrNameStmt]] }
-       : pquals '|' quals              { $3 : $1 }
+pquals :: { [RdrNameStmt] }    -- Either a singleton ParStmt, or a reversed list of Stmts
+       : pquals1                       { case $1 of
+                                           [qs] -> qs
+                                           qss  -> [ParStmt stmtss]
+                                                where
+                                                   stmtss = [ (reverse qs, undefined) 
+                                                            | qs <- qss ]
+                                       }
+                       
+pquals1 :: { [[RdrNameStmt]] }
+       : pquals1 '|' quals             { $3 : $1 }
        | '|' quals                     { [$2] }
 
 quals :: { [RdrNameStmt] }
-       : quals ',' stmt                { $3 : $1 }
-       | stmt                          { [$1] }
+       : quals ',' qual                { $3 : $1 }
+       | qual                          { [$1] }
 
 -----------------------------------------------------------------------------
 -- Parallel array expressions
@@ -1081,16 +1119,9 @@ parr :: { RdrNameHsExpr }
                                                       (reverse $1) }
        | exp '..' exp                  { PArrSeqIn (FromTo $1 $3) }
        | exp ',' exp '..' exp          { PArrSeqIn (FromThenTo $1 $3 $5) }
-       | exp srcloc pquals             {% let {
-                                            body [qs] = qs;
-                                            body  qss = [ParStmt 
-                                                          (map reverse qss)]}
-                                          in
-                                          returnP $ 
-                                            mkHsDo PArrComp 
-                                                   (reverse (ResultStmt $1 $2 
-                                                            : body $3))
-                                                   $2
+       | exp srcloc pquals             {  mkHsDo PArrComp 
+                                                 (reverse (ResultStmt $1 $2 : $3))
+                                                 $2
                                        }
 
 -- We are reusing `lexps' and `pquals' from the list case.
@@ -1156,6 +1187,12 @@ maybe_stmt :: { Maybe RdrNameStmt }
        | {- nothing -}                 { Nothing }
 
 stmt  :: { RdrNameStmt }
+       : qual                          { $1 }
+       | srcloc infixexp '->' exp      {% checkPattern $1 $4 `thenP` \p ->
+                                          returnP (BindStmt p $2 $1) }
+       | srcloc 'rec' stmtlist         { RecStmt $3 undefined undefined undefined }
+
+qual  :: { RdrNameStmt }
        : srcloc infixexp '<-' exp      {% checkPattern $1 $2 `thenP` \p ->
                                           returnP (BindStmt p $4 $1) }
        | srcloc exp                    { ExprStmt $2 placeHolderType $1 }
@@ -1206,14 +1243,14 @@ deprec_var : var                        { $1 }
           | tycon                      { $1 }
 
 gcon   :: { RdrName }  -- Data constructor namespace
-       : sysdcon               { $1 }
+       : sysdcon               { nameRdrName (dataConName $1) }
        | qcon                  { $1 }
 -- the case of '[:' ':]' is part of the production `parr'
 
-sysdcon        :: { RdrName }  -- Data constructor namespace
-       : '(' ')'               { getRdrName unitDataCon }
-       | '(' commas ')'        { getRdrName (tupleCon Boxed $2) }
-       | '[' ']'               { nameRdrName nilDataConName }
+sysdcon        :: { DataCon }  -- Wired in data constructors
+       : '(' ')'               { unitDataCon }
+       | '(' commas ')'        { tupleCon Boxed $2 }
+       | '[' ']'               { nilDataCon }
 
 var    :: { RdrName }
        : varid                 { $1 }
@@ -1391,8 +1428,10 @@ qconsym :: { RdrName }   -- Qualified or unqualified
 
 consym :: { RdrName }
        : CONSYM                { mkUnqual dataName $1 }
-       | ':'                   { nameRdrName consDataConName }
+
        -- ':' means only list cons
+       | ':'                   { nameRdrName consDataConName }
+                               -- NB: SrcName because we are reading source
 
 
 -----------------------------------------------------------------------------