remove Haddock-lexing/parsing/renaming from GHC
[ghc-hetmet.git] / compiler / parser / Parser.y.pp
index cbc3bcb..f051726 100644 (file)
@@ -51,8 +51,6 @@ import BasicTypes     ( Boxity(..), Fixity(..), FixityDirection(..), IPName(..),
                          Activation(..), RuleMatchInfo(..), defaultInlineSpec )
 import DynFlags
 import OrdList
-import HaddockParse
-import {-# SOURCE #-} HaddockLex hiding ( Token )
 import HaddockUtils
 
 import FastString
@@ -248,7 +246,6 @@ incorrect.
  'stdcall'      { L _ ITstdcallconv }
  'ccall'        { L _ ITccallconv }
  'prim'         { L _ ITprimcallconv }
- 'dotnet'       { L _ ITdotnet }
  'proc'                { L _ ITproc }          -- for arrow notation extension
  'rec'         { L _ ITrec }           -- for arrow notation extension
  'group'    { L _ ITgroup }     -- for list transform extension
@@ -383,25 +380,25 @@ identifier :: { Located RdrName }
 
 module         :: { Located (HsModule RdrName) }
        : maybedocheader 'module' modid maybemodwarning maybeexports 'where' body
-               {% fileSrcSpan >>= \ loc -> case $1 of { (info, doc) ->
-                  return (L loc (HsModule (Just $3) $5 (fst $7) (snd $7) $4
-                          info doc) )}}
+               {% fileSrcSpan >>= \ loc ->
+                  return (L loc (HsModule (Just $3) $5 (fst $7) (snd $7) $4 $1
+                          ) )}
         | body2
                {% fileSrcSpan >>= \ loc ->
                   return (L loc (HsModule Nothing Nothing
-                          (fst $1) (snd $1) Nothing emptyHaddockModInfo
-                          Nothing)) }
+                          (fst $1) (snd $1) Nothing Nothing
+                          )) }
 
-maybedocheader :: { (HaddockModInfo RdrName, Maybe (HsDoc RdrName)) }
+maybedocheader :: { Maybe LHsDocString }
         : moduleheader            { $1 }
-        | {- empty -}             { (emptyHaddockModInfo, Nothing) }
+        | {- empty -}             { Nothing }
 
 missing_module_keyword :: { () }
        : {- empty -}                           {% pushCurrentContext }
 
 maybemodwarning :: { Maybe WarningTxt }
-    : '{-# DEPRECATED' STRING '#-}' { Just (DeprecatedTxt (getSTRING $2)) }
-    | '{-# WARNING' STRING '#-}'    { Just (WarningTxt (getSTRING $2)) }
+    : '{-# DEPRECATED' strings '#-}' { Just (DeprecatedTxt $ unLoc $2) }
+    | '{-# WARNING' strings '#-}'    { Just (WarningTxt $ unLoc $2) }
     |  {- empty -}                  { Nothing }
 
 body   :: { ([LImportDecl RdrName], [LHsDecl RdrName]) }
@@ -425,13 +422,13 @@ cvtopdecls :: { [LHsDecl RdrName] }
 
 header         :: { Located (HsModule RdrName) }
        : maybedocheader 'module' modid maybemodwarning maybeexports 'where' header_body
-               {% fileSrcSpan >>= \ loc -> case $1 of { (info, doc) ->
-                  return (L loc (HsModule (Just $3) $5 $7 [] $4
-                   info doc))}}
+               {% fileSrcSpan >>= \ loc ->
+                  return (L loc (HsModule (Just $3) $5 $7 [] $4 $1
+                          ))}
        | missing_module_keyword importdecls
                {% fileSrcSpan >>= \ loc ->
                   return (L loc (HsModule Nothing Nothing $2 [] Nothing
-                   emptyHaddockModInfo Nothing)) }
+                          Nothing)) }
 
 header_body :: { [LImportDecl RdrName] }
        :  '{'            importdecls           { $2 }
@@ -708,7 +705,7 @@ tycl_hdr :: { Located (LHsContext RdrName, LHsType RdrName) }
 
 -- Glasgow extension: stand-alone deriving declarations
 stand_alone_deriving :: { LDerivDecl RdrName }
-       : 'deriving' 'instance' inst_type {% checkDerivDecl (LL (DerivDecl $3)) }
+       : 'deriving' 'instance' inst_type { LL (DerivDecl $3) }
 
 -----------------------------------------------------------------------------
 -- Nested declarations
