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