Migrate cvs diff from fptools-assoc branch
[ghc-hetmet.git] / compiler / parser / Parser.y.pp
1 --                                                              -*-haskell-*-
2 -- ---------------------------------------------------------------------------
3 -- (c) The University of Glasgow 1997-2003
4 ---
5 -- The GHC grammar.
6 --
7 -- Author(s): Simon Marlow, Sven Panne 1997, 1998, 1999
8 -- ---------------------------------------------------------------------------
9
10 {
11 module Parser ( parseModule, parseStmt, parseIdentifier, parseType,
12                 parseHeader ) where
13
14 #define INCLUDE #include 
15 INCLUDE "HsVersions.h"
16
17 import HsSyn
18 import RdrHsSyn
19 import HscTypes         ( IsBootInterface, DeprecTxt )
20 import Lexer
21 import RdrName
22 import TysWiredIn       ( unitTyCon, unitDataCon, tupleTyCon, tupleCon, nilDataCon,
23                           listTyCon_RDR, parrTyCon_RDR, consDataCon_RDR )
24 import Type             ( funTyCon )
25 import ForeignCall      ( Safety(..), CExportSpec(..), CLabelString,
26                           CCallConv(..), CCallTarget(..), defaultCCallConv
27                         )
28 import OccName          ( varName, dataName, tcClsName, tvName )
29 import DataCon          ( DataCon, dataConName )
30 import SrcLoc           ( Located(..), unLoc, getLoc, noLoc, combineSrcSpans,
31                           SrcSpan, combineLocs, srcLocFile, 
32                           mkSrcLoc, mkSrcSpan )
33 import Module
34 import StaticFlags      ( opt_SccProfilingOn )
35 import Type             ( Kind, mkArrowKind, liftedTypeKind, unliftedTypeKind )
36 import BasicTypes       ( Boxity(..), Fixity(..), FixityDirection(..), IPName(..),
37                           Activation(..), defaultInlineSpec )
38 import OrdList
39
40 import FastString
41 import Maybes           ( orElse )
42 import Outputable
43 import GLAEXTS
44 }
45
46 {-
47 -----------------------------------------------------------------------------
48 26 July 2006
49
50 Conflicts: 37 shift/reduce
51            1 reduce/reduce
52
53 The reduce/reduce conflict is weird.  It's between tyconsym and consym, and I
54 would think the two should never occur in the same context.
55
56   -=chak
57
58 -----------------------------------------------------------------------------
59 Conflicts: 36 shift/reduce (1.25)
60
61 10 for abiguity in 'if x then y else z + 1'             [State 178]
62         (shift parses as 'if x then y else (z + 1)', as per longest-parse rule)
63         10 because op might be: : - ! * . `x` VARSYM CONSYM QVARSYM QCONSYM
64
65 1 for ambiguity in 'if x then y else z :: T'            [State 178]
66         (shift parses as 'if x then y else (z :: T)', as per longest-parse rule)
67
68 4 for ambiguity in 'if x then y else z -< e'            [State 178]
69         (shift parses as 'if x then y else (z -< T)', as per longest-parse rule)
70         There are four such operators: -<, >-, -<<, >>-
71
72
73 2 for ambiguity in 'case v of { x :: T -> T ... } '     [States 11, 253]
74         Which of these two is intended?
75           case v of
76             (x::T) -> T         -- Rhs is T
77     or
78           case v of
79             (x::T -> T) -> ..   -- Rhs is ...
80
81 10 for ambiguity in 'e :: a `b` c'.  Does this mean     [States 11, 253]
82         (e::a) `b` c, or 
83         (e :: (a `b` c))
84     As well as `b` we can have !, VARSYM, QCONSYM, and CONSYM, hence 5 cases
85     Same duplication between states 11 and 253 as the previous case
86
87 1 for ambiguity in 'let ?x ...'                         [State 329]
88         the parser can't tell whether the ?x is the lhs of a normal binding or
89         an implicit binding.  Fortunately resolving as shift gives it the only
90         sensible meaning, namely the lhs of an implicit binding.
91
92 1 for ambiguity in '{-# RULES "name" [ ... #-}          [State 382]
93         we don't know whether the '[' starts the activation or not: it
94         might be the start of the declaration with the activation being
95         empty.  --SDM 1/4/2002
96
97 1 for ambiguity in '{-# RULES "name" forall = ... #-}'  [State 474]
98         since 'forall' is a valid variable name, we don't know whether
99         to treat a forall on the input as the beginning of a quantifier
100         or the beginning of the rule itself.  Resolving to shift means
101         it's always treated as a quantifier, hence the above is disallowed.
102         This saves explicitly defining a grammar for the rule lhs that
103         doesn't include 'forall'.
104
105 -- ---------------------------------------------------------------------------
106 -- Adding location info
107
108 This is done in a stylised way using the three macros below, L0, L1
109 and LL.  Each of these macros can be thought of as having type
110
111    L0, L1, LL :: a -> Located a
112
113 They each add a SrcSpan to their argument.
114
115    L0   adds 'noSrcSpan', used for empty productions
116
117    L1   for a production with a single token on the lhs.  Grabs the SrcSpan
118         from that token.
119
120    LL   for a production with >1 token on the lhs.  Makes up a SrcSpan from
121         the first and last tokens.
122
123 These suffice for the majority of cases.  However, we must be
124 especially careful with empty productions: LL won't work if the first
125 or last token on the lhs can represent an empty span.  In these cases,
126 we have to calculate the span using more of the tokens from the lhs, eg.
127
128         | 'newtype' tycl_hdr '=' newconstr deriving
129                 { L (comb3 $1 $4 $5)
130                     (mkTyData NewType (unLoc $2) [$4] (unLoc $5)) }
131
132 We provide comb3 and comb4 functions which are useful in such cases.
133
134 Be careful: there's no checking that you actually got this right, the
135 only symptom will be that the SrcSpans of your syntax will be
136 incorrect.
137
138 /*
139  * We must expand these macros *before* running Happy, which is why this file is
140  * Parser.y.pp rather than just Parser.y - we run the C pre-processor first.
141  */
142 #define L0   L noSrcSpan
143 #define L1   sL (getLoc $1)
144 #define LL   sL (comb2 $1 $>)
145
146 -- -----------------------------------------------------------------------------
147
148 -}
149
150 %token
151  '_'            { L _ ITunderscore }            -- Haskell keywords
152  'as'           { L _ ITas }
153  'case'         { L _ ITcase }          
154  'class'        { L _ ITclass } 
155  'data'         { L _ ITdata } 
156  'default'      { L _ ITdefault }
157  'deriving'     { L _ ITderiving }
158  'do'           { L _ ITdo }
159  'else'         { L _ ITelse }
160  'hiding'       { L _ IThiding }
161  'if'           { L _ ITif }
162  'import'       { L _ ITimport }
163  'in'           { L _ ITin }
164  'infix'        { L _ ITinfix }
165  'infixl'       { L _ ITinfixl }
166  'infixr'       { L _ ITinfixr }
167  'instance'     { L _ ITinstance }
168  'let'          { L _ ITlet }
169  'module'       { L _ ITmodule }
170  'newtype'      { L _ ITnewtype }
171  'of'           { L _ ITof }
172  'qualified'    { L _ ITqualified }
173  'then'         { L _ ITthen }
174  'type'         { L _ ITtype }
175  'where'        { L _ ITwhere }
176  '_scc_'        { L _ ITscc }         -- ToDo: remove
177
178  'forall'       { L _ ITforall }                        -- GHC extension keywords
179  'foreign'      { L _ ITforeign }
180  'export'       { L _ ITexport }
181  'label'        { L _ ITlabel } 
182  'dynamic'      { L _ ITdynamic }
183  'safe'         { L _ ITsafe }
184  'threadsafe'   { L _ ITthreadsafe }
185  'unsafe'       { L _ ITunsafe }
186  'mdo'          { L _ ITmdo }
187  'stdcall'      { L _ ITstdcallconv }
188  'ccall'        { L _ ITccallconv }
189  'dotnet'       { L _ ITdotnet }
190  'proc'         { L _ ITproc }          -- for arrow notation extension
191  'rec'          { L _ ITrec }           -- for arrow notation extension
192
193  '{-# INLINE'             { L _ (ITinline_prag _) }
194  '{-# SPECIALISE'         { L _ ITspec_prag }
195  '{-# SPECIALISE_INLINE'  { L _ (ITspec_inline_prag _) }
196  '{-# SOURCE'      { L _ ITsource_prag }
197  '{-# RULES'       { L _ ITrules_prag }
198  '{-# CORE'        { L _ ITcore_prag }              -- hdaume: annotated core
199  '{-# SCC'         { L _ ITscc_prag }
200  '{-# DEPRECATED'  { L _ ITdeprecated_prag }
201  '{-# UNPACK'      { L _ ITunpack_prag }
202  '#-}'             { L _ ITclose_prag }
203
204  '..'           { L _ ITdotdot }                        -- reserved symbols
205  ':'            { L _ ITcolon }
206  '::'           { L _ ITdcolon }
207  '='            { L _ ITequal }
208  '\\'           { L _ ITlam }
209  '|'            { L _ ITvbar }
210  '<-'           { L _ ITlarrow }
211  '->'           { L _ ITrarrow }
212  '@'            { L _ ITat }
213  '~'            { L _ ITtilde }
214  '=>'           { L _ ITdarrow }
215  '-'            { L _ ITminus }
216  '!'            { L _ ITbang }
217  '*'            { L _ ITstar }
218  '-<'           { L _ ITlarrowtail }            -- for arrow notation
219  '>-'           { L _ ITrarrowtail }            -- for arrow notation
220  '-<<'          { L _ ITLarrowtail }            -- for arrow notation
221  '>>-'          { L _ ITRarrowtail }            -- for arrow notation
222  '.'            { L _ ITdot }
223
224  '{'            { L _ ITocurly }                        -- special symbols
225  '}'            { L _ ITccurly }
226  '{|'           { L _ ITocurlybar }
227  '|}'           { L _ ITccurlybar }
228  vocurly        { L _ ITvocurly } -- virtual open curly (from layout)
229  vccurly        { L _ ITvccurly } -- virtual close curly (from layout)
230  '['            { L _ ITobrack }
231  ']'            { L _ ITcbrack }
232  '[:'           { L _ ITopabrack }
233  ':]'           { L _ ITcpabrack }
234  '('            { L _ IToparen }
235  ')'            { L _ ITcparen }
236  '(#'           { L _ IToubxparen }
237  '#)'           { L _ ITcubxparen }
238  '(|'           { L _ IToparenbar }
239  '|)'           { L _ ITcparenbar }
240  ';'            { L _ ITsemi }
241  ','            { L _ ITcomma }
242  '`'            { L _ ITbackquote }
243
244  VARID          { L _ (ITvarid    _) }          -- identifiers
245  CONID          { L _ (ITconid    _) }
246  VARSYM         { L _ (ITvarsym   _) }
247  CONSYM         { L _ (ITconsym   _) }
248  QVARID         { L _ (ITqvarid   _) }
249  QCONID         { L _ (ITqconid   _) }
250  QVARSYM        { L _ (ITqvarsym  _) }
251  QCONSYM        { L _ (ITqconsym  _) }
252
253  IPDUPVARID     { L _ (ITdupipvarid   _) }              -- GHC extension
254  IPSPLITVARID   { L _ (ITsplitipvarid _) }              -- GHC extension
255
256  CHAR           { L _ (ITchar     _) }
257  STRING         { L _ (ITstring   _) }
258  INTEGER        { L _ (ITinteger  _) }
259  RATIONAL       { L _ (ITrational _) }
260                     
261  PRIMCHAR       { L _ (ITprimchar   _) }
262  PRIMSTRING     { L _ (ITprimstring _) }
263  PRIMINTEGER    { L _ (ITprimint    _) }
264  PRIMFLOAT      { L _ (ITprimfloat  _) }
265  PRIMDOUBLE     { L _ (ITprimdouble _) }
266                     
267 -- Template Haskell 
268 '[|'            { L _ ITopenExpQuote  }       
269 '[p|'           { L _ ITopenPatQuote  }      
270 '[t|'           { L _ ITopenTypQuote  }      
271 '[d|'           { L _ ITopenDecQuote  }      
272 '|]'            { L _ ITcloseQuote    }
273 TH_ID_SPLICE    { L _ (ITidEscape _)  }     -- $x
274 '$('            { L _ ITparenEscape   }     -- $( exp )
275 TH_VAR_QUOTE    { L _ ITvarQuote      }     -- 'x
276 TH_TY_QUOTE     { L _ ITtyQuote       }      -- ''T
277
278 %monad { P } { >>= } { return }
279 %lexer { lexer } { L _ ITeof }
280 %name parseModule module
281 %name parseStmt   maybe_stmt
282 %name parseIdentifier  identifier
283 %name parseType ctype
284 %partial parseHeader header
285 %tokentype { (Located Token) }
286 %%
287
288 -----------------------------------------------------------------------------
289 -- Identifiers; one of the entry points
290 identifier :: { Located RdrName }
291         : qvar                          { $1 }
292         | qcon                          { $1 }
293         | qvarop                        { $1 }
294         | qconop                        { $1 }
295
296 -----------------------------------------------------------------------------
297 -- Module Header
298
299 -- The place for module deprecation is really too restrictive, but if it
300 -- was allowed at its natural place just before 'module', we get an ugly
301 -- s/r conflict with the second alternative. Another solution would be the
302 -- introduction of a new pragma DEPRECATED_MODULE, but this is not very nice,
303 -- either, and DEPRECATED is only expected to be used by people who really
304 -- know what they are doing. :-)
305
306 module  :: { Located (HsModule RdrName) }
307         : 'module' modid maybemoddeprec maybeexports 'where' body 
308                 {% fileSrcSpan >>= \ loc ->
309                    return (L loc (HsModule (Just $2) $4 (fst $6) (snd $6) $3)) }
310         | missing_module_keyword top close
311                 {% fileSrcSpan >>= \ loc ->
312                    return (L loc (HsModule Nothing Nothing 
313                                 (fst $2) (snd $2) Nothing)) }
314
315 missing_module_keyword :: { () }
316         : {- empty -}                           {% pushCurrentContext }
317
318 maybemoddeprec :: { Maybe DeprecTxt }
319         : '{-# DEPRECATED' STRING '#-}'         { Just (getSTRING $2) }
320         |  {- empty -}                          { Nothing }
321
322 body    :: { ([LImportDecl RdrName], [LHsDecl RdrName]) }
323         :  '{'            top '}'               { $2 }
324         |      vocurly    top close             { $2 }
325
326 top     :: { ([LImportDecl RdrName], [LHsDecl RdrName]) }
327         : importdecls                           { (reverse $1,[]) }
328         | importdecls ';' cvtopdecls            { (reverse $1,$3) }
329         | cvtopdecls                            { ([],$1) }
330
331 cvtopdecls :: { [LHsDecl RdrName] }
332         : topdecls                              { cvTopDecls $1 }
333
334 -----------------------------------------------------------------------------
335 -- Module declaration & imports only
336
337 header  :: { Located (HsModule RdrName) }
338         : 'module' modid maybemoddeprec maybeexports 'where' header_body
339                 {% fileSrcSpan >>= \ loc ->
340                    return (L loc (HsModule (Just $2) $4 $6 [] $3)) }
341         | missing_module_keyword importdecls
342                 {% fileSrcSpan >>= \ loc ->
343                    return (L loc (HsModule Nothing Nothing $2 [] Nothing)) }
344
345 header_body :: { [LImportDecl RdrName] }
346         :  '{'            importdecls           { $2 }
347         |      vocurly    importdecls           { $2 }
348
349 -----------------------------------------------------------------------------
350 -- The Export List
351
352 maybeexports :: { Maybe [LIE RdrName] }
353         :  '(' exportlist ')'                   { Just $2 }
354         |  {- empty -}                          { Nothing }
355
356 exportlist  :: { [LIE RdrName] }
357         : ','                                   { [] }
358         | exportlist1                           { $1 }
359
360 exportlist1 :: { [LIE RdrName] }
361         :  export                               { [$1] }
362         |  export ',' exportlist                { $1 : $3 }
363         |  {- empty -}                          { [] }
364
365    -- No longer allow things like [] and (,,,) to be exported
366    -- They are built in syntax, always available
367 export  :: { LIE RdrName }
368         :  qvar                         { L1 (IEVar (unLoc $1)) }
369         |  oqtycon                      { L1 (IEThingAbs (unLoc $1)) }
370         |  oqtycon '(' '..' ')'         { LL (IEThingAll (unLoc $1)) }
371         |  oqtycon '(' ')'              { LL (IEThingWith (unLoc $1) []) }
372         |  oqtycon '(' qcnames ')'      { LL (IEThingWith (unLoc $1) (reverse $3)) }
373         |  'module' modid               { LL (IEModuleContents (unLoc $2)) }
374
375 qcnames :: { [RdrName] }
376         :  qcnames ',' qcname                   { unLoc $3 : $1 }
377         |  qcname                               { [unLoc $1]  }
378
379 qcname  :: { Located RdrName }  -- Variable or data constructor
380         :  qvar                                 { $1 }
381         |  qcon                                 { $1 }
382
383 -----------------------------------------------------------------------------
384 -- Import Declarations
385
386 -- import decls can be *empty*, or even just a string of semicolons
387 -- whereas topdecls must contain at least one topdecl.
388
389 importdecls :: { [LImportDecl RdrName] }
390         : importdecls ';' importdecl            { $3 : $1 }
391         | importdecls ';'                       { $1 }
392         | importdecl                            { [ $1 ] }
393         | {- empty -}                           { [] }
394
395 importdecl :: { LImportDecl RdrName }
396         : 'import' maybe_src optqualified modid maybeas maybeimpspec 
397                 { L (comb4 $1 $4 $5 $6) (ImportDecl $4 $2 $3 (unLoc $5) (unLoc $6)) }
398
399 maybe_src :: { IsBootInterface }
400         : '{-# SOURCE' '#-}'                    { True }
401         | {- empty -}                           { False }
402
403 optqualified :: { Bool }
404         : 'qualified'                           { True  }
405         | {- empty -}                           { False }
406
407 maybeas :: { Located (Maybe ModuleName) }
408         : 'as' modid                            { LL (Just (unLoc $2)) }
409         | {- empty -}                           { noLoc Nothing }
410
411 maybeimpspec :: { Located (Maybe (Bool, [LIE RdrName])) }
412         : impspec                               { L1 (Just (unLoc $1)) }
413         | {- empty -}                           { noLoc Nothing }
414
415 impspec :: { Located (Bool, [LIE RdrName]) }
416         :  '(' exportlist ')'                   { LL (False, $2) }
417         |  'hiding' '(' exportlist ')'          { LL (True,  $3) }
418
419 -----------------------------------------------------------------------------
420 -- Fixity Declarations
421
422 prec    :: { Int }
423         : {- empty -}           { 9 }
424         | INTEGER               {% checkPrecP (L1 (fromInteger (getINTEGER $1))) }
425
426 infix   :: { Located FixityDirection }
427         : 'infix'                               { L1 InfixN  }
428         | 'infixl'                              { L1 InfixL  }
429         | 'infixr'                              { L1 InfixR }
430
431 ops     :: { Located [Located RdrName] }
432         : ops ',' op                            { LL ($3 : unLoc $1) }
433         | op                                    { L1 [$1] }
434
435 -----------------------------------------------------------------------------
436 -- Top-Level Declarations
437
438 topdecls :: { OrdList (LHsDecl RdrName) }
439         : topdecls ';' topdecl          { $1 `appOL` $3 }
440         | topdecls ';'                  { $1 }
441         | topdecl                       { $1 }
442
443 topdecl :: { OrdList (LHsDecl RdrName) }
444         : cl_decl                       { unitOL (L1 (TyClD (unLoc $1))) }
445         | ty_decl                       {% checkTopTyClD $1 >>= return.unitOL.L1 }
446         | 'instance' inst_type where
447                 { let (binds, sigs, ats) = cvBindsAndSigs (unLoc $3)
448                   in unitOL (L (comb3 $1 $2 $3) 
449                             (InstD (InstDecl $2 binds sigs ats))) }
450         | 'default' '(' comma_types0 ')'        { unitOL (LL $ DefD (DefaultDecl $3)) }
451         | 'foreign' fdecl                       { unitOL (LL (unLoc $2)) }
452         | '{-# DEPRECATED' deprecations '#-}'   { $2 }
453         | '{-# RULES' rules '#-}'               { $2 }
454         | decl                                  { unLoc $1 }
455
456         -- Template Haskell Extension
457         | '$(' exp ')'                          { unitOL (LL $ SpliceD (SpliceDecl $2)) }
458         | TH_ID_SPLICE                          { unitOL (LL $ SpliceD (SpliceDecl $
459                                                         L1 $ HsVar (mkUnqual varName (getTH_ID_SPLICE $1))
460                                                   )) }
461
462 -- Type classes
463 --
464 cl_decl :: { LTyClDecl RdrName }
465         : 'class' tycl_hdr fds where
466                 {% do { let { (binds, sigs, ats)           = 
467                                 cvBindsAndSigs (unLoc $4)
468                             ; (ctxt, tc, tvs, Just tparms) = unLoc $2}
469                       ; checkTyVars tparms
470                       ; return $ L (comb4 $1 $2 $3 $4) 
471                                    (mkClassDecl (ctxt, tc, tvs) 
472                                                 (unLoc $3) sigs binds ats) } }
473
474 -- Type declarations
475 --
476 ty_decl :: { LTyClDecl RdrName }
477         : 'type' type '=' ctype 
478                 -- Note type on the left of the '='; this allows
479                 -- infix type constructors to be declared
480                 -- 
481                 -- Note ctype, not sigtype, on the right
482                 -- We allow an explicit for-all but we don't insert one
483                 -- in   type Foo a = (b,b)
484                 -- Instead we just say b is out of scope
485                 {% do { (tc,tvs) <- checkSynHdr $2
486                       ; return (LL (TySynonym tc tvs $4)) } }
487
488         | data_or_newtype tycl_hdr constrs deriving
489                 { L (comb4 $1 $2 $3 $4) -- We need the location on tycl_hdr 
490                                         -- in case constrs and deriving are both empty
491                     (mkTyData (unLoc $1) (unLoc $2) Nothing (reverse (unLoc $3)) (unLoc $4)) }
492
493         | data_or_newtype tycl_hdr opt_kind_sig 
494                  'where' gadt_constrlist
495                  deriving
496                 { L (comb4 $1 $2 $4 $5)
497                     (mkTyData (unLoc $1) (unLoc $2) $3 (reverse (unLoc $5)) (unLoc $6)) }
498
499 data_or_newtype :: { Located NewOrData }
500         : 'data'        { L1 DataType }
501         | 'newtype'     { L1 NewType }
502
503 opt_kind_sig :: { Maybe Kind }
504         :                               { Nothing }
505         | '::' kind                     { Just $2 }
506
507 -- tycl_hdr parses the header of a type decl,
508 -- which takes the form
509 --      T a b
510 --      Eq a => T a
511 --      (Eq a, Ord b) => T a b
512 --      T Int [a]                       -- for associated types
513 -- Rather a lot of inlining here, else we get reduce/reduce errors
514 tycl_hdr :: { Located (LHsContext RdrName, 
515                        Located RdrName, 
516                        [LHsTyVarBndr RdrName],
517                        Maybe [LHsType RdrName]) }
518         : context '=>' type             {% checkTyClHdr $1         $3 >>= return.LL }
519         | type                          {% checkTyClHdr (noLoc []) $1 >>= return.L1 }
520
521 -----------------------------------------------------------------------------
522 -- Nested declarations
523
524 -- Type declaration or value declaration
525 --
526 tydecl  :: { Located (OrdList (LHsDecl RdrName)) }
527 tydecl  : ty_decl                       { LL (unitOL (L1 (TyClD (unLoc $1)))) }
528         | decl                          { $1 }
529
530 tydecls :: { Located (OrdList (LHsDecl RdrName)) }      -- Reversed
531         : tydecls ';' tydecl            { LL (unLoc $1 `appOL` unLoc $3) }
532         | tydecls ';'                   { LL (unLoc $1) }
533         | tydecl                        { $1 }
534         | {- empty -}                   { noLoc nilOL }
535
536
537 tydecllist 
538         :: { Located (OrdList (LHsDecl RdrName)) }      -- Reversed
539         : '{'            tydecls '}'    { LL (unLoc $2) }
540         |     vocurly    tydecls close  { $2 }
541
542 -- Form of the body of class and instance declarations
543 --
544 where   :: { Located (OrdList (LHsDecl RdrName)) }      -- Reversed
545                                 -- No implicit parameters
546                                 -- May have type declarations
547         : 'where' tydecllist            { LL (unLoc $2) }
548         | {- empty -}                   { noLoc nilOL }
549
550 decls   :: { Located (OrdList (LHsDecl RdrName)) }      
551         : decls ';' decl                { LL (unLoc $1 `appOL` unLoc $3) }
552         | decls ';'                     { LL (unLoc $1) }
553         | decl                          { $1 }
554         | {- empty -}                   { noLoc nilOL }
555
556
557 decllist :: { Located (OrdList (LHsDecl RdrName)) }
558         : '{'            decls '}'      { LL (unLoc $2) }
559         |     vocurly    decls close    { $2 }
560
561 -- Binding groups other than those of class and instance declarations
562 --
563 binds   ::  { Located (HsLocalBinds RdrName) }          -- May have implicit parameters
564                                                 -- No type declarations
565         : decllist                      { L1 (HsValBinds (cvBindGroup (unLoc $1))) }
566         | '{'            dbinds '}'     { LL (HsIPBinds (IPBinds (unLoc $2) emptyLHsBinds)) }
567         |     vocurly    dbinds close   { L (getLoc $2) (HsIPBinds (IPBinds (unLoc $2) emptyLHsBinds)) }
568
569 wherebinds :: { Located (HsLocalBinds RdrName) }        -- May have implicit parameters
570                                                 -- No type declarations
571         : 'where' binds                 { LL (unLoc $2) }
572         | {- empty -}                   { noLoc emptyLocalBinds }
573
574
575 -----------------------------------------------------------------------------
576 -- Transformation Rules
577
578 rules   :: { OrdList (LHsDecl RdrName) }
579         :  rules ';' rule                       { $1 `snocOL` $3 }
580         |  rules ';'                            { $1 }
581         |  rule                                 { unitOL $1 }
582         |  {- empty -}                          { nilOL }
583
584 rule    :: { LHsDecl RdrName }
585         : STRING activation rule_forall infixexp '=' exp
586              { LL $ RuleD (HsRule (getSTRING $1) 
587                                   ($2 `orElse` AlwaysActive) 
588                                   $3 $4 placeHolderNames $6 placeHolderNames) }
589
590 activation :: { Maybe Activation } 
591         : {- empty -}                           { Nothing }
592         | explicit_activation                   { Just $1 }
593
594 explicit_activation :: { Activation }  -- In brackets
595         : '[' INTEGER ']'               { ActiveAfter  (fromInteger (getINTEGER $2)) }
596         | '[' '~' INTEGER ']'           { ActiveBefore (fromInteger (getINTEGER $3)) }
597
598 rule_forall :: { [RuleBndr RdrName] }
599         : 'forall' rule_var_list '.'            { $2 }
600         | {- empty -}                           { [] }
601
602 rule_var_list :: { [RuleBndr RdrName] }
603         : rule_var                              { [$1] }
604         | rule_var rule_var_list                { $1 : $2 }
605
606 rule_var :: { RuleBndr RdrName }
607         : varid                                 { RuleBndr $1 }
608         | '(' varid '::' ctype ')'              { RuleBndrSig $2 $4 }
609
610 -----------------------------------------------------------------------------
611 -- Deprecations (c.f. rules)
612
613 deprecations :: { OrdList (LHsDecl RdrName) }
614         : deprecations ';' deprecation          { $1 `appOL` $3 }
615         | deprecations ';'                      { $1 }
616         | deprecation                           { $1 }
617         | {- empty -}                           { nilOL }
618
619 -- SUP: TEMPORARY HACK, not checking for `module Foo'
620 deprecation :: { OrdList (LHsDecl RdrName) }
621         : depreclist STRING
622                 { toOL [ LL $ DeprecD (Deprecation n (getSTRING $2)) 
623                        | n <- unLoc $1 ] }
624
625
626 -----------------------------------------------------------------------------
627 -- Foreign import and export declarations
628
629 fdecl :: { LHsDecl RdrName }
630 fdecl : 'import' callconv safety fspec
631                 {% mkImport $2 $3 (unLoc $4) >>= return.LL }
632       | 'import' callconv        fspec          
633                 {% do { d <- mkImport $2 (PlaySafe False) (unLoc $3);
634                         return (LL d) } }
635       | 'export' callconv fspec
636                 {% mkExport $2 (unLoc $3) >>= return.LL }
637
638 callconv :: { CallConv }
639           : 'stdcall'                   { CCall  StdCallConv }
640           | 'ccall'                     { CCall  CCallConv   }
641           | 'dotnet'                    { DNCall             }
642
643 safety :: { Safety }
644         : 'unsafe'                      { PlayRisky }
645         | 'safe'                        { PlaySafe  False }
646         | 'threadsafe'                  { PlaySafe  True }
647
648 fspec :: { Located (Located FastString, Located RdrName, LHsType RdrName) }
649        : STRING var '::' sigtype      { LL (L (getLoc $1) (getSTRING $1), $2, $4) }
650        |        var '::' sigtype      { LL (noLoc nilFS, $1, $3) }
651          -- if the entity string is missing, it defaults to the empty string;
652          -- the meaning of an empty entity string depends on the calling
653          -- convention
654
655 -----------------------------------------------------------------------------
656 -- Type signatures
657
658 opt_sig :: { Maybe (LHsType RdrName) }
659         : {- empty -}                   { Nothing }
660         | '::' sigtype                  { Just $2 }
661
662 opt_asig :: { Maybe (LHsType RdrName) }
663         : {- empty -}                   { Nothing }
664         | '::' atype                    { Just $2 }
665
666 sigtypes1 :: { [LHsType RdrName] }
667         : sigtype                       { [ $1 ] }
668         | sigtype ',' sigtypes1         { $1 : $3 }
669
670 sigtype :: { LHsType RdrName }
671         : ctype                         { L1 (mkImplicitHsForAllTy (noLoc []) $1) }
672         -- Wrap an Implicit forall if there isn't one there already
673
674 sig_vars :: { Located [Located RdrName] }
675          : sig_vars ',' var             { LL ($3 : unLoc $1) }
676          | var                          { L1 [$1] }
677
678 -----------------------------------------------------------------------------
679 -- Types
680
681 strict_mark :: { Located HsBang }
682         : '!'                           { L1 HsStrict }
683         | '{-# UNPACK' '#-}' '!'        { LL HsUnbox }
684
685 -- A ctype is a for-all type
686 ctype   :: { LHsType RdrName }
687         : 'forall' tv_bndrs '.' ctype   { LL $ mkExplicitHsForAllTy $2 (noLoc []) $4 }
688         | context '=>' type             { LL $ mkImplicitHsForAllTy   $1 $3 }
689         -- A type of form (context => type) is an *implicit* HsForAllTy
690         | type                          { $1 }
691
692 -- We parse a context as a btype so that we don't get reduce/reduce
693 -- errors in ctype.  The basic problem is that
694 --      (Eq a, Ord a)
695 -- looks so much like a tuple type.  We can't tell until we find the =>
696 context :: { LHsContext RdrName }
697         : btype                         {% checkContext $1 }
698
699 type :: { LHsType RdrName }
700         : ipvar '::' gentype            { LL (HsPredTy (HsIParam (unLoc $1) $3)) }
701         | gentype                       { $1 }
702
703 gentype :: { LHsType RdrName }
704         : btype                         { $1 }
705         | btype qtyconop gentype        { LL $ HsOpTy $1 $2 $3 }
706         | btype tyvarop  gentype        { LL $ HsOpTy $1 $2 $3 }
707         | btype '->' ctype              { LL $ HsFunTy $1 $3 }
708
709 btype :: { LHsType RdrName }
710         : btype atype                   { LL $ HsAppTy $1 $2 }
711         | atype                         { $1 }
712
713 atype :: { LHsType RdrName }
714         : gtycon                        { L1 (HsTyVar (unLoc $1)) }
715         | tyvar                         { L1 (HsTyVar (unLoc $1)) }
716         | strict_mark atype             { LL (HsBangTy (unLoc $1) $2) }
717         | '(' ctype ',' comma_types1 ')'  { LL $ HsTupleTy Boxed  ($2:$4) }
718         | '(#' comma_types1 '#)'        { LL $ HsTupleTy Unboxed $2     }
719         | '[' ctype ']'                 { LL $ HsListTy  $2 }
720         | '[:' ctype ':]'               { LL $ HsPArrTy  $2 }
721         | '(' ctype ')'                 { LL $ HsParTy   $2 }
722         | '(' ctype '::' kind ')'       { LL $ HsKindSig $2 $4 }
723 -- Generics
724         | INTEGER                       { L1 (HsNumTy (getINTEGER $1)) }
725
726 -- An inst_type is what occurs in the head of an instance decl
727 --      e.g.  (Foo a, Gaz b) => Wibble a b
728 -- It's kept as a single type, with a MonoDictTy at the right
729 -- hand corner, for convenience.
730 inst_type :: { LHsType RdrName }
731         : sigtype                       {% checkInstType $1 }
732
733 inst_types1 :: { [LHsType RdrName] }
734         : inst_type                     { [$1] }
735         | inst_type ',' inst_types1     { $1 : $3 }
736
737 comma_types0  :: { [LHsType RdrName] }
738         : comma_types1                  { $1 }
739         | {- empty -}                   { [] }
740
741 comma_types1    :: { [LHsType RdrName] }
742         : ctype                         { [$1] }
743         | ctype  ',' comma_types1       { $1 : $3 }
744
745 tv_bndrs :: { [LHsTyVarBndr RdrName] }
746          : tv_bndr tv_bndrs             { $1 : $2 }
747          | {- empty -}                  { [] }
748
749 tv_bndr :: { LHsTyVarBndr RdrName }
750         : tyvar                         { L1 (UserTyVar (unLoc $1)) }
751         | '(' tyvar '::' kind ')'       { LL (KindedTyVar (unLoc $2) $4) }
752
753 fds :: { Located [Located ([RdrName], [RdrName])] }
754         : {- empty -}                   { noLoc [] }
755         | '|' fds1                      { LL (reverse (unLoc $2)) }
756
757 fds1 :: { Located [Located ([RdrName], [RdrName])] }
758         : fds1 ',' fd                   { LL ($3 : unLoc $1) }
759         | fd                            { L1 [$1] }
760
761 fd :: { Located ([RdrName], [RdrName]) }
762         : varids0 '->' varids0          { L (comb3 $1 $2 $3)
763                                            (reverse (unLoc $1), reverse (unLoc $3)) }
764
765 varids0 :: { Located [RdrName] }
766         : {- empty -}                   { noLoc [] }
767         | varids0 tyvar                 { LL (unLoc $2 : unLoc $1) }
768
769 -----------------------------------------------------------------------------
770 -- Kinds
771
772 kind    :: { Kind }
773         : akind                 { $1 }
774         | akind '->' kind       { mkArrowKind $1 $3 }
775
776 akind   :: { Kind }
777         : '*'                   { liftedTypeKind }
778         | '!'                   { unliftedTypeKind }
779         | '(' kind ')'          { $2 }
780
781
782 -----------------------------------------------------------------------------
783 -- Datatype declarations
784
785 gadt_constrlist :: { Located [LConDecl RdrName] }
786         : '{'            gadt_constrs '}'       { LL (unLoc $2) }
787         |     vocurly    gadt_constrs close     { $2 }
788
789 gadt_constrs :: { Located [LConDecl RdrName] }
790         : gadt_constrs ';' gadt_constr  { LL ($3 : unLoc $1) }
791         | gadt_constrs ';'              { $1 }
792         | gadt_constr                   { L1 [$1] } 
793
794 -- We allow the following forms:
795 --      C :: Eq a => a -> T a
796 --      C :: forall a. Eq a => !a -> T a
797 --      D { x,y :: a } :: T a
798 --      forall a. Eq a => D { x,y :: a } :: T a
799
800 gadt_constr :: { LConDecl RdrName }
801         : con '::' sigtype
802               { LL (mkGadtDecl $1 $3) } 
803         -- Syntax: Maybe merge the record stuff with the single-case above?
804         --         (to kill the mostly harmless reduce/reduce error)
805         -- XXX revisit audreyt
806         | constr_stuff_record '::' sigtype
807                 { let (con,details) = unLoc $1 in 
808                   LL (ConDecl con Implicit [] (noLoc []) details (ResTyGADT $3)) }
809 {-
810         | forall context '=>' constr_stuff_record '::' sigtype
811                 { let (con,details) = unLoc $4 in 
812                   LL (ConDecl con Implicit (unLoc $1) $2 details (ResTyGADT $6)) }
813         | forall constr_stuff_record '::' sigtype
814                 { let (con,details) = unLoc $2 in 
815                   LL (ConDecl con Implicit (unLoc $1) (noLoc []) details (ResTyGADT $4)) }
816 -}
817
818
819 constrs :: { Located [LConDecl RdrName] }
820         : {- empty; a GHC extension -}  { noLoc [] }
821         | '=' constrs1                  { LL (unLoc $2) }
822
823 constrs1 :: { Located [LConDecl RdrName] }
824         : constrs1 '|' constr           { LL ($3 : unLoc $1) }
825         | constr                        { L1 [$1] }
826
827 constr :: { LConDecl RdrName }
828         : forall context '=>' constr_stuff      
829                 { let (con,details) = unLoc $4 in 
830                   LL (ConDecl con Explicit (unLoc $1) $2 details ResTyH98) }
831         | forall constr_stuff
832                 { let (con,details) = unLoc $2 in 
833                   LL (ConDecl con Explicit (unLoc $1) (noLoc []) details ResTyH98) }
834
835 forall :: { Located [LHsTyVarBndr RdrName] }
836         : 'forall' tv_bndrs '.'         { LL $2 }
837         | {- empty -}                   { noLoc [] }
838
839 constr_stuff :: { Located (Located RdrName, HsConDetails RdrName (LBangType RdrName)) }
840 -- We parse the constructor declaration 
841 --      C t1 t2
842 -- as a btype (treating C as a type constructor) and then convert C to be
843 -- a data constructor.  Reason: it might continue like this:
844 --      C t1 t2 %: D Int
845 -- in which case C really would be a type constructor.  We can't resolve this
846 -- ambiguity till we come across the constructor oprerator :% (or not, more usually)
847         : btype                         {% mkPrefixCon $1 [] >>= return.LL }
848         | oqtycon '{' '}'               {% mkRecCon $1 [] >>= return.LL }
849         | oqtycon '{' fielddecls '}'    {% mkRecCon $1 $3 >>= return.LL }
850         | btype conop btype             { LL ($2, InfixCon $1 $3) }
851
852 constr_stuff_record :: { Located (Located RdrName, HsConDetails RdrName (LBangType RdrName)) }
853         : oqtycon '{' '}'               {% mkRecCon $1 [] >>= return.sL (comb2 $1 $>) }
854         | oqtycon '{' fielddecls '}'    {% mkRecCon $1 $3 >>= return.sL (comb2 $1 $>) }
855
856 fielddecls :: { [([Located RdrName], LBangType RdrName)] }
857         : fielddecl ',' fielddecls      { unLoc $1 : $3 }
858         | fielddecl                     { [unLoc $1] }
859
860 fielddecl :: { Located ([Located RdrName], LBangType RdrName) }
861         : sig_vars '::' ctype           { LL (reverse (unLoc $1), $3) }
862
863 -- We allow the odd-looking 'inst_type' in a deriving clause, so that
864 -- we can do deriving( forall a. C [a] ) in a newtype (GHC extension).
865 -- The 'C [a]' part is converted to an HsPredTy by checkInstType
866 -- We don't allow a context, but that's sorted out by the type checker.
867 deriving :: { Located (Maybe [LHsType RdrName]) }
868         : {- empty -}                           { noLoc Nothing }
869         | 'deriving' qtycon     {% do { let { L loc tv = $2 }
870                                       ; p <- checkInstType (L loc (HsTyVar tv))
871                                       ; return (LL (Just [p])) } }
872         | 'deriving' '(' ')'                    { LL (Just []) }
873         | 'deriving' '(' inst_types1 ')'        { LL (Just $3) }
874              -- Glasgow extension: allow partial 
875              -- applications in derivings
876
877 -----------------------------------------------------------------------------
878 -- Value definitions
879
880 {- There's an awkward overlap with a type signature.  Consider
881         f :: Int -> Int = ...rhs...
882    Then we can't tell whether it's a type signature or a value
883    definition with a result signature until we see the '='.
884    So we have to inline enough to postpone reductions until we know.
885 -}
886
887 {-
888   ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
889   instead of qvar, we get another shift/reduce-conflict. Consider the
890   following programs:
891   
892      { (^^) :: Int->Int ; }          Type signature; only var allowed
893
894      { (^^) :: Int->Int = ... ; }    Value defn with result signature;
895                                      qvar allowed (because of instance decls)
896   
897   We can't tell whether to reduce var to qvar until after we've read the signatures.
898 -}
899
900 decl    :: { Located (OrdList (LHsDecl RdrName)) }
901         : sigdecl                       { $1 }
902         | '!' infixexp rhs              {% do { pat <- checkPattern $2;
903                                                 return (LL $ unitOL $ LL $ ValD $ 
904                                                         PatBind (LL $ BangPat pat) (unLoc $3)
905                                                                 placeHolderType placeHolderNames) } }
906         | infixexp opt_sig rhs          {% do { r <- checkValDef $1 $2 $3;
907                                                 return (LL $ unitOL (LL $ ValD r)) } }
908
909 rhs     :: { Located (GRHSs RdrName) }
910         : '=' exp wherebinds    { L (comb3 $1 $2 $3) $ GRHSs (unguardedRHS $2) (unLoc $3) }
911         | gdrhs wherebinds      { LL $ GRHSs (reverse (unLoc $1)) (unLoc $2) }
912
913 gdrhs :: { Located [LGRHS RdrName] }
914         : gdrhs gdrh            { LL ($2 : unLoc $1) }
915         | gdrh                  { L1 [$1] }
916
917 gdrh :: { LGRHS RdrName }
918         : '|' quals '=' exp     { sL (comb2 $1 $>) $ GRHS (reverse (unLoc $2)) $4 }
919
920 sigdecl :: { Located (OrdList (LHsDecl RdrName)) }
921         : infixexp '::' sigtype
922                                 {% do s <- checkValSig $1 $3; 
923                                       return (LL $ unitOL (LL $ SigD s)) }
924                 -- See the above notes for why we need infixexp here
925         | var ',' sig_vars '::' sigtype 
926                                 { LL $ toOL [ LL $ SigD (TypeSig n $5) | n <- $1 : unLoc $3 ] }
927         | infix prec ops        { LL $ toOL [ LL $ SigD (FixSig (FixitySig n (Fixity $2 (unLoc $1))))
928                                              | n <- unLoc $3 ] }
929         | '{-# INLINE'   activation qvar '#-}'        
930                                 { LL $ unitOL (LL $ SigD (InlineSig $3 (mkInlineSpec $2 (getINLINE $1)))) }
931         | '{-# SPECIALISE' qvar '::' sigtypes1 '#-}'
932                                 { LL $ toOL [ LL $ SigD (SpecSig $2 t defaultInlineSpec)
933                                             | t <- $4] }
934         | '{-# SPECIALISE_INLINE' activation qvar '::' sigtypes1 '#-}'
935                                 { LL $ toOL [ LL $ SigD (SpecSig $3 t (mkInlineSpec $2 (getSPEC_INLINE $1)))
936                                             | t <- $5] }
937         | '{-# SPECIALISE' 'instance' inst_type '#-}'
938                                 { LL $ unitOL (LL $ SigD (SpecInstSig $3)) }
939
940 -----------------------------------------------------------------------------
941 -- Expressions
942
943 exp   :: { LHsExpr RdrName }
944         : infixexp '::' sigtype         { LL $ ExprWithTySig $1 $3 }
945         | infixexp '-<' exp             { LL $ HsArrApp $1 $3 placeHolderType HsFirstOrderApp True }
946         | infixexp '>-' exp             { LL $ HsArrApp $3 $1 placeHolderType HsFirstOrderApp False }
947         | infixexp '-<<' exp            { LL $ HsArrApp $1 $3 placeHolderType HsHigherOrderApp True }
948         | infixexp '>>-' exp            { LL $ HsArrApp $3 $1 placeHolderType HsHigherOrderApp False}
949         | infixexp                      { $1 }
950
951 infixexp :: { LHsExpr RdrName }
952         : exp10                         { $1 }
953         | infixexp qop exp10            { LL (OpApp $1 $2 (panic "fixity") $3) }
954
955 exp10 :: { LHsExpr RdrName }
956         : '\\' aexp aexps opt_asig '->' exp     
957                         {% checkPatterns ($2 : reverse $3) >>= \ ps -> 
958                            return (LL $ HsLam (mkMatchGroup [LL $ Match ps $4
959                                             (GRHSs (unguardedRHS $6) emptyLocalBinds
960                                                         )])) }
961         | 'let' binds 'in' exp                  { LL $ HsLet (unLoc $2) $4 }
962         | 'if' exp 'then' exp 'else' exp        { LL $ HsIf $2 $4 $6 }
963         | 'case' exp 'of' altslist              { LL $ HsCase $2 (mkMatchGroup (unLoc $4)) }
964         | '-' fexp                              { LL $ mkHsNegApp $2 }
965
966         | 'do' stmtlist                 {% let loc = comb2 $1 $2 in
967                                            checkDo loc (unLoc $2)  >>= \ (stmts,body) ->
968                                            return (L loc (mkHsDo DoExpr stmts body)) }
969         | 'mdo' stmtlist                {% let loc = comb2 $1 $2 in
970                                            checkDo loc (unLoc $2)  >>= \ (stmts,body) ->
971                                            return (L loc (mkHsDo (MDoExpr noPostTcTable) stmts body)) }
972         | scc_annot exp                         { LL $ if opt_SccProfilingOn
973                                                         then HsSCC (unLoc $1) $2
974                                                         else HsPar $2 }
975
976         | 'proc' aexp '->' exp  
977                         {% checkPattern $2 >>= \ p -> 
978                            return (LL $ HsProc p (LL $ HsCmdTop $4 [] 
979                                                    placeHolderType undefined)) }
980                                                 -- TODO: is LL right here?
981
982         | '{-# CORE' STRING '#-}' exp           { LL $ HsCoreAnn (getSTRING $2) $4 }
983                                                     -- hdaume: core annotation
984         | fexp                                  { $1 }
985
986 scc_annot :: { Located FastString }
987         : '_scc_' STRING                        { LL $ getSTRING $2 }
988         | '{-# SCC' STRING '#-}'                { LL $ getSTRING $2 }
989
990 fexp    :: { LHsExpr RdrName }
991         : fexp aexp                             { LL $ HsApp $1 $2 }
992         | aexp                                  { $1 }
993
994 aexps   :: { [LHsExpr RdrName] }
995         : aexps aexp                            { $2 : $1 }
996         | {- empty -}                           { [] }
997
998 aexp    :: { LHsExpr RdrName }
999         : qvar '@' aexp                 { LL $ EAsPat $1 $3 }
1000         | '~' aexp                      { LL $ ELazyPat $2 }
1001 --      | '!' aexp                      { LL $ EBangPat $2 }
1002         | aexp1                         { $1 }
1003
1004 aexp1   :: { LHsExpr RdrName }
1005         : aexp1 '{' fbinds '}'  {% do { r <- mkRecConstrOrUpdate $1 (comb2 $2 $4) 
1006                                                         (reverse $3);
1007                                         return (LL r) }}
1008         | aexp2                 { $1 }
1009
1010 -- Here was the syntax for type applications that I was planning
1011 -- but there are difficulties (e.g. what order for type args)
1012 -- so it's not enabled yet.
1013 -- But this case *is* used for the left hand side of a generic definition,
1014 -- which is parsed as an expression before being munged into a pattern
1015         | qcname '{|' gentype '|}'      { LL $ HsApp (sL (getLoc $1) (HsVar (unLoc $1)))
1016                                                      (sL (getLoc $3) (HsType $3)) }
1017
1018 aexp2   :: { LHsExpr RdrName }
1019         : ipvar                         { L1 (HsIPVar $! unLoc $1) }
1020         | qcname                        { L1 (HsVar   $! unLoc $1) }
1021         | literal                       { L1 (HsLit   $! unLoc $1) }
1022         | INTEGER                       { L1 (HsOverLit $! mkHsIntegral (getINTEGER $1)) }
1023         | RATIONAL                      { L1 (HsOverLit $! mkHsFractional (getRATIONAL $1)) }
1024         | '(' exp ')'                   { LL (HsPar $2) }
1025         | '(' texp ',' texps ')'        { LL $ ExplicitTuple ($2 : reverse $4) Boxed }
1026         | '(#' texps '#)'               { LL $ ExplicitTuple (reverse $2)      Unboxed }
1027         | '[' list ']'                  { LL (unLoc $2) }
1028         | '[:' parr ':]'                { LL (unLoc $2) }
1029         | '(' infixexp qop ')'          { LL $ SectionL $2 $3 }
1030         | '(' qopm infixexp ')'         { LL $ SectionR $2 $3 }
1031         | '_'                           { L1 EWildPat }
1032         
1033         -- Template Haskell Extension
1034         | TH_ID_SPLICE          { L1 $ HsSpliceE (mkHsSplice 
1035                                         (L1 $ HsVar (mkUnqual varName 
1036                                                         (getTH_ID_SPLICE $1)))) } -- $x
1037         | '$(' exp ')'          { LL $ HsSpliceE (mkHsSplice $2) }               -- $( exp )
1038
1039         | TH_VAR_QUOTE qvar     { LL $ HsBracket (VarBr (unLoc $2)) }
1040         | TH_VAR_QUOTE qcon     { LL $ HsBracket (VarBr (unLoc $2)) }
1041         | TH_TY_QUOTE tyvar     { LL $ HsBracket (VarBr (unLoc $2)) }
1042         | TH_TY_QUOTE gtycon    { LL $ HsBracket (VarBr (unLoc $2)) }
1043         | '[|' exp '|]'         { LL $ HsBracket (ExpBr $2) }                       
1044         | '[t|' ctype '|]'      { LL $ HsBracket (TypBr $2) }                       
1045         | '[p|' infixexp '|]'   {% checkPattern $2 >>= \p ->
1046                                            return (LL $ HsBracket (PatBr p)) }
1047         | '[d|' cvtopbody '|]'  { LL $ HsBracket (DecBr (mkGroup $2)) }
1048
1049         -- arrow notation extension
1050         | '(|' aexp2 cmdargs '|)'       { LL $ HsArrForm $2 Nothing (reverse $3) }
1051
1052 cmdargs :: { [LHsCmdTop RdrName] }
1053         : cmdargs acmd                  { $2 : $1 }
1054         | {- empty -}                   { [] }
1055
1056 acmd    :: { LHsCmdTop RdrName }
1057         : aexp2                 { L1 $ HsCmdTop $1 [] placeHolderType undefined }
1058
1059 cvtopbody :: { [LHsDecl RdrName] }
1060         :  '{'            cvtopdecls0 '}'               { $2 }
1061         |      vocurly    cvtopdecls0 close             { $2 }
1062
1063 cvtopdecls0 :: { [LHsDecl RdrName] }
1064         : {- empty -}           { [] }
1065         | cvtopdecls            { $1 }
1066
1067 texp :: { LHsExpr RdrName }
1068         : exp                           { $1 }
1069         | qopm infixexp                 { LL $ SectionR $1 $2 }
1070         -- The second production is really here only for bang patterns
1071         -- but 
1072
1073 texps :: { [LHsExpr RdrName] }
1074         : texps ',' texp                { $3 : $1 }
1075         | texp                          { [$1] }
1076
1077
1078 -----------------------------------------------------------------------------
1079 -- List expressions
1080
1081 -- The rules below are little bit contorted to keep lexps left-recursive while
1082 -- avoiding another shift/reduce-conflict.
1083
1084 list :: { LHsExpr RdrName }
1085         : texp                  { L1 $ ExplicitList placeHolderType [$1] }
1086         | lexps                 { L1 $ ExplicitList placeHolderType (reverse (unLoc $1)) }
1087         | texp '..'             { LL $ ArithSeq noPostTcExpr (From $1) }
1088         | texp ',' exp '..'     { LL $ ArithSeq noPostTcExpr (FromThen $1 $3) }
1089         | texp '..' exp         { LL $ ArithSeq noPostTcExpr (FromTo $1 $3) }
1090         | texp ',' exp '..' exp { LL $ ArithSeq noPostTcExpr (FromThenTo $1 $3 $5) }
1091         | texp pquals           { sL (comb2 $1 $>) $ mkHsDo ListComp (reverse (unLoc $2)) $1 }
1092
1093 lexps :: { Located [LHsExpr RdrName] }
1094         : lexps ',' texp                { LL ($3 : unLoc $1) }
1095         | texp ',' texp                 { LL [$3,$1] }
1096
1097 -----------------------------------------------------------------------------
1098 -- List Comprehensions
1099
1100 pquals :: { Located [LStmt RdrName] }   -- Either a singleton ParStmt, 
1101                                         -- or a reversed list of Stmts
1102         : pquals1                       { case unLoc $1 of
1103                                             [qs] -> L1 qs
1104                                             qss  -> L1 [L1 (ParStmt stmtss)]
1105                                                  where
1106                                                     stmtss = [ (reverse qs, undefined) 
1107                                                              | qs <- qss ]
1108                                         }
1109                         
1110 pquals1 :: { Located [[LStmt RdrName]] }
1111         : pquals1 '|' quals             { LL (unLoc $3 : unLoc $1) }
1112         | '|' quals                     { L (getLoc $2) [unLoc $2] }
1113
1114 quals :: { Located [LStmt RdrName] }
1115         : quals ',' qual                { LL ($3 : unLoc $1) }
1116         | qual                          { L1 [$1] }
1117
1118 -----------------------------------------------------------------------------
1119 -- Parallel array expressions
1120
1121 -- The rules below are little bit contorted; see the list case for details.
1122 -- Note that, in contrast to lists, we only have finite arithmetic sequences.
1123 -- Moreover, we allow explicit arrays with no element (represented by the nil
1124 -- constructor in the list case).
1125
1126 parr :: { LHsExpr RdrName }
1127         :                               { noLoc (ExplicitPArr placeHolderType []) }
1128         | exp                           { L1 $ ExplicitPArr placeHolderType [$1] }
1129         | lexps                         { L1 $ ExplicitPArr placeHolderType 
1130                                                        (reverse (unLoc $1)) }
1131         | exp '..' exp                  { LL $ PArrSeq noPostTcExpr (FromTo $1 $3) }
1132         | exp ',' exp '..' exp          { LL $ PArrSeq noPostTcExpr (FromThenTo $1 $3 $5) }
1133         | exp pquals                    { sL (comb2 $1 $>) $ mkHsDo PArrComp (reverse (unLoc $2)) $1 }
1134
1135 -- We are reusing `lexps' and `pquals' from the list case.
1136
1137 -----------------------------------------------------------------------------
1138 -- Case alternatives
1139
1140 altslist :: { Located [LMatch RdrName] }
1141         : '{'            alts '}'       { LL (reverse (unLoc $2)) }
1142         |     vocurly    alts  close    { L (getLoc $2) (reverse (unLoc $2)) }
1143
1144 alts    :: { Located [LMatch RdrName] }
1145         : alts1                         { L1 (unLoc $1) }
1146         | ';' alts                      { LL (unLoc $2) }
1147
1148 alts1   :: { Located [LMatch RdrName] }
1149         : alts1 ';' alt                 { LL ($3 : unLoc $1) }
1150         | alts1 ';'                     { LL (unLoc $1) }
1151         | alt                           { L1 [$1] }
1152
1153 alt     :: { LMatch RdrName }
1154         : infixexp opt_sig alt_rhs      {%  checkPattern $1 >>= \p ->
1155                                             return (LL (Match [p] $2 (unLoc $3))) }
1156         | '!' infixexp opt_sig alt_rhs  {%  checkPattern $2 >>= \p ->
1157                                             return (LL (Match [LL $ BangPat p] $3 (unLoc $4))) }
1158
1159 alt_rhs :: { Located (GRHSs RdrName) }
1160         : ralt wherebinds               { LL (GRHSs (unLoc $1) (unLoc $2)) }
1161
1162 ralt :: { Located [LGRHS RdrName] }
1163         : '->' exp                      { LL (unguardedRHS $2) }
1164         | gdpats                        { L1 (reverse (unLoc $1)) }
1165
1166 gdpats :: { Located [LGRHS RdrName] }
1167         : gdpats gdpat                  { LL ($2 : unLoc $1) }
1168         | gdpat                         { L1 [$1] }
1169
1170 gdpat   :: { LGRHS RdrName }
1171         : '|' quals '->' exp            { sL (comb2 $1 $>) $ GRHS (reverse (unLoc $2)) $4 }
1172
1173 -----------------------------------------------------------------------------
1174 -- Statement sequences
1175
1176 stmtlist :: { Located [LStmt RdrName] }
1177         : '{'           stmts '}'       { LL (unLoc $2) }
1178         |     vocurly   stmts close     { $2 }
1179
1180 --      do { ;; s ; s ; ; s ;; }
1181 -- The last Stmt should be an expression, but that's hard to enforce
1182 -- here, because we need too much lookahead if we see do { e ; }
1183 -- So we use ExprStmts throughout, and switch the last one over
1184 -- in ParseUtils.checkDo instead
1185 stmts :: { Located [LStmt RdrName] }
1186         : stmt stmts_help               { LL ($1 : unLoc $2) }
1187         | ';' stmts                     { LL (unLoc $2) }
1188         | {- empty -}                   { noLoc [] }
1189
1190 stmts_help :: { Located [LStmt RdrName] } -- might be empty
1191         : ';' stmts                     { LL (unLoc $2) }
1192         | {- empty -}                   { noLoc [] }
1193
1194 -- For typing stmts at the GHCi prompt, where 
1195 -- the input may consist of just comments.
1196 maybe_stmt :: { Maybe (LStmt RdrName) }
1197         : stmt                          { Just $1 }
1198         | {- nothing -}                 { Nothing }
1199
1200 stmt  :: { LStmt RdrName }
1201         : qual                          { $1 }
1202         | infixexp '->' exp             {% checkPattern $3 >>= \p ->
1203                                            return (LL $ mkBindStmt p $1) }
1204         | 'rec' stmtlist                { LL $ mkRecStmt (unLoc $2) }
1205
1206 qual  :: { LStmt RdrName }
1207         : exp '<-' exp                  {% checkPattern $1 >>= \p ->
1208                                            return (LL $ mkBindStmt p $3) }
1209         | exp                           { L1 $ mkExprStmt $1 }
1210         | 'let' binds                   { LL $ LetStmt (unLoc $2) }
1211
1212 -----------------------------------------------------------------------------
1213 -- Record Field Update/Construction
1214
1215 fbinds  :: { HsRecordBinds RdrName }
1216         : fbinds1                       { $1 }
1217         | {- empty -}                   { [] }
1218
1219 fbinds1 :: { HsRecordBinds RdrName }
1220         : fbinds1 ',' fbind             { $3 : $1 }
1221         | fbind                         { [$1] }
1222   
1223 fbind   :: { (Located RdrName, LHsExpr RdrName) }
1224         : qvar '=' exp                  { ($1,$3) }
1225
1226 -----------------------------------------------------------------------------
1227 -- Implicit Parameter Bindings
1228
1229 dbinds  :: { Located [LIPBind RdrName] }
1230         : dbinds ';' dbind              { LL ($3 : unLoc $1) }
1231         | dbinds ';'                    { LL (unLoc $1) }
1232         | dbind                         { L1 [$1] }
1233 --      | {- empty -}                   { [] }
1234
1235 dbind   :: { LIPBind RdrName }
1236 dbind   : ipvar '=' exp                 { LL (IPBind (unLoc $1) $3) }
1237
1238 ipvar   :: { Located (IPName RdrName) }
1239         : IPDUPVARID            { L1 (Dupable (mkUnqual varName (getIPDUPVARID $1))) }
1240         | IPSPLITVARID          { L1 (Linear  (mkUnqual varName (getIPSPLITVARID $1))) }
1241
1242 -----------------------------------------------------------------------------
1243 -- Deprecations
1244
1245 depreclist :: { Located [RdrName] }
1246 depreclist : deprec_var                 { L1 [unLoc $1] }
1247            | deprec_var ',' depreclist  { LL (unLoc $1 : unLoc $3) }
1248
1249 deprec_var :: { Located RdrName }
1250 deprec_var : var                        { $1 }
1251            | con                        { $1 }
1252
1253 -----------------------------------------
1254 -- Data constructors
1255 qcon    :: { Located RdrName }
1256         : qconid                { $1 }
1257         | '(' qconsym ')'       { LL (unLoc $2) }
1258         | sysdcon               { L1 $ nameRdrName (dataConName (unLoc $1)) }
1259 -- The case of '[:' ':]' is part of the production `parr'
1260
1261 con     :: { Located RdrName }
1262         : conid                 { $1 }
1263         | '(' consym ')'        { LL (unLoc $2) }
1264         | sysdcon               { L1 $ nameRdrName (dataConName (unLoc $1)) }
1265
1266 sysdcon :: { Located DataCon }  -- Wired in data constructors
1267         : '(' ')'               { LL unitDataCon }
1268         | '(' commas ')'        { LL $ tupleCon Boxed $2 }
1269         | '[' ']'               { LL nilDataCon }
1270
1271 conop :: { Located RdrName }
1272         : consym                { $1 }  
1273         | '`' conid '`'         { LL (unLoc $2) }
1274
1275 qconop :: { Located RdrName }
1276         : qconsym               { $1 }
1277         | '`' qconid '`'        { LL (unLoc $2) }
1278
1279 -----------------------------------------------------------------------------
1280 -- Type constructors
1281
1282 gtycon  :: { Located RdrName }  -- A "general" qualified tycon
1283         : oqtycon                       { $1 }
1284         | '(' ')'                       { LL $ getRdrName unitTyCon }
1285         | '(' commas ')'                { LL $ getRdrName (tupleTyCon Boxed $2) }
1286         | '(' '->' ')'                  { LL $ getRdrName funTyCon }
1287         | '[' ']'                       { LL $ listTyCon_RDR }
1288         | '[:' ':]'                     { LL $ parrTyCon_RDR }
1289
1290 oqtycon :: { Located RdrName }  -- An "ordinary" qualified tycon
1291         : qtycon                        { $1 }
1292         | '(' qtyconsym ')'             { LL (unLoc $2) }
1293
1294 qtyconop :: { Located RdrName } -- Qualified or unqualified
1295         : qtyconsym                     { $1 }
1296         | '`' qtycon '`'                { LL (unLoc $2) }
1297
1298 qtycon :: { Located RdrName }   -- Qualified or unqualified
1299         : QCONID                        { L1 $! mkQual tcClsName (getQCONID $1) }
1300         | tycon                         { $1 }
1301
1302 tycon   :: { Located RdrName }  -- Unqualified
1303         : CONID                         { L1 $! mkUnqual tcClsName (getCONID $1) }
1304
1305 qtyconsym :: { Located RdrName }
1306         : QCONSYM                       { L1 $! mkQual tcClsName (getQCONSYM $1) }
1307         | tyconsym                      { $1 }
1308
1309 tyconsym :: { Located RdrName }
1310         : CONSYM                        { L1 $! mkUnqual tcClsName (getCONSYM $1) }
1311
1312 -----------------------------------------------------------------------------
1313 -- Operators
1314
1315 op      :: { Located RdrName }   -- used in infix decls
1316         : varop                 { $1 }
1317         | conop                 { $1 }
1318
1319 varop   :: { Located RdrName }
1320         : varsym                { $1 }
1321         | '`' varid '`'         { LL (unLoc $2) }
1322
1323 qop     :: { LHsExpr RdrName }   -- used in sections
1324         : qvarop                { L1 $ HsVar (unLoc $1) }
1325         | qconop                { L1 $ HsVar (unLoc $1) }
1326
1327 qopm    :: { LHsExpr RdrName }   -- used in sections
1328         : qvaropm               { L1 $ HsVar (unLoc $1) }
1329         | qconop                { L1 $ HsVar (unLoc $1) }
1330
1331 qvarop :: { Located RdrName }
1332         : qvarsym               { $1 }
1333         | '`' qvarid '`'        { LL (unLoc $2) }
1334
1335 qvaropm :: { Located RdrName }
1336         : qvarsym_no_minus      { $1 }
1337         | '`' qvarid '`'        { LL (unLoc $2) }
1338
1339 -----------------------------------------------------------------------------
1340 -- Type variables
1341
1342 tyvar   :: { Located RdrName }
1343 tyvar   : tyvarid               { $1 }
1344         | '(' tyvarsym ')'      { LL (unLoc $2) }
1345
1346 tyvarop :: { Located RdrName }
1347 tyvarop : '`' tyvarid '`'       { LL (unLoc $2) }
1348         | tyvarsym              { $1 }
1349
1350 tyvarid :: { Located RdrName }
1351         : VARID                 { L1 $! mkUnqual tvName (getVARID $1) }
1352         | special_id            { L1 $! mkUnqual tvName (unLoc $1) }
1353         | 'unsafe'              { L1 $! mkUnqual tvName FSLIT("unsafe") }
1354         | 'safe'                { L1 $! mkUnqual tvName FSLIT("safe") }
1355         | 'threadsafe'          { L1 $! mkUnqual tvName FSLIT("threadsafe") }
1356
1357 tyvarsym :: { Located RdrName }
1358 -- Does not include "!", because that is used for strictness marks
1359 --               or ".", because that separates the quantified type vars from the rest
1360 --               or "*", because that's used for kinds
1361 tyvarsym : VARSYM               { L1 $! mkUnqual tvName (getVARSYM $1) }
1362
1363 -----------------------------------------------------------------------------
1364 -- Variables 
1365
1366 var     :: { Located RdrName }
1367         : varid                 { $1 }
1368         | '(' varsym ')'        { LL (unLoc $2) }
1369
1370 qvar    :: { Located RdrName }
1371         : qvarid                { $1 }
1372         | '(' varsym ')'        { LL (unLoc $2) }
1373         | '(' qvarsym1 ')'      { LL (unLoc $2) }
1374 -- We've inlined qvarsym here so that the decision about
1375 -- whether it's a qvar or a var can be postponed until
1376 -- *after* we see the close paren.
1377
1378 qvarid :: { Located RdrName }
1379         : varid                 { $1 }
1380         | QVARID                { L1 $ mkQual varName (getQVARID $1) }
1381
1382 varid :: { Located RdrName }
1383         : varid_no_unsafe       { $1 }
1384         | 'unsafe'              { L1 $! mkUnqual varName FSLIT("unsafe") }
1385         | 'safe'                { L1 $! mkUnqual varName FSLIT("safe") }
1386         | 'threadsafe'          { L1 $! mkUnqual varName FSLIT("threadsafe") }
1387
1388 varid_no_unsafe :: { Located RdrName }
1389         : VARID                 { L1 $! mkUnqual varName (getVARID $1) }
1390         | special_id            { L1 $! mkUnqual varName (unLoc $1) }
1391         | 'forall'              { L1 $! mkUnqual varName FSLIT("forall") }
1392
1393 qvarsym :: { Located RdrName }
1394         : varsym                { $1 }
1395         | qvarsym1              { $1 }
1396
1397 qvarsym_no_minus :: { Located RdrName }
1398         : varsym_no_minus       { $1 }
1399         | qvarsym1              { $1 }
1400
1401 qvarsym1 :: { Located RdrName }
1402 qvarsym1 : QVARSYM              { L1 $ mkQual varName (getQVARSYM $1) }
1403
1404 varsym :: { Located RdrName }
1405         : varsym_no_minus       { $1 }
1406         | '-'                   { L1 $ mkUnqual varName FSLIT("-") }
1407
1408 varsym_no_minus :: { Located RdrName } -- varsym not including '-'
1409         : VARSYM                { L1 $ mkUnqual varName (getVARSYM $1) }
1410         | special_sym           { L1 $ mkUnqual varName (unLoc $1) }
1411
1412
1413 -- These special_ids are treated as keywords in various places, 
1414 -- but as ordinary ids elsewhere.   'special_id' collects all these
1415 -- except 'unsafe' and 'forall' whose treatment differs depending on context
1416 special_id :: { Located FastString }
1417 special_id
1418         : 'as'                  { L1 FSLIT("as") }
1419         | 'qualified'           { L1 FSLIT("qualified") }
1420         | 'hiding'              { L1 FSLIT("hiding") }
1421         | 'export'              { L1 FSLIT("export") }
1422         | 'label'               { L1 FSLIT("label")  }
1423         | 'dynamic'             { L1 FSLIT("dynamic") }
1424         | 'stdcall'             { L1 FSLIT("stdcall") }
1425         | 'ccall'               { L1 FSLIT("ccall") }
1426         | 'iso'                 { L1 FSLIT("iso") }
1427
1428 special_sym :: { Located FastString }
1429 special_sym : '!'       { L1 FSLIT("!") }
1430             | '.'       { L1 FSLIT(".") }
1431             | '*'       { L1 FSLIT("*") }
1432
1433 -----------------------------------------------------------------------------
1434 -- Data constructors
1435
1436 qconid :: { Located RdrName }   -- Qualified or unqualified
1437         : conid                 { $1 }
1438         | QCONID                { L1 $ mkQual dataName (getQCONID $1) }
1439
1440 conid   :: { Located RdrName }
1441         : CONID                 { L1 $ mkUnqual dataName (getCONID $1) }
1442
1443 qconsym :: { Located RdrName }  -- Qualified or unqualified
1444         : consym                { $1 }
1445         | QCONSYM               { L1 $ mkQual dataName (getQCONSYM $1) }
1446
1447 consym :: { Located RdrName }
1448         : CONSYM                { L1 $ mkUnqual dataName (getCONSYM $1) }
1449
1450         -- ':' means only list cons
1451         | ':'                   { L1 $ consDataCon_RDR }
1452
1453
1454 -----------------------------------------------------------------------------
1455 -- Literals
1456
1457 literal :: { Located HsLit }
1458         : CHAR                  { L1 $ HsChar       $ getCHAR $1 }
1459         | STRING                { L1 $ HsString     $ getSTRING $1 }
1460         | PRIMINTEGER           { L1 $ HsIntPrim    $ getPRIMINTEGER $1 }
1461         | PRIMCHAR              { L1 $ HsCharPrim   $ getPRIMCHAR $1 }
1462         | PRIMSTRING            { L1 $ HsStringPrim $ getPRIMSTRING $1 }
1463         | PRIMFLOAT             { L1 $ HsFloatPrim  $ getPRIMFLOAT $1 }
1464         | PRIMDOUBLE            { L1 $ HsDoublePrim $ getPRIMDOUBLE $1 }
1465
1466 -----------------------------------------------------------------------------
1467 -- Layout
1468
1469 close :: { () }
1470         : vccurly               { () } -- context popped in lexer.
1471         | error                 {% popContext }
1472
1473 -----------------------------------------------------------------------------
1474 -- Miscellaneous (mostly renamings)
1475
1476 modid   :: { Located ModuleName }
1477         : CONID                 { L1 $ mkModuleNameFS (getCONID $1) }
1478         | QCONID                { L1 $ let (mod,c) = getQCONID $1 in
1479                                   mkModuleNameFS
1480                                    (mkFastString
1481                                      (unpackFS mod ++ '.':unpackFS c))
1482                                 }
1483
1484 commas :: { Int }
1485         : commas ','                    { $1 + 1 }
1486         | ','                           { 2 }
1487
1488 -----------------------------------------------------------------------------
1489
1490 {
1491 happyError :: P a
1492 happyError = srcParseFail
1493
1494 getVARID        (L _ (ITvarid    x)) = x
1495 getCONID        (L _ (ITconid    x)) = x
1496 getVARSYM       (L _ (ITvarsym   x)) = x
1497 getCONSYM       (L _ (ITconsym   x)) = x
1498 getQVARID       (L _ (ITqvarid   x)) = x
1499 getQCONID       (L _ (ITqconid   x)) = x
1500 getQVARSYM      (L _ (ITqvarsym  x)) = x
1501 getQCONSYM      (L _ (ITqconsym  x)) = x
1502 getIPDUPVARID   (L _ (ITdupipvarid   x)) = x
1503 getIPSPLITVARID (L _ (ITsplitipvarid x)) = x
1504 getCHAR         (L _ (ITchar     x)) = x
1505 getSTRING       (L _ (ITstring   x)) = x
1506 getINTEGER      (L _ (ITinteger  x)) = x
1507 getRATIONAL     (L _ (ITrational x)) = x
1508 getPRIMCHAR     (L _ (ITprimchar   x)) = x
1509 getPRIMSTRING   (L _ (ITprimstring x)) = x
1510 getPRIMINTEGER  (L _ (ITprimint    x)) = x
1511 getPRIMFLOAT    (L _ (ITprimfloat  x)) = x
1512 getPRIMDOUBLE   (L _ (ITprimdouble x)) = x
1513 getTH_ID_SPLICE (L _ (ITidEscape x)) = x
1514 getINLINE       (L _ (ITinline_prag b)) = b
1515 getSPEC_INLINE  (L _ (ITspec_inline_prag b)) = b
1516
1517 -- Utilities for combining source spans
1518 comb2 :: Located a -> Located b -> SrcSpan
1519 comb2 = combineLocs
1520
1521 comb3 :: Located a -> Located b -> Located c -> SrcSpan
1522 comb3 a b c = combineSrcSpans (getLoc a) (combineSrcSpans (getLoc b) (getLoc c))
1523
1524 comb4 :: Located a -> Located b -> Located c -> Located d -> SrcSpan
1525 comb4 a b c d = combineSrcSpans (getLoc a) $ combineSrcSpans (getLoc b) $
1526                 combineSrcSpans (getLoc c) (getLoc d)
1527
1528 -- strict constructor version:
1529 {-# INLINE sL #-}
1530 sL :: SrcSpan -> a -> Located a
1531 sL span a = span `seq` L span a
1532
1533 -- Make a source location for the file.  We're a bit lazy here and just
1534 -- make a point SrcSpan at line 1, column 0.  Strictly speaking we should
1535 -- try to find the span of the whole file (ToDo).
1536 fileSrcSpan :: P SrcSpan
1537 fileSrcSpan = do 
1538   l <- getSrcLoc; 
1539   let loc = mkSrcLoc (srcLocFile l) 1 0;
1540   return (mkSrcSpan loc loc)
1541 }