@@ -840,8 +837,8 @@ warnings :: { OrdList (LHsDecl RdrName) }
 
 -- SUP: TEMPORARY HACK, not checking for `module Foo'
 warning :: { OrdList (LHsDecl RdrName) }
-       : namelist STRING
-               { toOL [ LL $ WarningD (Warning n (WarningTxt (getSTRING $2)))
+       : namelist strings
+               { toOL [ LL $ WarningD (Warning n (WarningTxt $ unLoc $2))
                       | n <- unLoc $1 ] }
 
 deprecations :: { OrdList (LHsDecl RdrName) }
@@ -852,10 +849,18 @@ deprecations :: { OrdList (LHsDecl RdrName) }
 
 -- SUP: TEMPORARY HACK, not checking for `module Foo'
 deprecation :: { OrdList (LHsDecl RdrName) }
-       : namelist STRING
-               { toOL [ LL $ WarningD (Warning n (DeprecatedTxt (getSTRING $2)))
+       : namelist strings
+               { toOL [ LL $ WarningD (Warning n (DeprecatedTxt $ unLoc $2))
                       | n <- unLoc $1 ] }
 
+strings :: { Located [FastString] }
+    : STRING { L1 [getSTRING $1] }
+    | '[' stringlist ']' { LL $ fromOL (unLoc $2) }
+
+stringlist :: { Located (OrdList FastString) }
+    : stringlist ',' STRING { LL (unLoc $1 `snocOL` getSTRING $3) }
+    | STRING                { LL (unitOL (getSTRING $1)) }
+
 -----------------------------------------------------------------------------
 -- Annotations
 annotation :: { LHsDecl RdrName }
@@ -876,11 +881,10 @@ fdecl : 'import' callconv safety fspec
       | 'export' callconv fspec
                {% mkExport $2 (unLoc $3) >>= return.LL }
 
-callconv :: { CallConv }
-         : 'stdcall'                   { CCall  StdCallConv }
-         | 'ccall'                     { CCall  CCallConv   }
-         | 'prim'                      { CCall  PrimCallConv}
-         | 'dotnet'                    { DNCall             }
+callconv :: { CCallConv }
+         : 'stdcall'                   { StdCallConv }
+         | 'ccall'                     { CCallConv   }
+         | 'prim'                      { PrimCallConv}
 
 safety :: { Safety }
        : 'unsafe'                      { PlayRisky }
@@ -1186,7 +1190,7 @@ deriving :: { Located (Maybe [LHsType RdrName]) }
 docdecl :: { LHsDecl RdrName }
         : docdecld { L1 (DocD (unLoc $1)) }
 
-docdecld :: { LDocDecl RdrName }
+docdecld :: { LDocDecl }
         : docnext                               { L1 (DocCommentNext (unLoc $1)) }
         | docprev                               { L1 (DocCommentPrev (unLoc $1)) }
         | docnamed                              { L1 (case (unLoc $1) of (n, doc) -> DocCommentNamed n doc) }
@@ -1332,13 +1336,17 @@ aexp2   :: { LHsExpr RdrName }
 --     | STRING                        { sL (getLoc $1) (HsOverLit $! mkHsIsString (getSTRING $1) placeHolderType) }
        | INTEGER                       { sL (getLoc $1) (HsOverLit $! mkHsIntegral (getINTEGER $1) placeHolderType) }
        | RATIONAL                      { sL (getLoc $1) (HsOverLit $! mkHsFractional (getRATIONAL $1) placeHolderType) }
+
         -- N.B.: sections get parsed by these next two productions.
         -- This allows you to write, e.g., '(+ 3, 4 -)', which isn't correct Haskell98
         -- (you'd have to write '((+ 3), (4 -))')
         -- but the less cluttered version fell out of having texps.
        | '(' texp ')'                  { LL (HsPar $2) }
-       | '(' texp ',' texps ')'        { LL $ ExplicitTuple ($2 : reverse $4) Boxed }
-       | '(#' texps '#)'               { LL $ ExplicitTuple (reverse $2)      Unboxed }
+       | '(' tup_exprs ')'             { LL (ExplicitTuple $2 Boxed) }
+
+       | '(#' texp '#)'                { LL (ExplicitTuple [Present $2] Unboxed) }
+       | '(#' tup_exprs '#)'           { LL (ExplicitTuple $2 Unboxed) }
+
        | '[' list ']'                  { LL (unLoc $2) }
        | '[:' parr ':]'                { LL (unLoc $2) }
        | '_'                           { L1 EWildPat }
@@ -1383,6 +1391,9 @@ cvtopdecls0 :: { [LHsDecl RdrName] }
        : {- empty -}           { [] }
        | cvtopdecls            { $1 }
 
+-----------------------------------------------------------------------------
+-- Tuple expressions
+
 -- "texp" is short for tuple expressions: 
 -- things that can appear unparenthesized as long as they're
 -- inside parens or delimitted by commas
@@ -1406,10 +1417,20 @@ texp :: { LHsExpr RdrName }
        -- View patterns get parenthesized above
        | exp '->' exp   { LL $ EViewPat $1 $3 }
 
-texps :: { [LHsExpr RdrName] }
-       : texps ',' texp                { $3 : $1 }
-       | texp                          { [$1] }
+-- Always at least one comma
+tup_exprs :: { [HsTupArg RdrName] }
+           : texp commas_tup_tail  { Present $1 : $2 }
+           | commas tup_tail      { replicate $1 missingTupArg ++ $2 }
+
+-- Always starts with commas; always follows an expr
+commas_tup_tail :: { [HsTupArg RdrName] }
+commas_tup_tail : commas tup_tail  { replicate ($1-1) missingTupArg ++ $2 }
 
+-- Always follows a comma
+tup_tail :: { [HsTupArg RdrName] }
+          : texp commas_tup_tail       { Present $1 : $2 }
+         | texp                        { [Present $1] }
+          | {- empty -}                        { [missingTupArg] }
 
 -----------------------------------------------------------------------------
 -- List expressions
@@ -1473,8 +1494,18 @@ transformquals1 :: { Located [LStmt RdrName] }
 
 transformqual :: { Located ([LStmt RdrName] -> Stmt RdrName) }
     : 'then' exp                { LL $ \leftStmts -> (mkTransformStmt (reverse leftStmts) $2) }
+    -- >>>
     | 'then' exp 'by' exp       { LL $ \leftStmts -> (mkTransformByStmt (reverse leftStmts) $2 $4) }
     | 'then' 'group' 'by' exp              { LL $ \leftStmts -> (mkGroupByStmt (reverse leftStmts) $4) }
+    -- <<<
+    -- These two productions deliberately have a shift-reduce conflict. I have made 'group' into a special_id,
+    -- which means you can enable TransformListComp while still using Data.List.group. However, this makes the two
+    -- productions ambiguous. I've set things up so that Happy chooses to resolve the conflict in that case by
+    -- choosing the "group by" variant, which is what we want.
+    --
+    -- This is rather dubious: the user might be confused as to how to parse this statement. However, it is a good
+    -- practical choice. NB: Data.List.group :: [a] -> [[a]], so using the first production would not even type check
+    -- if /that/ is the group function we conflict with.
     | 'then' 'group' 'using' exp           { LL $ \leftStmts -> (mkGroupUsingStmt (reverse leftStmts) $4) }
     | 'then' 'group' 'by' exp 'using' exp  { LL $ \leftStmts -> (mkGroupByUsingStmt (reverse leftStmts) $4 $6) }
 
@@ -1606,7 +1637,7 @@ fbinds1   :: { ([HsRecField RdrName (LHsExpr RdrName)], Bool) }
   
 fbind  :: { HsRecField RdrName (LHsExpr RdrName) }
        : qvar '=' exp  { HsRecField $1 $3 False }
-       | qvar          { HsRecField $1 (L (getLoc $1) (HsVar (unLoc $1))) True }
+        | qvar          { HsRecField $1 (L (getLoc $1) placeHolderPunRhs) True }
                        -- Here's where we say that plain 'x'
                        -- means exactly 'x = x'.  The pun-flag boolean is
                        -- there so we can still print it right
@@ -1657,9 +1688,9 @@ con_list : con                  { L1 [$1] }
 
 sysdcon        :: { Located DataCon }  -- Wired in data constructors
        : '(' ')'               { LL unitDataCon }
-       | '(' commas ')'        { LL $ tupleCon Boxed $2 }
+       | '(' commas ')'        { LL $ tupleCon Boxed ($2 + 1) }
        | '(#' '#)'             { LL $ unboxedSingletonDataCon }
-       | '(#' commas '#)'      { LL $ tupleCon Unboxed $2 }
+       | '(#' commas '#)'      { LL $ tupleCon Unboxed ($2 + 1) }
        | '[' ']'               { LL nilDataCon }
 
 conop :: { Located RdrName }
@@ -1676,9 +1707,9 @@ qconop :: { Located RdrName }
 gtycon         :: { Located RdrName }  -- A "general" qualified tycon
        : oqtycon                       { $1 }
        | '(' ')'                       { LL $ getRdrName unitTyCon }
-       | '(' commas ')'                { LL $ getRdrName (tupleTyCon Boxed $2) }
+       | '(' commas ')'                { LL $ getRdrName (tupleTyCon Boxed ($2 + 1)) }
        | '(#' '#)'                     { LL $ getRdrName unboxedSingletonTyCon }
-       | '(#' commas '#)'              { LL $ getRdrName (tupleTyCon Unboxed $2) }
+       | '(#' commas '#)'              { LL $ getRdrName (tupleTyCon Unboxed ($2 + 1)) }
        | '(' '->' ')'                  { LL $ getRdrName funTyCon }
        | '[' ']'                       { LL $ listTyCon_RDR }
        | '[:' ':]'                     { LL $ parrTyCon_RDR }
@@ -1826,6 +1857,7 @@ special_id
        | 'stdcall'             { L1 (fsLit "stdcall") }
        | 'ccall'               { L1 (fsLit "ccall") }
        | 'prim'                { L1 (fsLit "prim") }
+       | 'group'               { L1 (fsLit "group") }
 
 special_sym :: { Located FastString }
 special_sym : '!'      { L1 (fsLit "!") }
@@ -1887,51 +1919,36 @@ modid   :: { Located ModuleName }
 
 commas :: { Int }
        : commas ','                    { $1 + 1 }
-       | ','                           { 2 }
+       | ','                           { 1 }
 
 -----------------------------------------------------------------------------
 -- Documentation comments
 
-docnext :: { LHsDoc RdrName }
-  : DOCNEXT {% case parseHaddockParagraphs (tokenise (getDOCNEXT $1)) of {
-      MyLeft  err -> parseError (getLoc $1) err;
-      MyRight doc -> return (L1 doc) } }
+docnext :: { LHsDocString }
+  : DOCNEXT {% return (L1 (HsDocString (mkFastString (getDOCNEXT $1)))) }
 
-docprev :: { LHsDoc RdrName }
-  : DOCPREV {% case parseHaddockParagraphs (tokenise (getDOCPREV $1)) of {
-      MyLeft  err -> parseError (getLoc $1) err;
-      MyRight doc -> return (L1 doc) } }
+docprev :: { LHsDocString }
+  : DOCPREV {% return (L1 (HsDocString (mkFastString (getDOCPREV $1)))) }
 
-docnamed :: { Located (String, (HsDoc RdrName)) }
+docnamed :: { Located (String, HsDocString) }
   : DOCNAMED {%
       let string = getDOCNAMED $1 
           (name, rest) = break isSpace string
-      in case parseHaddockParagraphs (tokenise rest) of {
-        MyLeft  err -> parseError (getLoc $1) err;
-        MyRight doc -> return (L1 (name, doc)) } }
+      in return (L1 (name, HsDocString (mkFastString rest))) }
 
-docsection :: { Located (Int, HsDoc RdrName) }
+docsection :: { Located (Int, HsDocString) }
   : DOCSECTION {% let (n, doc) = getDOCSECTION $1 in
-        case parseHaddockString (tokenise doc) of {
-      MyLeft  err -> parseError (getLoc $1) err;
-      MyRight doc -> return (L1 (n, doc)) } }
+        return (L1 (n, HsDocString (mkFastString doc))) }
 
-moduleheader :: { (HaddockModInfo RdrName, Maybe (HsDoc RdrName)) }                                    
+moduleheader :: { Maybe LHsDocString }
         : DOCNEXT {% let string = getDOCNEXT $1 in
-               case parseModuleHeader string of {                       
-                 Right (str, info) ->                                  
-                   case parseHaddockParagraphs (tokenise str) of {               
-                     MyLeft err -> parseError (getLoc $1) err;                    
-                     MyRight doc -> return (info, Just doc);          
-                   };                                             
-                 Left err -> parseError (getLoc $1) err
-            }  }                                                  
-
-maybe_docprev :: { Maybe (LHsDoc RdrName) }
+                     return (Just (L1 (HsDocString (mkFastString string)))) }
+
+maybe_docprev :: { Maybe LHsDocString }
        : docprev                       { Just $1 }
        | {- empty -}                   { Nothing }
 
-maybe_docnext :: { Maybe (LHsDoc RdrName) }
+maybe_docnext :: { Maybe LHsDocString }
        : docnext                       { Just $1 }
        | {- empty -}                   { Nothing }