2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.121 2003/07/16 08:49:05 ross Exp $
7 Author(s): Simon Marlow, Sven Panne 1997, 1998, 1999
8 -----------------------------------------------------------------------------
12 module Parser ( parseModule, parseStmt, parseIdentifier, parseIface ) where
14 #include "HsVersions.h"
17 import HsTypes ( mkHsTupCon )
20 import HscTypes ( ParsedIface(..), IsBootInterface, noDependencies )
23 import PrelNames ( mAIN_Name, funTyConName, listTyConName,
24 parrTyConName, consDataConName )
25 import TysWiredIn ( unitTyCon, unitDataCon, tupleTyCon, tupleCon, nilDataCon )
26 import ForeignCall ( Safety(..), CExportSpec(..),
27 CCallConv(..), CCallTarget(..), defaultCCallConv,
29 import OccName ( UserFS, varName, tcName, dataName, tcClsName, tvName )
30 import TyCon ( DataConDetails(..) )
31 import DataCon ( DataCon, dataConName )
32 import SrcLoc ( SrcLoc )
34 import CmdLineOpts ( opt_SccProfilingOn, opt_InPackage )
35 import Type ( Kind, mkArrowKind, liftedTypeKind )
36 import BasicTypes ( Boxity(..), Fixity(..), FixityDirection(..), IPName(..),
37 NewOrData(..), StrictnessMark(..), Activation(..),
42 import CStrings ( CLabelString )
44 import Maybes ( orElse )
50 -----------------------------------------------------------------------------
51 Conflicts: 29 shift/reduce, [SDM 19/9/2002]
53 10 for abiguity in 'if x then y else z + 1' [State 136]
54 (shift parses as 'if x then y else (z + 1)', as per longest-parse rule)
55 10 because op might be: : - ! * . `x` VARSYM CONSYM QVARSYM QCONSYM
57 1 for ambiguity in 'if x then y else z with ?x=3' [State 136]
58 (shift parses as 'if x then y else (z with ?x=3)'
60 1 for ambiguity in 'if x then y else z :: T' [State 136]
61 (shift parses as 'if x then y else (z :: T)', as per longest-parse rule)
63 8 for ambiguity in 'e :: a `b` c'. Does this mean [States 160,246]
67 1 for ambiguity in 'let ?x ...' [State 268]
68 the parser can't tell whether the ?x is the lhs of a normal binding or
69 an implicit binding. Fortunately resolving as shift gives it the only
70 sensible meaning, namely the lhs of an implicit binding.
72 1 for ambiguity in '{-# RULES "name" [ ... #-} [State 332]
73 we don't know whether the '[' starts the activation or not: it
74 might be the start of the declaration with the activation being
77 1 for ambiguity in '{-# RULES "name" forall = ... #-}' [State 394]
78 since 'forall' is a valid variable name, we don't know whether
79 to treat a forall on the input as the beginning of a quantifier
80 or the beginning of the rule itself. Resolving to shift means
81 it's always treated as a quantifier, hence the above is disallowed.
82 This saves explicitly defining a grammar for the rule lhs that
83 doesn't include 'forall'.
85 6 for conflicts between `fdecl' and `fdeclDEPRECATED', [States 384,385]
86 which are resolved correctly, and moreover,
87 should go away when `fdeclDEPRECATED' is removed.
89 -----------------------------------------------------------------------------
93 '_' { ITunderscore } -- Haskell keywords
98 'default' { ITdefault }
99 'deriving' { ITderiving }
102 'hiding' { IThiding }
104 'import' { ITimport }
107 'infixl' { ITinfixl }
108 'infixr' { ITinfixr }
109 'instance' { ITinstance }
111 'module' { ITmodule }
112 'newtype' { ITnewtype }
114 'qualified' { ITqualified }
118 '_scc_' { ITscc } -- ToDo: remove
120 'forall' { ITforall } -- GHC extension keywords
121 'foreign' { ITforeign }
122 'export' { ITexport }
124 'dynamic' { ITdynamic }
126 'threadsafe' { ITthreadsafe }
127 'unsafe' { ITunsafe }
130 'stdcall' { ITstdcallconv }
131 'ccall' { ITccallconv }
132 'dotnet' { ITdotnet }
133 'proc' { ITproc } -- for arrow notation extension
134 'rec' { ITrec } -- for arrow notation extension
135 '_ccall_' { ITccall (False, False, PlayRisky) }
136 '_ccall_GC_' { ITccall (False, False, PlaySafe False) }
137 '_casm_' { ITccall (False, True, PlayRisky) }
138 '_casm_GC_' { ITccall (False, True, PlaySafe False) }
140 '{-# SPECIALISE' { ITspecialise_prag }
141 '{-# SOURCE' { ITsource_prag }
142 '{-# INLINE' { ITinline_prag }
143 '{-# NOINLINE' { ITnoinline_prag }
144 '{-# RULES' { ITrules_prag }
145 '{-# CORE' { ITcore_prag } -- hdaume: annotated core
146 '{-# SCC' { ITscc_prag }
147 '{-# DEPRECATED' { ITdeprecated_prag }
148 '#-}' { ITclose_prag }
151 '__interface' { ITinterface } -- interface keywords
152 '__export' { IT__export }
153 '__instimport' { ITinstimport }
154 '__forall' { IT__forall }
155 '__letrec' { ITletrec }
156 '__coerce' { ITcoerce }
157 '__depends' { ITdepends }
158 '__inline' { ITinline }
159 '__DEFAULT' { ITdefaultbranch }
161 '__integer' { ITinteger_lit }
162 '__float' { ITfloat_lit }
163 '__rational' { ITrational_lit }
164 '__addr' { ITaddr_lit }
165 '__label' { ITlabel_lit }
166 '__litlit' { ITlit_lit }
167 '__string' { ITstring_lit }
168 '__ccall' { ITccall $$ }
170 '__sccC' { ITsccAllCafs }
173 '__P' { ITspecialise }
176 '__S' { ITstrict $$ }
177 '__M' { ITcprinfo $$ }
180 '..' { ITdotdot } -- reserved symbols
194 '-<' { ITlarrowtail } -- for arrow notation
195 '>-' { ITrarrowtail } -- for arrow notation
196 '-<<' { ITLarrowtail } -- for arrow notation
197 '>>-' { ITRarrowtail } -- for arrow notation
200 '{' { ITocurly } -- special symbols
204 vccurly { ITvccurly } -- virtual close curly (from layout)
219 VARID { ITvarid $$ } -- identifiers
221 VARSYM { ITvarsym $$ }
222 CONSYM { ITconsym $$ }
223 QVARID { ITqvarid $$ }
224 QCONID { ITqconid $$ }
225 QVARSYM { ITqvarsym $$ }
226 QCONSYM { ITqconsym $$ }
228 IPDUPVARID { ITdupipvarid $$ } -- GHC extension
229 IPSPLITVARID { ITsplitipvarid $$ } -- GHC extension
232 STRING { ITstring $$ }
233 INTEGER { ITinteger $$ }
234 RATIONAL { ITrational $$ }
236 PRIMCHAR { ITprimchar $$ }
237 PRIMSTRING { ITprimstring $$ }
238 PRIMINTEGER { ITprimint $$ }
239 PRIMFLOAT { ITprimfloat $$ }
240 PRIMDOUBLE { ITprimdouble $$ }
241 CLITLIT { ITlitlit $$ }
244 '[|' { ITopenExpQuote }
245 '[p|' { ITopenPatQuote }
246 '[t|' { ITopenTypQuote }
247 '[d|' { ITopenDecQuote }
248 '|]' { ITcloseQuote }
249 ID_SPLICE { ITidEscape $$ } -- $x
250 '$(' { ITparenEscape } -- $( exp )
251 REIFY_TYPE { ITreifyType }
252 REIFY_DECL { ITreifyDecl }
253 REIFY_FIXITY { ITreifyFixity }
255 %monad { P } { thenP } { returnP }
256 %lexer { lexer } { ITeof }
257 %name parseModule module
258 %name parseStmt maybe_stmt
259 %name parseIdentifier identifier
260 %name parseIface iface
264 -----------------------------------------------------------------------------
267 -- The place for module deprecation is really too restrictive, but if it
268 -- was allowed at its natural place just before 'module', we get an ugly
269 -- s/r conflict with the second alternative. Another solution would be the
270 -- introduction of a new pragma DEPRECATED_MODULE, but this is not very nice,
271 -- either, and DEPRECATED is only expected to be used by people who really
272 -- know what they are doing. :-)
274 module :: { RdrNameHsModule }
275 : srcloc 'module' modid maybemoddeprec maybeexports 'where' body
276 { HsModule (Just (mkHomeModule $3)) $5 (fst $7) (snd $7) $4 $1 }
278 { HsModule Nothing Nothing (fst $2) (snd $2) Nothing $1 }
280 maybemoddeprec :: { Maybe DeprecTxt }
281 : '{-# DEPRECATED' STRING '#-}' { Just $2 }
282 | {- empty -} { Nothing }
284 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
286 | layout_on top close { $2 }
288 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
289 : importdecls { (reverse $1,[]) }
290 | importdecls ';' cvtopdecls { (reverse $1,$3) }
291 | cvtopdecls { ([],$1) }
293 cvtopdecls :: { [RdrNameHsDecl] }
294 : topdecls { cvTopDecls $1 }
296 -----------------------------------------------------------------------------
297 -- Interfaces (.hi-boot files)
299 iface :: { ParsedIface }
300 : 'module' modid 'where' ifacebody
303 pi_pkg = opt_InPackage,
304 pi_vers = 1, -- Module version
306 pi_exports = (1,[($2,mkIfaceExports $4)]),
307 pi_deps = noDependencies,
311 pi_decls = map (\x -> (1,x)) $4,
317 ifacebody :: { [RdrNameTyClDecl] }
318 : '{' ifacedecls '}' { $2 }
319 | layout_on ifacedecls close { $2 }
321 ifacedecls :: { [RdrNameTyClDecl] }
322 : ifacedecl ';' ifacedecls { $1 : $3 }
323 | ';' ifacedecls { $2 }
327 ifacedecl :: { RdrNameTyClDecl }
329 | srcloc var '::' sigtype { IfaceSig $2 $4 [] $1 }
331 -----------------------------------------------------------------------------
334 maybeexports :: { Maybe [RdrNameIE] }
335 : '(' exportlist ')' { Just $2 }
336 | {- empty -} { Nothing }
338 exportlist :: { [RdrNameIE] }
339 : exportlist ',' export { $3 : $1 }
340 | exportlist ',' { $1 }
344 -- No longer allow things like [] and (,,,) to be exported
345 -- They are built in syntax, always available
346 export :: { RdrNameIE }
348 | oqtycon { IEThingAbs $1 }
349 | oqtycon '(' '..' ')' { IEThingAll $1 }
350 | oqtycon '(' ')' { IEThingWith $1 [] }
351 | oqtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
352 | 'module' modid { IEModuleContents $2 }
354 qcnames :: { [RdrName] }
355 : qcnames ',' qcname { $3 : $1 }
358 qcname :: { RdrName } -- Variable or data constructor
362 -----------------------------------------------------------------------------
363 -- Import Declarations
365 -- import decls can be *empty*, or even just a string of semicolons
366 -- whereas topdecls must contain at least one topdecl.
368 importdecls :: { [RdrNameImportDecl] }
369 : importdecls ';' importdecl { $3 : $1 }
370 | importdecls ';' { $1 }
371 | importdecl { [ $1 ] }
374 importdecl :: { RdrNameImportDecl }
375 : 'import' srcloc maybe_src optqualified modid maybeas maybeimpspec
376 { ImportDecl $5 $3 $4 $6 $7 $2 }
378 maybe_src :: { IsBootInterface }
379 : '{-# SOURCE' '#-}' { True }
380 | {- empty -} { False }
382 optqualified :: { Bool }
383 : 'qualified' { True }
384 | {- empty -} { False }
386 maybeas :: { Maybe ModuleName }
387 : 'as' modid { Just $2 }
388 | {- empty -} { Nothing }
390 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
391 : impspec { Just $1 }
392 | {- empty -} { Nothing }
394 impspec :: { (Bool, [RdrNameIE]) }
395 : '(' exportlist ')' { (False, reverse $2) }
396 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
398 -----------------------------------------------------------------------------
399 -- Fixity Declarations
403 | INTEGER {% checkPrecP (fromInteger $1) }
405 infix :: { FixityDirection }
407 | 'infixl' { InfixL }
408 | 'infixr' { InfixR }
411 : ops ',' op { $3 : $1 }
414 -----------------------------------------------------------------------------
415 -- Top-Level Declarations
417 topdecls :: { [RdrBinding] } -- Reversed
418 : topdecls ';' topdecl { $3 : $1 }
419 | topdecls ';' { $1 }
422 topdecl :: { RdrBinding }
423 : tycl_decl { RdrHsDecl (TyClD $1) }
424 | srcloc 'instance' inst_type where
425 { let (binds,sigs) = cvMonoBindsAndSigs $4
426 in RdrHsDecl (InstD (InstDecl $3 binds sigs Nothing $1)) }
427 | srcloc 'default' '(' comma_types0 ')' { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
428 | 'foreign' fdecl { RdrHsDecl $2 }
429 | '{-# DEPRECATED' deprecations '#-}' { RdrBindings (reverse $2) }
430 | '{-# RULES' rules '#-}' { RdrBindings (reverse $2) }
431 | srcloc '$(' exp ')' { RdrHsDecl (SpliceD (SpliceDecl $3 $1)) }
434 tycl_decl :: { RdrNameTyClDecl }
435 : srcloc 'type' syn_hdr '=' ctype
436 -- Note ctype, not sigtype.
437 -- We allow an explicit for-all but we don't insert one
438 -- in type Foo a = (b,b)
439 -- Instead we just say b is out of scope
440 { let (tc,tvs) = $3 in TySynonym tc tvs $5 $1 }
443 | srcloc 'data' tycl_hdr constrs deriving
444 { mkTyData DataType $3 (DataCons (reverse $4)) $5 $1 }
446 | srcloc 'newtype' tycl_hdr '=' newconstr deriving
447 { mkTyData NewType $3 (DataCons [$5]) $6 $1 }
449 | srcloc 'class' tycl_hdr fds where
451 (binds,sigs) = cvMonoBindsAndSigs $5
453 mkClassDecl $3 $4 sigs (Just binds) $1 }
455 syn_hdr :: { (RdrName, [RdrNameHsTyVar]) } -- We don't retain the syntax of an infix
456 -- type synonym declaration. Oh well.
457 : tycon tv_bndrs { ($1, $2) }
458 | tv_bndr tyconop tv_bndr { ($2, [$1,$3]) }
460 -- tycl_hdr parses the header of a type or class decl,
461 -- which takes the form
464 -- (Eq a, Ord b) => T a b
465 -- Rather a lot of inlining here, else we get reduce/reduce errors
466 tycl_hdr :: { (RdrNameContext, RdrName, [RdrNameHsTyVar]) }
467 : context '=>' type {% checkTyClHdr $3 `thenP` \ (tc,tvs) ->
468 returnP ($1, tc, tvs) }
469 | type {% checkTyClHdr $1 `thenP` \ (tc,tvs) ->
470 returnP ([], tc, tvs) }
472 -----------------------------------------------------------------------------
473 -- Nested declarations
475 decls :: { [RdrBinding] } -- Reversed
476 : decls ';' decl { $3 : $1 }
482 decllist :: { [RdrBinding] } -- Reversed
483 : '{' decls '}' { $2 }
484 | layout_on decls close { $2 }
486 where :: { [RdrBinding] } -- Reversed
487 -- No implicit parameters
488 : 'where' decllist { $2 }
491 binds :: { RdrNameHsBinds } -- May have implicit parameters
492 : decllist { cvBinds $1 }
493 | '{' dbinds '}' { IPBinds $2 False{-not with-} }
494 | layout_on dbinds close { IPBinds $2 False{-not with-} }
496 wherebinds :: { RdrNameHsBinds } -- May have implicit parameters
497 : 'where' binds { $2 }
498 | {- empty -} { EmptyBinds }
502 -----------------------------------------------------------------------------
503 -- Transformation Rules
505 rules :: { [RdrBinding] } -- Reversed
506 : rules ';' rule { $3 : $1 }
511 rule :: { RdrBinding }
512 : STRING activation rule_forall infixexp '=' srcloc exp
513 { RdrHsDecl (RuleD (HsRule $1 $2 $3 $4 $7 $6)) }
515 activation :: { Activation } -- Omitted means AlwaysActive
516 : {- empty -} { AlwaysActive }
517 | explicit_activation { $1 }
519 inverse_activation :: { Activation } -- Omitted means NeverActive
520 : {- empty -} { NeverActive }
521 | explicit_activation { $1 }
523 explicit_activation :: { Activation } -- In brackets
524 : '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
525 | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
527 rule_forall :: { [RdrNameRuleBndr] }
528 : 'forall' rule_var_list '.' { $2 }
531 rule_var_list :: { [RdrNameRuleBndr] }
533 | rule_var rule_var_list { $1 : $2 }
535 rule_var :: { RdrNameRuleBndr }
536 : varid { RuleBndr $1 }
537 | '(' varid '::' ctype ')' { RuleBndrSig $2 $4 }
539 -----------------------------------------------------------------------------
540 -- Deprecations (c.f. rules)
542 deprecations :: { [RdrBinding] } -- Reversed
543 : deprecations ';' deprecation { $3 : $1 }
544 | deprecations ';' { $1 }
545 | deprecation { [$1] }
548 -- SUP: TEMPORARY HACK, not checking for `module Foo'
549 deprecation :: { RdrBinding }
550 : srcloc depreclist STRING
552 [ RdrHsDecl (DeprecD (Deprecation n $3 $1)) | n <- $2 ] }
555 -----------------------------------------------------------------------------
556 -- Foreign import and export declarations
558 -- for the time being, the following accepts foreign declarations conforming
559 -- to the FFI Addendum, Version 1.0 as well as pre-standard declarations
561 -- * a flag indicates whether pre-standard declarations have been used and
562 -- triggers a deprecation warning further down the road
564 -- NB: The first two rules could be combined into one by replacing `safety1'
565 -- with `safety'. However, the combined rule conflicts with the
568 fdecl :: { RdrNameHsDecl }
569 fdecl : srcloc 'import' callconv safety1 fspec {% mkImport $3 $4 $5 $1 }
570 | srcloc 'import' callconv fspec {% mkImport $3 (PlaySafe False) $4 $1 }
571 | srcloc 'export' callconv fspec {% mkExport $3 $4 $1 }
572 -- the following syntax is DEPRECATED
573 | srcloc fdecl1DEPRECATED { ForD ($2 True $1) }
574 | srcloc fdecl2DEPRECATED { $2 $1 }
576 fdecl1DEPRECATED :: { Bool -> SrcLoc -> ForeignDecl RdrName }
578 ----------- DEPRECATED label decls ------------
579 : 'label' ext_name varid '::' sigtype
580 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
581 (CLabel ($2 `orElse` mkExtName $3))) }
583 ----------- DEPRECATED ccall/stdcall decls ------------
585 -- NB: This business with the case expression below may seem overly
586 -- complicated, but it is necessary to avoid some conflicts.
588 -- DEPRECATED variant #1: lack of a calling convention specification
590 | 'import' {-no callconv-} ext_name safety varid_no_unsafe '::' sigtype
592 target = StaticTarget ($2 `orElse` mkExtName $4)
594 ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
595 (CFunction target)) }
597 -- DEPRECATED variant #2: external name consists of two separate strings
598 -- (module name and function name) (import)
599 | 'import' callconv STRING STRING safety varid_no_unsafe '::' sigtype
601 DNCall -> parseError "Illegal format of .NET foreign import"
602 CCall cconv -> returnP $
604 imp = CFunction (StaticTarget $4)
606 ForeignImport $6 $8 (CImport cconv $5 nilFS nilFS imp) }
608 -- DEPRECATED variant #3: `unsafe' after entity
609 | 'import' callconv STRING 'unsafe' varid_no_unsafe '::' sigtype
611 DNCall -> parseError "Illegal format of .NET foreign import"
612 CCall cconv -> returnP $
614 imp = CFunction (StaticTarget $3)
616 ForeignImport $5 $7 (CImport cconv PlayRisky nilFS nilFS imp) }
618 -- DEPRECATED variant #4: use of the special identifier `dynamic' without
619 -- an explicit calling convention (import)
620 | 'import' {-no callconv-} 'dynamic' safety varid_no_unsafe '::' sigtype
621 { ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
622 (CFunction DynamicTarget)) }
624 -- DEPRECATED variant #5: use of the special identifier `dynamic' (import)
625 | 'import' callconv 'dynamic' safety varid_no_unsafe '::' sigtype
627 DNCall -> parseError "Illegal format of .NET foreign import"
628 CCall cconv -> returnP $
629 ForeignImport $5 $7 (CImport cconv $4 nilFS nilFS
630 (CFunction DynamicTarget)) }
632 -- DEPRECATED variant #6: lack of a calling convention specification
634 | 'export' {-no callconv-} ext_name varid '::' sigtype
635 { ForeignExport $3 $5 (CExport (CExportStatic ($2 `orElse` mkExtName $3)
638 -- DEPRECATED variant #7: external name consists of two separate strings
639 -- (module name and function name) (export)
640 | 'export' callconv STRING STRING varid '::' sigtype
642 DNCall -> parseError "Illegal format of .NET foreign import"
643 CCall cconv -> returnP $
645 (CExport (CExportStatic $4 cconv)) }
647 -- DEPRECATED variant #8: use of the special identifier `dynamic' without
648 -- an explicit calling convention (export)
649 | 'export' {-no callconv-} 'dynamic' varid '::' sigtype
650 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
653 -- DEPRECATED variant #9: use of the special identifier `dynamic' (export)
654 | 'export' callconv 'dynamic' varid '::' sigtype
656 DNCall -> parseError "Illegal format of .NET foreign import"
657 CCall cconv -> returnP $
658 ForeignImport $4 $6 (CImport cconv (PlaySafe False) nilFS nilFS CWrapper) }
660 ----------- DEPRECATED .NET decls ------------
661 -- NB: removed the .NET call declaration, as it is entirely subsumed
662 -- by the new standard FFI declarations
664 fdecl2DEPRECATED :: { SrcLoc -> RdrNameHsDecl }
666 : 'import' 'dotnet' 'type' ext_name tycon
667 { \loc -> TyClD (ForeignType $5 $4 DNType loc) }
668 -- left this one unchanged for the moment as type imports are not
669 -- covered currently by the FFI standard -=chak
672 callconv :: { CallConv }
673 : 'stdcall' { CCall StdCallConv }
674 | 'ccall' { CCall CCallConv }
675 | 'dotnet' { DNCall }
678 : 'unsafe' { PlayRisky }
679 | 'safe' { PlaySafe False }
680 | 'threadsafe' { PlaySafe True }
681 | {- empty -} { PlaySafe False }
683 safety1 :: { Safety }
684 : 'unsafe' { PlayRisky }
685 | 'safe' { PlaySafe False }
686 | 'threadsafe' { PlaySafe True }
687 -- only needed to avoid conflicts with the DEPRECATED rules
689 fspec :: { (FastString, RdrName, RdrNameHsType) }
690 : STRING var '::' sigtype { ($1 , $2, $4) }
691 | var '::' sigtype { (nilFS, $1, $3) }
692 -- if the entity string is missing, it defaults to the empty string;
693 -- the meaning of an empty entity string depends on the calling
697 ext_name :: { Maybe CLabelString }
699 | STRING STRING { Just $2 } -- Ignore "module name" for now
700 | {- empty -} { Nothing }
703 -----------------------------------------------------------------------------
706 opt_sig :: { Maybe RdrNameHsType }
707 : {- empty -} { Nothing }
708 | '::' sigtype { Just $2 }
710 opt_asig :: { Maybe RdrNameHsType }
711 : {- empty -} { Nothing }
712 | '::' atype { Just $2 }
714 sigtypes :: { [RdrNameHsType] }
716 | sigtypes ',' sigtype { $3 : $1 }
718 sigtype :: { RdrNameHsType }
719 : ctype { mkHsForAllTy Nothing [] $1 }
721 sig_vars :: { [RdrName] }
722 : sig_vars ',' var { $3 : $1 }
725 -----------------------------------------------------------------------------
728 -- A ctype is a for-all type
729 ctype :: { RdrNameHsType }
730 : 'forall' tv_bndrs '.' ctype { mkHsForAllTy (Just $2) [] $4 }
731 | context '=>' type { mkHsForAllTy Nothing $1 $3 }
732 -- A type of form (context => type) is an *implicit* HsForAllTy
735 -- We parse a context as a btype so that we don't get reduce/reduce
736 -- errors in ctype. The basic problem is that
738 -- looks so much like a tuple type. We can't tell until we find the =>
739 context :: { RdrNameContext }
740 : btype {% checkContext $1 }
742 type :: { RdrNameHsType }
743 : ipvar '::' gentype { mkHsIParamTy $1 $3 }
746 gentype :: { RdrNameHsType }
748 | btype qtyconop gentype { HsOpTy $1 (HsTyOp $2) $3 }
749 | btype '`' tyvar '`' gentype { HsOpTy $1 (HsTyOp $3) $5 }
750 | btype '->' gentype { HsOpTy $1 HsArrow $3 }
752 btype :: { RdrNameHsType }
753 : btype atype { HsAppTy $1 $2 }
756 atype :: { RdrNameHsType }
757 : gtycon { HsTyVar $1 }
758 | tyvar { HsTyVar $1 }
759 | '(' type ',' comma_types1 ')' { HsTupleTy (mkHsTupCon tcName Boxed ($2:$4)) ($2:$4) }
760 | '(#' comma_types1 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
761 | '[' type ']' { HsListTy $2 }
762 | '[:' type ':]' { HsPArrTy $2 }
763 | '(' ctype ')' { HsParTy $2 }
764 | '(' ctype '::' kind ')' { HsKindSig $2 $4 }
766 | INTEGER { HsNumTy $1 }
768 -- An inst_type is what occurs in the head of an instance decl
769 -- e.g. (Foo a, Gaz b) => Wibble a b
770 -- It's kept as a single type, with a MonoDictTy at the right
771 -- hand corner, for convenience.
772 inst_type :: { RdrNameHsType }
773 : ctype {% checkInstType $1 }
775 comma_types0 :: { [RdrNameHsType] }
776 : comma_types1 { $1 }
779 comma_types1 :: { [RdrNameHsType] }
781 | type ',' comma_types1 { $1 : $3 }
783 tv_bndrs :: { [RdrNameHsTyVar] }
784 : tv_bndr tv_bndrs { $1 : $2 }
787 tv_bndr :: { RdrNameHsTyVar }
788 : tyvar { UserTyVar $1 }
789 | '(' tyvar '::' kind ')' { IfaceTyVar $2 $4 }
791 fds :: { [([RdrName], [RdrName])] }
793 | '|' fds1 { reverse $2 }
795 fds1 :: { [([RdrName], [RdrName])] }
796 : fds1 ',' fd { $3 : $1 }
799 fd :: { ([RdrName], [RdrName]) }
800 : varids0 '->' varids0 { (reverse $1, reverse $3) }
802 varids0 :: { [RdrName] }
804 | varids0 tyvar { $2 : $1 }
806 -----------------------------------------------------------------------------
811 | akind '->' kind { mkArrowKind $1 $3 }
814 : '*' { liftedTypeKind }
815 | '(' kind ')' { $2 }
818 -----------------------------------------------------------------------------
819 -- Datatype declarations
821 newconstr :: { RdrNameConDecl }
822 : srcloc conid atype { ConDecl $2 [] [] (PrefixCon [unbangedType $3]) $1 }
823 | srcloc conid '{' var '::' ctype '}'
824 { ConDecl $2 [] [] (RecCon [($4, unbangedType $6)]) $1 }
826 constrs :: { [RdrNameConDecl] }
827 : {- empty; a GHC extension -} { [] }
828 | '=' constrs1 { $2 }
830 constrs1 :: { [RdrNameConDecl] }
831 : constrs1 '|' constr { $3 : $1 }
834 constr :: { RdrNameConDecl }
835 : srcloc forall context '=>' constr_stuff
836 { ConDecl (fst $5) $2 $3 (snd $5) $1 }
837 | srcloc forall constr_stuff
838 { ConDecl (fst $3) $2 [] (snd $3) $1 }
840 forall :: { [RdrNameHsTyVar] }
841 : 'forall' tv_bndrs '.' { $2 }
844 constr_stuff :: { (RdrName, RdrNameConDetails) }
845 : btype {% mkPrefixCon $1 [] }
846 | btype '!' atype satypes {% mkPrefixCon $1 (BangType MarkedUserStrict $3 : $4) }
847 | oqtycon '{' '}' {% mkRecCon $1 [] }
848 | oqtycon '{' fielddecls '}' {% mkRecCon $1 $3 }
849 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
851 satypes :: { [RdrNameBangType] }
852 : atype satypes { unbangedType $1 : $2 }
853 | '!' atype satypes { BangType MarkedUserStrict $2 : $3 }
856 sbtype :: { RdrNameBangType }
857 : btype { unbangedType $1 }
858 | '!' atype { BangType MarkedUserStrict $2 }
860 fielddecls :: { [([RdrName],RdrNameBangType)] }
861 : fielddecl ',' fielddecls { $1 : $3 }
864 fielddecl :: { ([RdrName],RdrNameBangType) }
865 : sig_vars '::' stype { (reverse $1, $3) }
867 stype :: { RdrNameBangType }
868 : ctype { unbangedType $1 }
869 | '!' atype { BangType MarkedUserStrict $2 }
871 deriving :: { Maybe RdrNameContext }
872 : {- empty -} { Nothing }
873 | 'deriving' context { Just $2 }
874 -- Glasgow extension: allow partial
875 -- applications in derivings
877 -----------------------------------------------------------------------------
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.
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
892 { (^^) :: Int->Int ; } Type signature; only var allowed
894 { (^^) :: Int->Int = ... ; } Value defn with result signature;
895 qvar allowed (because of instance decls)
897 We can't tell whether to reduce var to qvar until after we've read the signatures.
900 decl :: { RdrBinding }
902 | infixexp srcloc opt_sig rhs {% checkValDef $1 $3 $4 $2 }
904 rhs :: { RdrNameGRHSs }
905 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2) $4 placeHolderType }
906 | gdrhs wherebinds { GRHSs (reverse $1) $2 placeHolderType }
908 gdrhs :: { [RdrNameGRHS] }
909 : gdrhs gdrh { $2 : $1 }
912 gdrh :: { RdrNameGRHS }
913 : '|' srcloc quals '=' exp { GRHS (reverse (ResultStmt $5 $2 : $3)) $2 }
915 sigdecl :: { RdrBinding }
916 : infixexp srcloc '::' sigtype
917 {% checkValSig $1 $4 $2 }
918 -- See the above notes for why we need infixexp here
919 | var ',' sig_vars srcloc '::' sigtype
920 { mkSigDecls [ Sig n $6 $4 | n <- $1:$3 ] }
921 | srcloc infix prec ops { mkSigDecls [ FixSig (FixitySig n (Fixity $3 $2) $1)
923 | '{-# INLINE' srcloc activation qvar '#-}'
924 { RdrHsDecl (SigD (InlineSig True $4 $3 $2)) }
925 | '{-# NOINLINE' srcloc inverse_activation qvar '#-}'
926 { RdrHsDecl (SigD (InlineSig False $4 $3 $2)) }
927 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
928 { mkSigDecls [ SpecSig $3 t $2 | t <- $5] }
929 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
930 { RdrHsDecl (SigD (SpecInstSig $4 $2)) }
932 -----------------------------------------------------------------------------
935 exp :: { RdrNameHsExpr }
936 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
937 | infixexp 'with' dbinding { HsLet (IPBinds $3 True{-not a let-}) $1 }
938 | fexp srcloc '-<' exp { HsArrApp $1 $4 placeHolderType HsFirstOrderApp True $2 }
939 | fexp srcloc '>-' exp { HsArrApp $4 $1 placeHolderType HsFirstOrderApp False $2 }
940 | fexp srcloc '-<<' exp { HsArrApp $1 $4 placeHolderType HsHigherOrderApp True $2 }
941 | fexp srcloc '>>-' exp { HsArrApp $4 $1 placeHolderType HsHigherOrderApp False $2 }
944 infixexp :: { RdrNameHsExpr }
946 | infixexp qop exp10 { (OpApp $1 (HsVar $2)
947 (panic "fixity") $3 )}
949 exp10 :: { RdrNameHsExpr }
950 : '\\' srcloc aexp aexps opt_asig '->' srcloc exp
951 {% checkPatterns $2 ($3 : reverse $4) `thenP` \ ps ->
952 returnP (HsLam (Match ps $5
953 (GRHSs (unguardedRHS $8 $7)
954 EmptyBinds placeHolderType))) }
955 | 'let' binds 'in' exp { HsLet $2 $4 }
956 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
957 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
958 | '-' fexp { mkHsNegApp $2 }
959 | srcloc 'do' stmtlist {% checkDo $3 `thenP` \ stmts ->
960 returnP (mkHsDo DoExpr stmts $1) }
961 | srcloc 'mdo' stmtlist {% checkMDo $3 `thenP` \ stmts ->
962 returnP (mkHsDo MDoExpr stmts $1) }
964 | '_ccall_' ccallid aexps0 { HsCCall $2 $3 PlayRisky False placeHolderType }
965 | '_ccall_GC_' ccallid aexps0 { HsCCall $2 $3 (PlaySafe False) False placeHolderType }
966 | '_casm_' CLITLIT aexps0 { HsCCall $2 $3 PlayRisky True placeHolderType }
967 | '_casm_GC_' CLITLIT aexps0 { HsCCall $2 $3 (PlaySafe False) True placeHolderType }
969 | scc_annot exp { if opt_SccProfilingOn
973 | 'proc' srcloc aexp '->' srcloc exp
974 {% checkPattern $2 $3 `thenP` \ p ->
975 returnP (HsProc p (HsCmdTop $6 [] placeHolderType undefined) $5) }
977 | '{-# CORE' STRING '#-}' exp { HsCoreAnn $2 $4 } -- hdaume: core annotation
979 | reifyexp { HsReify $1 }
982 scc_annot :: { FastString }
983 : '_scc_' STRING { $2 }
984 | '{-# SCC' STRING '#-}' { $2 }
986 ccallid :: { FastString }
990 fexp :: { RdrNameHsExpr }
991 : fexp aexp { (HsApp $1 $2) }
994 reifyexp :: { HsReify RdrName }
995 : REIFY_DECL gtycon { Reify ReifyDecl $2 }
996 | REIFY_DECL qvar { Reify ReifyDecl $2 }
997 | REIFY_TYPE qcname { Reify ReifyType $2 }
998 | REIFY_FIXITY qcname { Reify ReifyFixity $2 }
1000 aexps0 :: { [RdrNameHsExpr] }
1001 : aexps { reverse $1 }
1003 aexps :: { [RdrNameHsExpr] }
1004 : aexps aexp { $2 : $1 }
1005 | {- empty -} { [] }
1007 aexp :: { RdrNameHsExpr }
1008 : qvar '@' aexp { EAsPat $1 $3 }
1009 | '~' aexp { ELazyPat $2 }
1012 aexp1 :: { RdrNameHsExpr }
1013 : aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1 (reverse $3)) }
1016 -- Here was the syntax for type applications that I was planning
1017 -- but there are difficulties (e.g. what order for type args)
1018 -- so it's not enabled yet.
1019 | qcname '{|' gentype '|}' { (HsApp (HsVar $1) (HsType $3)) }
1021 aexp2 :: { RdrNameHsExpr }
1022 : ipvar { HsIPVar $1 }
1023 | qcname { HsVar $1 }
1024 | literal { HsLit $1 }
1025 | INTEGER { HsOverLit (mkHsIntegral $1) }
1026 | RATIONAL { HsOverLit (mkHsFractional $1) }
1027 | '(' exp ')' { HsPar $2 }
1028 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) Boxed}
1029 | '(#' texps '#)' { ExplicitTuple (reverse $2) Unboxed }
1030 | '[' list ']' { $2 }
1031 | '[:' parr ':]' { $2 }
1032 | '(' infixexp qop ')' { (SectionL $2 (HsVar $3)) }
1033 | '(' qopm infixexp ')' { (SectionR $2 $3) }
1036 -- MetaHaskell Extension
1037 | srcloc ID_SPLICE { mkHsSplice (HsVar (mkUnqual varName $2)) $1 } -- $x
1038 | srcloc '$(' exp ')' { mkHsSplice $3 $1 } -- $( exp )
1039 | srcloc '[|' exp '|]' { HsBracket (ExpBr $3) $1 }
1040 | srcloc '[t|' ctype '|]' { HsBracket (TypBr $3) $1 }
1041 | srcloc '[p|' infixexp '|]' {% checkPattern $1 $3 `thenP` \p ->
1042 returnP (HsBracket (PatBr p) $1) }
1043 | srcloc '[d|' cvtopbody '|]' { HsBracket (DecBr (mkGroup $3)) $1 }
1045 -- arrow notation extension
1046 | srcloc '(|' aexp2 cmdargs '|)'
1047 { HsArrForm $3 Nothing (reverse $4) $1 }
1049 cmdargs :: { [RdrNameHsCmdTop] }
1050 : cmdargs acmd { $2 : $1 }
1051 | {- empty -} { [] }
1053 acmd :: { RdrNameHsCmdTop }
1054 : aexp2 { HsCmdTop $1 [] placeHolderType undefined }
1056 cvtopbody :: { [RdrNameHsDecl] }
1057 : '{' cvtopdecls '}' { $2 }
1058 | layout_on cvtopdecls close { $2 }
1060 texps :: { [RdrNameHsExpr] }
1061 : texps ',' exp { $3 : $1 }
1065 -----------------------------------------------------------------------------
1068 -- The rules below are little bit contorted to keep lexps left-recursive while
1069 -- avoiding another shift/reduce-conflict.
1071 list :: { RdrNameHsExpr }
1072 : exp { ExplicitList placeHolderType [$1] }
1073 | lexps { ExplicitList placeHolderType (reverse $1) }
1074 | exp '..' { ArithSeqIn (From $1) }
1075 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
1076 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
1077 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
1078 | exp srcloc pquals { mkHsDo ListComp
1079 (reverse (ResultStmt $1 $2 : $3))
1083 lexps :: { [RdrNameHsExpr] }
1084 : lexps ',' exp { $3 : $1 }
1085 | exp ',' exp { [$3,$1] }
1087 -----------------------------------------------------------------------------
1088 -- List Comprehensions
1090 pquals :: { [RdrNameStmt] } -- Either a singleton ParStmt, or a reversed list of Stmts
1091 : pquals1 { case $1 of
1093 qss -> [ParStmt stmtss]
1095 stmtss = [ (reverse qs, undefined)
1099 pquals1 :: { [[RdrNameStmt]] }
1100 : pquals1 '|' quals { $3 : $1 }
1101 | '|' quals { [$2] }
1103 quals :: { [RdrNameStmt] }
1104 : quals ',' qual { $3 : $1 }
1107 -----------------------------------------------------------------------------
1108 -- Parallel array expressions
1110 -- The rules below are little bit contorted; see the list case for details.
1111 -- Note that, in contrast to lists, we only have finite arithmetic sequences.
1112 -- Moreover, we allow explicit arrays with no element (represented by the nil
1113 -- constructor in the list case).
1115 parr :: { RdrNameHsExpr }
1116 : { ExplicitPArr placeHolderType [] }
1117 | exp { ExplicitPArr placeHolderType [$1] }
1118 | lexps { ExplicitPArr placeHolderType
1120 | exp '..' exp { PArrSeqIn (FromTo $1 $3) }
1121 | exp ',' exp '..' exp { PArrSeqIn (FromThenTo $1 $3 $5) }
1122 | exp srcloc pquals { mkHsDo PArrComp
1123 (reverse (ResultStmt $1 $2 : $3))
1127 -- We are reusing `lexps' and `pquals' from the list case.
1129 -----------------------------------------------------------------------------
1130 -- Case alternatives
1132 altslist :: { [RdrNameMatch] }
1133 : '{' alts '}' { reverse $2 }
1134 | layout_on alts close { reverse $2 }
1136 alts :: { [RdrNameMatch] }
1140 alts1 :: { [RdrNameMatch] }
1141 : alts1 ';' alt { $3 : $1 }
1145 alt :: { RdrNameMatch }
1146 : srcloc infixexp opt_sig ralt wherebinds
1147 {% (checkPattern $1 $2 `thenP` \p ->
1148 returnP (Match [p] $3
1149 (GRHSs $4 $5 placeHolderType)) )}
1151 ralt :: { [RdrNameGRHS] }
1152 : '->' srcloc exp { [GRHS [ResultStmt $3 $2] $2] }
1153 | gdpats { reverse $1 }
1155 gdpats :: { [RdrNameGRHS] }
1156 : gdpats gdpat { $2 : $1 }
1159 gdpat :: { RdrNameGRHS }
1160 : srcloc '|' quals '->' exp { GRHS (reverse (ResultStmt $5 $1:$3)) $1}
1162 -----------------------------------------------------------------------------
1163 -- Statement sequences
1165 stmtlist :: { [RdrNameStmt] }
1166 : '{' stmts '}' { $2 }
1167 | layout_on_for_do stmts close { $2 }
1169 -- do { ;; s ; s ; ; s ;; }
1170 -- The last Stmt should be a ResultStmt, but that's hard to enforce
1171 -- here, because we need too much lookahead if we see do { e ; }
1172 -- So we use ExprStmts throughout, and switch the last one over
1173 -- in ParseUtils.checkDo instead
1174 stmts :: { [RdrNameStmt] }
1175 : stmt stmts_help { $1 : $2 }
1177 | {- empty -} { [] }
1179 stmts_help :: { [RdrNameStmt] }
1181 | {- empty -} { [] }
1183 -- For typing stmts at the GHCi prompt, where
1184 -- the input may consist of just comments.
1185 maybe_stmt :: { Maybe RdrNameStmt }
1187 | {- nothing -} { Nothing }
1189 stmt :: { RdrNameStmt }
1191 | srcloc infixexp '->' exp {% checkPattern $1 $4 `thenP` \p ->
1192 returnP (BindStmt p $2 $1) }
1193 | srcloc 'rec' stmtlist { RecStmt $3 undefined undefined undefined }
1195 qual :: { RdrNameStmt }
1196 : srcloc infixexp '<-' exp {% checkPattern $1 $2 `thenP` \p ->
1197 returnP (BindStmt p $4 $1) }
1198 | srcloc exp { ExprStmt $2 placeHolderType $1 }
1199 | srcloc 'let' binds { LetStmt $3 }
1201 -----------------------------------------------------------------------------
1202 -- Record Field Update/Construction
1204 fbinds :: { RdrNameHsRecordBinds }
1205 : fbinds ',' fbind { $3 : $1 }
1208 | {- empty -} { [] }
1210 fbind :: { (RdrName, RdrNameHsExpr) }
1211 : qvar '=' exp { ($1,$3) }
1213 -----------------------------------------------------------------------------
1214 -- Implicit Parameter Bindings
1216 dbinding :: { [(IPName RdrName, RdrNameHsExpr)] }
1217 : '{' dbinds '}' { $2 }
1218 | layout_on dbinds close { $2 }
1220 dbinds :: { [(IPName RdrName, RdrNameHsExpr)] }
1221 : dbinds ';' dbind { $3 : $1 }
1224 -- | {- empty -} { [] }
1226 dbind :: { (IPName RdrName, RdrNameHsExpr) }
1227 dbind : ipvar '=' exp { ($1, $3) }
1229 -----------------------------------------------------------------------------
1230 -- Variables, Constructors and Operators.
1232 identifier :: { RdrName }
1237 depreclist :: { [RdrName] }
1238 depreclist : deprec_var { [$1] }
1239 | deprec_var ',' depreclist { $1 : $3 }
1241 deprec_var :: { RdrName }
1242 deprec_var : var { $1 }
1245 gcon :: { RdrName } -- Data constructor namespace
1246 : sysdcon { nameRdrName (dataConName $1) }
1248 -- the case of '[:' ':]' is part of the production `parr'
1250 sysdcon :: { DataCon } -- Wired in data constructors
1251 : '(' ')' { unitDataCon }
1252 | '(' commas ')' { tupleCon Boxed $2 }
1253 | '[' ']' { nilDataCon }
1257 | '(' varsym ')' { $2 }
1261 | '(' varsym ')' { $2 }
1262 | '(' qvarsym1 ')' { $2 }
1263 -- We've inlined qvarsym here so that the decision about
1264 -- whether it's a qvar or a var can be postponed until
1265 -- *after* we see the close paren.
1267 ipvar :: { IPName RdrName }
1268 : IPDUPVARID { Dupable (mkUnqual varName $1) }
1269 | IPSPLITVARID { Linear (mkUnqual varName $1) }
1273 | '(' qconsym ')' { $2 }
1275 varop :: { RdrName }
1277 | '`' varid '`' { $2 }
1279 qvarop :: { RdrName }
1281 | '`' qvarid '`' { $2 }
1283 qvaropm :: { RdrName }
1284 : qvarsym_no_minus { $1 }
1285 | '`' qvarid '`' { $2 }
1287 conop :: { RdrName }
1289 | '`' conid '`' { $2 }
1291 qconop :: { RdrName }
1293 | '`' qconid '`' { $2 }
1295 -----------------------------------------------------------------------------
1296 -- Type constructors
1298 gtycon :: { RdrName } -- A "general" qualified tycon
1300 | '(' ')' { getRdrName unitTyCon }
1301 | '(' commas ')' { getRdrName (tupleTyCon Boxed $2) }
1302 | '(' '->' ')' { nameRdrName funTyConName }
1303 | '[' ']' { nameRdrName listTyConName }
1304 | '[:' ':]' { nameRdrName parrTyConName }
1306 oqtycon :: { RdrName } -- An "ordinary" qualified tycon
1308 | '(' qtyconsym ')' { $2 }
1310 qtyconop :: { RdrName } -- Qualified or unqualified
1312 | '`' qtycon '`' { $2 }
1314 tyconop :: { RdrName } -- Unqualified
1316 | '`' tycon '`' { $2 }
1318 qtycon :: { RdrName } -- Qualified or unqualified
1319 : QCONID { mkQual tcClsName $1 }
1322 tycon :: { RdrName } -- Unqualified
1323 : CONID { mkUnqual tcClsName $1 }
1325 qtyconsym :: { RdrName }
1326 : QCONSYM { mkQual tcClsName $1 }
1329 tyconsym :: { RdrName }
1330 : CONSYM { mkUnqual tcClsName $1 }
1332 -----------------------------------------------------------------------------
1335 op :: { RdrName } -- used in infix decls
1339 qop :: { RdrName {-HsExpr-} } -- used in sections
1343 qopm :: { RdrNameHsExpr } -- used in sections
1344 : qvaropm { HsVar $1 }
1345 | qconop { HsVar $1 }
1347 -----------------------------------------------------------------------------
1350 qvarid :: { RdrName }
1352 | QVARID { mkQual varName $1 }
1354 varid :: { RdrName }
1355 : varid_no_unsafe { $1 }
1356 | 'unsafe' { mkUnqual varName FSLIT("unsafe") }
1357 | 'safe' { mkUnqual varName FSLIT("safe") }
1358 | 'threadsafe' { mkUnqual varName FSLIT("threadsafe") }
1360 varid_no_unsafe :: { RdrName }
1361 : VARID { mkUnqual varName $1 }
1362 | special_id { mkUnqual varName $1 }
1363 | 'forall' { mkUnqual varName FSLIT("forall") }
1365 tyvar :: { RdrName }
1366 : VARID { mkUnqual tvName $1 }
1367 | special_id { mkUnqual tvName $1 }
1368 | 'unsafe' { mkUnqual tvName FSLIT("unsafe") }
1369 | 'safe' { mkUnqual tvName FSLIT("safe") }
1370 | 'threadsafe' { mkUnqual tvName FSLIT("threadsafe") }
1372 -- These special_ids are treated as keywords in various places,
1373 -- but as ordinary ids elsewhere. 'special_id' collects all these
1374 -- except 'unsafe' and 'forall' whose treatment differs depending on context
1375 special_id :: { UserFS }
1377 : 'as' { FSLIT("as") }
1378 | 'qualified' { FSLIT("qualified") }
1379 | 'hiding' { FSLIT("hiding") }
1380 | 'export' { FSLIT("export") }
1381 | 'label' { FSLIT("label") }
1382 | 'dynamic' { FSLIT("dynamic") }
1383 | 'stdcall' { FSLIT("stdcall") }
1384 | 'ccall' { FSLIT("ccall") }
1386 -----------------------------------------------------------------------------
1389 qvarsym :: { RdrName }
1393 qvarsym_no_minus :: { RdrName }
1394 : varsym_no_minus { $1 }
1397 qvarsym1 :: { RdrName }
1398 qvarsym1 : QVARSYM { mkQual varName $1 }
1400 varsym :: { RdrName }
1401 : varsym_no_minus { $1 }
1402 | '-' { mkUnqual varName FSLIT("-") }
1404 varsym_no_minus :: { RdrName } -- varsym not including '-'
1405 : VARSYM { mkUnqual varName $1 }
1406 | special_sym { mkUnqual varName $1 }
1409 -- See comments with special_id
1410 special_sym :: { UserFS }
1411 special_sym : '!' { FSLIT("!") }
1412 | '.' { FSLIT(".") }
1413 | '*' { FSLIT("*") }
1415 -----------------------------------------------------------------------------
1416 -- Data constructors
1418 qconid :: { RdrName } -- Qualified or unqualifiedb
1420 | QCONID { mkQual dataName $1 }
1422 conid :: { RdrName }
1423 : CONID { mkUnqual dataName $1 }
1425 qconsym :: { RdrName } -- Qualified or unqualified
1427 | QCONSYM { mkQual dataName $1 }
1429 consym :: { RdrName }
1430 : CONSYM { mkUnqual dataName $1 }
1432 -- ':' means only list cons
1433 | ':' { nameRdrName consDataConName }
1434 -- NB: SrcName because we are reading source
1437 -----------------------------------------------------------------------------
1440 literal :: { HsLit }
1441 : CHAR { HsChar $1 }
1442 | STRING { HsString $1 }
1443 | PRIMINTEGER { HsIntPrim $1 }
1444 | PRIMCHAR { HsCharPrim $1 }
1445 | PRIMSTRING { HsStringPrim $1 }
1446 | PRIMFLOAT { HsFloatPrim $1 }
1447 | PRIMDOUBLE { HsDoublePrim $1 }
1448 | CLITLIT { HsLitLit $1 placeHolderType }
1450 srcloc :: { SrcLoc } : {% getSrcLocP }
1452 -----------------------------------------------------------------------------
1456 : vccurly { () } -- context popped in lexer.
1457 | error {% popContext }
1459 layout_on :: { () } : {% layoutOn True{-strict-} }
1460 layout_on_for_do :: { () } : {% layoutOn False }
1462 -----------------------------------------------------------------------------
1463 -- Miscellaneous (mostly renamings)
1465 modid :: { ModuleName }
1466 : CONID { mkModuleNameFS $1 }
1467 | QCONID { mkModuleNameFS
1469 (unpackFS (fst $1) ++
1470 '.':unpackFS (snd $1)))
1474 : commas ',' { $1 + 1 }
1477 -----------------------------------------------------------------------------
1481 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)