2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.115 2003/02/12 15:01:37 simonpj 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 '_ccall_' { ITccall (False, False, PlayRisky) }
134 '_ccall_GC_' { ITccall (False, False, PlaySafe False) }
135 '_casm_' { ITccall (False, True, PlayRisky) }
136 '_casm_GC_' { ITccall (False, True, PlaySafe False) }
138 '{-# SPECIALISE' { ITspecialise_prag }
139 '{-# SOURCE' { ITsource_prag }
140 '{-# INLINE' { ITinline_prag }
141 '{-# NOINLINE' { ITnoinline_prag }
142 '{-# RULES' { ITrules_prag }
143 '{-# SCC' { ITscc_prag }
144 '{-# DEPRECATED' { ITdeprecated_prag }
145 '#-}' { ITclose_prag }
148 '__interface' { ITinterface } -- interface keywords
149 '__export' { IT__export }
150 '__instimport' { ITinstimport }
151 '__forall' { IT__forall }
152 '__letrec' { ITletrec }
153 '__coerce' { ITcoerce }
154 '__depends' { ITdepends }
155 '__inline' { ITinline }
156 '__DEFAULT' { ITdefaultbranch }
158 '__integer' { ITinteger_lit }
159 '__float' { ITfloat_lit }
160 '__rational' { ITrational_lit }
161 '__addr' { ITaddr_lit }
162 '__label' { ITlabel_lit }
163 '__litlit' { ITlit_lit }
164 '__string' { ITstring_lit }
165 '__ccall' { ITccall $$ }
167 '__sccC' { ITsccAllCafs }
170 '__P' { ITspecialise }
173 '__S' { ITstrict $$ }
174 '__M' { ITcprinfo $$ }
177 '..' { ITdotdot } -- reserved symbols
193 '{' { ITocurly } -- special symbols
197 vccurly { ITvccurly } -- virtual close curly (from layout)
210 VARID { ITvarid $$ } -- identifiers
212 VARSYM { ITvarsym $$ }
213 CONSYM { ITconsym $$ }
214 QVARID { ITqvarid $$ }
215 QCONID { ITqconid $$ }
216 QVARSYM { ITqvarsym $$ }
217 QCONSYM { ITqconsym $$ }
219 IPDUPVARID { ITdupipvarid $$ } -- GHC extension
220 IPSPLITVARID { ITsplitipvarid $$ } -- GHC extension
223 STRING { ITstring $$ }
224 INTEGER { ITinteger $$ }
225 RATIONAL { ITrational $$ }
227 PRIMCHAR { ITprimchar $$ }
228 PRIMSTRING { ITprimstring $$ }
229 PRIMINTEGER { ITprimint $$ }
230 PRIMFLOAT { ITprimfloat $$ }
231 PRIMDOUBLE { ITprimdouble $$ }
232 CLITLIT { ITlitlit $$ }
235 '[|' { ITopenExpQuote }
236 '[p|' { ITopenPatQuote }
237 '[t|' { ITopenTypQuote }
238 '[d|' { ITopenDecQuote }
239 '|]' { ITcloseQuote }
240 ID_SPLICE { ITidEscape $$ } -- $x
241 '$(' { ITparenEscape } -- $( exp )
242 REIFY_TYPE { ITreifyType }
243 REIFY_DECL { ITreifyDecl }
244 REIFY_FIXITY { ITreifyFixity }
246 %monad { P } { thenP } { returnP }
247 %lexer { lexer } { ITeof }
248 %name parseModule module
249 %name parseStmt maybe_stmt
250 %name parseIdentifier identifier
251 %name parseIface iface
255 -----------------------------------------------------------------------------
258 -- The place for module deprecation is really too restrictive, but if it
259 -- was allowed at its natural place just before 'module', we get an ugly
260 -- s/r conflict with the second alternative. Another solution would be the
261 -- introduction of a new pragma DEPRECATED_MODULE, but this is not very nice,
262 -- either, and DEPRECATED is only expected to be used by people who really
263 -- know what they are doing. :-)
265 module :: { RdrNameHsModule }
266 : srcloc 'module' modid maybemoddeprec maybeexports 'where' body
267 { HsModule (mkHomeModule $3) Nothing $5 (fst $7) (snd $7) $4 $1 }
269 { HsModule (mkHomeModule mAIN_Name) Nothing Nothing
270 (fst $2) (snd $2) Nothing $1 }
272 maybemoddeprec :: { Maybe DeprecTxt }
273 : '{-# DEPRECATED' STRING '#-}' { Just $2 }
274 | {- empty -} { Nothing }
276 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
278 | layout_on top close { $2 }
280 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
281 : importdecls { (reverse $1,[]) }
282 | importdecls ';' cvtopdecls { (reverse $1,$3) }
283 | cvtopdecls { ([],$1) }
285 cvtopdecls :: { [RdrNameHsDecl] }
286 : topdecls { cvTopDecls $1 }
288 -----------------------------------------------------------------------------
289 -- Interfaces (.hi-boot files)
291 iface :: { ParsedIface }
292 : 'module' modid 'where' ifacebody
295 pi_pkg = opt_InPackage,
296 pi_vers = 1, -- Module version
298 pi_exports = (1,[($2,mkIfaceExports $4)]),
299 pi_deps = noDependencies,
303 pi_decls = map (\x -> (1,x)) $4,
309 ifacebody :: { [RdrNameTyClDecl] }
310 : '{' ifacedecls '}' { $2 }
311 | layout_on ifacedecls close { $2 }
313 ifacedecls :: { [RdrNameTyClDecl] }
314 : ifacedecl ';' ifacedecls { $1 : $3 }
315 | ';' ifacedecls { $2 }
319 ifacedecl :: { RdrNameTyClDecl }
321 | srcloc var '::' sigtype { IfaceSig $2 $4 [] $1 }
323 -----------------------------------------------------------------------------
326 maybeexports :: { Maybe [RdrNameIE] }
327 : '(' exportlist ')' { Just $2 }
328 | {- empty -} { Nothing }
330 exportlist :: { [RdrNameIE] }
331 : exportlist ',' export { $3 : $1 }
332 | exportlist ',' { $1 }
336 -- No longer allow things like [] and (,,,) to be exported
337 -- They are built in syntax, always available
338 export :: { RdrNameIE }
340 | oqtycon { IEThingAbs $1 }
341 | oqtycon '(' '..' ')' { IEThingAll $1 }
342 | oqtycon '(' ')' { IEThingWith $1 [] }
343 | oqtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
344 | 'module' modid { IEModuleContents $2 }
346 qcnames :: { [RdrName] }
347 : qcnames ',' qcname { $3 : $1 }
350 qcname :: { RdrName } -- Variable or data constructor
354 -----------------------------------------------------------------------------
355 -- Import Declarations
357 -- import decls can be *empty*, or even just a string of semicolons
358 -- whereas topdecls must contain at least one topdecl.
360 importdecls :: { [RdrNameImportDecl] }
361 : importdecls ';' importdecl { $3 : $1 }
362 | importdecls ';' { $1 }
363 | importdecl { [ $1 ] }
366 importdecl :: { RdrNameImportDecl }
367 : 'import' srcloc maybe_src optqualified modid maybeas maybeimpspec
368 { ImportDecl $5 $3 $4 $6 $7 $2 }
370 maybe_src :: { IsBootInterface }
371 : '{-# SOURCE' '#-}' { True }
372 | {- empty -} { False }
374 optqualified :: { Bool }
375 : 'qualified' { True }
376 | {- empty -} { False }
378 maybeas :: { Maybe ModuleName }
379 : 'as' modid { Just $2 }
380 | {- empty -} { Nothing }
382 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
383 : impspec { Just $1 }
384 | {- empty -} { Nothing }
386 impspec :: { (Bool, [RdrNameIE]) }
387 : '(' exportlist ')' { (False, reverse $2) }
388 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
390 -----------------------------------------------------------------------------
391 -- Fixity Declarations
395 | INTEGER {% checkPrecP (fromInteger $1) }
397 infix :: { FixityDirection }
399 | 'infixl' { InfixL }
400 | 'infixr' { InfixR }
403 : ops ',' op { $3 : $1 }
406 -----------------------------------------------------------------------------
407 -- Top-Level Declarations
409 topdecls :: { [RdrBinding] } -- Reversed
410 : topdecls ';' topdecl { $3 : $1 }
411 | topdecls ';' { $1 }
414 topdecl :: { RdrBinding }
415 : tycl_decl { RdrHsDecl (TyClD $1) }
416 | srcloc 'instance' inst_type where
417 { let (binds,sigs) = cvMonoBindsAndSigs $4
418 in RdrHsDecl (InstD (InstDecl $3 binds sigs Nothing $1)) }
419 | srcloc 'default' '(' comma_types0 ')' { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
420 | 'foreign' fdecl { RdrHsDecl $2 }
421 | '{-# DEPRECATED' deprecations '#-}' { RdrBindings (reverse $2) }
422 | '{-# RULES' rules '#-}' { RdrBindings (reverse $2) }
423 | srcloc '$(' exp ')' { RdrHsDecl (SpliceD (SpliceDecl $3 $1)) }
426 tycl_decl :: { RdrNameTyClDecl }
427 : srcloc 'type' syn_hdr '=' ctype
428 -- Note ctype, not sigtype.
429 -- We allow an explicit for-all but we don't insert one
430 -- in type Foo a = (b,b)
431 -- Instead we just say b is out of scope
432 { let (tc,tvs) = $3 in TySynonym tc tvs $5 $1 }
435 | srcloc 'data' tycl_hdr constrs deriving
436 { mkTyData DataType $3 (DataCons (reverse $4)) $5 $1 }
438 | srcloc 'newtype' tycl_hdr '=' newconstr deriving
439 { mkTyData NewType $3 (DataCons [$5]) $6 $1 }
441 | srcloc 'class' tycl_hdr fds where
443 (binds,sigs) = cvMonoBindsAndSigs $5
445 mkClassDecl $3 $4 (map cvClassOpSig sigs) (Just binds) $1 }
447 syn_hdr :: { (RdrName, [RdrNameHsTyVar]) } -- We don't retain the syntax of an infix
448 -- type synonym declaration. Oh well.
449 : tycon tv_bndrs { ($1, $2) }
450 | tv_bndr tyconop tv_bndr { ($2, [$1,$3]) }
452 -- tycl_hdr parses the header of a type or class decl,
453 -- which takes the form
456 -- (Eq a, Ord b) => T a b
457 -- Rather a lot of inlining here, else we get reduce/reduce errors
458 tycl_hdr :: { (RdrNameContext, RdrName, [RdrNameHsTyVar]) }
459 : context '=>' type {% checkTyClHdr $3 `thenP` \ (tc,tvs) ->
460 returnP ($1, tc, tvs) }
461 | type {% checkTyClHdr $1 `thenP` \ (tc,tvs) ->
462 returnP ([], tc, tvs) }
464 -----------------------------------------------------------------------------
465 -- Nested declarations
467 decls :: { [RdrBinding] } -- Reversed
468 : decls ';' decl { $3 : $1 }
474 decllist :: { [RdrBinding] } -- Reversed
475 : '{' decls '}' { $2 }
476 | layout_on decls close { $2 }
478 where :: { [RdrBinding] } -- Reversed
479 -- No implicit parameters
480 : 'where' decllist { $2 }
483 binds :: { RdrNameHsBinds } -- May have implicit parameters
484 : decllist { cvBinds $1 }
485 | '{' dbinds '}' { IPBinds $2 False{-not with-} }
486 | layout_on dbinds close { IPBinds $2 False{-not with-} }
488 wherebinds :: { RdrNameHsBinds } -- May have implicit parameters
489 : 'where' binds { $2 }
490 | {- empty -} { EmptyBinds }
494 -----------------------------------------------------------------------------
495 -- Transformation Rules
497 rules :: { [RdrBinding] } -- Reversed
498 : rules ';' rule { $3 : $1 }
503 rule :: { RdrBinding }
504 : STRING activation rule_forall infixexp '=' srcloc exp
505 { RdrHsDecl (RuleD (HsRule $1 $2 $3 $4 $7 $6)) }
507 activation :: { Activation } -- Omitted means AlwaysActive
508 : {- empty -} { AlwaysActive }
509 | explicit_activation { $1 }
511 inverse_activation :: { Activation } -- Omitted means NeverActive
512 : {- empty -} { NeverActive }
513 | explicit_activation { $1 }
515 explicit_activation :: { Activation } -- In brackets
516 : '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
517 | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
519 rule_forall :: { [RdrNameRuleBndr] }
520 : 'forall' rule_var_list '.' { $2 }
523 rule_var_list :: { [RdrNameRuleBndr] }
525 | rule_var rule_var_list { $1 : $2 }
527 rule_var :: { RdrNameRuleBndr }
528 : varid { RuleBndr $1 }
529 | '(' varid '::' ctype ')' { RuleBndrSig $2 $4 }
531 -----------------------------------------------------------------------------
532 -- Deprecations (c.f. rules)
534 deprecations :: { [RdrBinding] } -- Reversed
535 : deprecations ';' deprecation { $3 : $1 }
536 | deprecations ';' { $1 }
537 | deprecation { [$1] }
540 -- SUP: TEMPORARY HACK, not checking for `module Foo'
541 deprecation :: { RdrBinding }
542 : srcloc depreclist STRING
544 [ RdrHsDecl (DeprecD (Deprecation n $3 $1)) | n <- $2 ] }
547 -----------------------------------------------------------------------------
548 -- Foreign import and export declarations
550 -- for the time being, the following accepts foreign declarations conforming
551 -- to the FFI Addendum, Version 1.0 as well as pre-standard declarations
553 -- * a flag indicates whether pre-standard declarations have been used and
554 -- triggers a deprecation warning further down the road
556 -- NB: The first two rules could be combined into one by replacing `safety1'
557 -- with `safety'. However, the combined rule conflicts with the
560 fdecl :: { RdrNameHsDecl }
561 fdecl : srcloc 'import' callconv safety1 fspec {% mkImport $3 $4 $5 $1 }
562 | srcloc 'import' callconv fspec {% mkImport $3 (PlaySafe False) $4 $1 }
563 | srcloc 'export' callconv fspec {% mkExport $3 $4 $1 }
564 -- the following syntax is DEPRECATED
565 | srcloc fdecl1DEPRECATED { ForD ($2 True $1) }
566 | srcloc fdecl2DEPRECATED { $2 $1 }
568 fdecl1DEPRECATED :: { Bool -> SrcLoc -> ForeignDecl RdrName }
570 ----------- DEPRECATED label decls ------------
571 : 'label' ext_name varid '::' sigtype
572 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
573 (CLabel ($2 `orElse` mkExtName $3))) }
575 ----------- DEPRECATED ccall/stdcall decls ------------
577 -- NB: This business with the case expression below may seem overly
578 -- complicated, but it is necessary to avoid some conflicts.
580 -- DEPRECATED variant #1: lack of a calling convention specification
582 | 'import' {-no callconv-} ext_name safety varid_no_unsafe '::' sigtype
584 target = StaticTarget ($2 `orElse` mkExtName $4)
586 ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
587 (CFunction target)) }
589 -- DEPRECATED variant #2: external name consists of two separate strings
590 -- (module name and function name) (import)
591 | 'import' callconv STRING STRING safety varid_no_unsafe '::' sigtype
593 DNCall -> parseError "Illegal format of .NET foreign import"
594 CCall cconv -> returnP $
596 imp = CFunction (StaticTarget $4)
598 ForeignImport $6 $8 (CImport cconv $5 nilFS nilFS imp) }
600 -- DEPRECATED variant #3: `unsafe' after entity
601 | 'import' callconv STRING 'unsafe' varid_no_unsafe '::' sigtype
603 DNCall -> parseError "Illegal format of .NET foreign import"
604 CCall cconv -> returnP $
606 imp = CFunction (StaticTarget $3)
608 ForeignImport $5 $7 (CImport cconv PlayRisky nilFS nilFS imp) }
610 -- DEPRECATED variant #4: use of the special identifier `dynamic' without
611 -- an explicit calling convention (import)
612 | 'import' {-no callconv-} 'dynamic' safety varid_no_unsafe '::' sigtype
613 { ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
614 (CFunction DynamicTarget)) }
616 -- DEPRECATED variant #5: use of the special identifier `dynamic' (import)
617 | 'import' callconv 'dynamic' safety varid_no_unsafe '::' sigtype
619 DNCall -> parseError "Illegal format of .NET foreign import"
620 CCall cconv -> returnP $
621 ForeignImport $5 $7 (CImport cconv $4 nilFS nilFS
622 (CFunction DynamicTarget)) }
624 -- DEPRECATED variant #6: lack of a calling convention specification
626 | 'export' {-no callconv-} ext_name varid '::' sigtype
627 { ForeignExport $3 $5 (CExport (CExportStatic ($2 `orElse` mkExtName $3)
630 -- DEPRECATED variant #7: external name consists of two separate strings
631 -- (module name and function name) (export)
632 | 'export' callconv STRING STRING varid '::' sigtype
634 DNCall -> parseError "Illegal format of .NET foreign import"
635 CCall cconv -> returnP $
637 (CExport (CExportStatic $4 cconv)) }
639 -- DEPRECATED variant #8: use of the special identifier `dynamic' without
640 -- an explicit calling convention (export)
641 | 'export' {-no callconv-} 'dynamic' varid '::' sigtype
642 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
645 -- DEPRECATED variant #9: use of the special identifier `dynamic' (export)
646 | 'export' callconv 'dynamic' varid '::' sigtype
648 DNCall -> parseError "Illegal format of .NET foreign import"
649 CCall cconv -> returnP $
650 ForeignImport $4 $6 (CImport cconv (PlaySafe False) nilFS nilFS CWrapper) }
652 ----------- DEPRECATED .NET decls ------------
653 -- NB: removed the .NET call declaration, as it is entirely subsumed
654 -- by the new standard FFI declarations
656 fdecl2DEPRECATED :: { SrcLoc -> RdrNameHsDecl }
658 : 'import' 'dotnet' 'type' ext_name tycon
659 { \loc -> TyClD (ForeignType $5 $4 DNType loc) }
660 -- left this one unchanged for the moment as type imports are not
661 -- covered currently by the FFI standard -=chak
664 callconv :: { CallConv }
665 : 'stdcall' { CCall StdCallConv }
666 | 'ccall' { CCall CCallConv }
667 | 'dotnet' { DNCall }
670 : 'unsafe' { PlayRisky }
671 | 'safe' { PlaySafe False }
672 | 'threadsafe' { PlaySafe True }
673 | {- empty -} { PlaySafe False }
675 safety1 :: { Safety }
676 : 'unsafe' { PlayRisky }
677 | 'safe' { PlaySafe False }
678 | 'threadsafe' { PlaySafe True }
679 -- only needed to avoid conflicts with the DEPRECATED rules
681 fspec :: { (FastString, RdrName, RdrNameHsType) }
682 : STRING var '::' sigtype { ($1 , $2, $4) }
683 | var '::' sigtype { (nilFS, $1, $3) }
684 -- if the entity string is missing, it defaults to the empty string;
685 -- the meaning of an empty entity string depends on the calling
689 ext_name :: { Maybe CLabelString }
691 | STRING STRING { Just $2 } -- Ignore "module name" for now
692 | {- empty -} { Nothing }
695 -----------------------------------------------------------------------------
698 opt_sig :: { Maybe RdrNameHsType }
699 : {- empty -} { Nothing }
700 | '::' sigtype { Just $2 }
702 opt_asig :: { Maybe RdrNameHsType }
703 : {- empty -} { Nothing }
704 | '::' atype { Just $2 }
706 sigtypes :: { [RdrNameHsType] }
708 | sigtypes ',' sigtype { $3 : $1 }
710 sigtype :: { RdrNameHsType }
711 : ctype { mkHsForAllTy Nothing [] $1 }
713 sig_vars :: { [RdrName] }
714 : sig_vars ',' var { $3 : $1 }
717 -----------------------------------------------------------------------------
720 -- A ctype is a for-all type
721 ctype :: { RdrNameHsType }
722 : 'forall' tv_bndrs '.' ctype { mkHsForAllTy (Just $2) [] $4 }
723 | context '=>' type { mkHsForAllTy Nothing $1 $3 }
724 -- A type of form (context => type) is an *implicit* HsForAllTy
727 -- We parse a context as a btype so that we don't get reduce/reduce
728 -- errors in ctype. The basic problem is that
730 -- looks so much like a tuple type. We can't tell until we find the =>
731 context :: { RdrNameContext }
732 : btype {% checkContext $1 }
734 type :: { RdrNameHsType }
735 : ipvar '::' gentype { mkHsIParamTy $1 $3 }
738 gentype :: { RdrNameHsType }
740 | btype qtyconop gentype { HsOpTy $1 (HsTyOp $2) $3 }
741 | btype '`' tyvar '`' gentype { HsOpTy $1 (HsTyOp $3) $5 }
742 | btype '->' gentype { HsOpTy $1 HsArrow $3 }
744 btype :: { RdrNameHsType }
745 : btype atype { HsAppTy $1 $2 }
748 atype :: { RdrNameHsType }
749 : gtycon { HsTyVar $1 }
750 | tyvar { HsTyVar $1 }
751 | '(' type ',' comma_types1 ')' { HsTupleTy (mkHsTupCon tcName Boxed ($2:$4)) ($2:$4) }
752 | '(#' comma_types1 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
753 | '[' type ']' { HsListTy $2 }
754 | '[:' type ':]' { HsPArrTy $2 }
755 | '(' ctype ')' { HsParTy $2 }
756 | '(' ctype '::' kind ')' { HsKindSig $2 $4 }
758 | INTEGER { HsNumTy $1 }
760 -- An inst_type is what occurs in the head of an instance decl
761 -- e.g. (Foo a, Gaz b) => Wibble a b
762 -- It's kept as a single type, with a MonoDictTy at the right
763 -- hand corner, for convenience.
764 inst_type :: { RdrNameHsType }
765 : ctype {% checkInstType $1 }
767 comma_types0 :: { [RdrNameHsType] }
768 : comma_types1 { $1 }
771 comma_types1 :: { [RdrNameHsType] }
773 | type ',' comma_types1 { $1 : $3 }
775 tv_bndrs :: { [RdrNameHsTyVar] }
776 : tv_bndr tv_bndrs { $1 : $2 }
779 tv_bndr :: { RdrNameHsTyVar }
780 : tyvar { UserTyVar $1 }
781 | '(' tyvar '::' kind ')' { IfaceTyVar $2 $4 }
783 fds :: { [([RdrName], [RdrName])] }
785 | '|' fds1 { reverse $2 }
787 fds1 :: { [([RdrName], [RdrName])] }
788 : fds1 ',' fd { $3 : $1 }
791 fd :: { ([RdrName], [RdrName]) }
792 : varids0 '->' varids0 { (reverse $1, reverse $3) }
794 varids0 :: { [RdrName] }
796 | varids0 tyvar { $2 : $1 }
798 -----------------------------------------------------------------------------
803 | akind '->' kind { mkArrowKind $1 $3 }
806 : '*' { liftedTypeKind }
807 | '(' kind ')' { $2 }
810 -----------------------------------------------------------------------------
811 -- Datatype declarations
813 newconstr :: { RdrNameConDecl }
814 : srcloc conid atype { ConDecl $2 [] [] (PrefixCon [unbangedType $3]) $1 }
815 | srcloc conid '{' var '::' ctype '}'
816 { ConDecl $2 [] [] (RecCon [($4, unbangedType $6)]) $1 }
818 constrs :: { [RdrNameConDecl] }
819 : {- empty; a GHC extension -} { [] }
820 | '=' constrs1 { $2 }
822 constrs1 :: { [RdrNameConDecl] }
823 : constrs1 '|' constr { $3 : $1 }
826 constr :: { RdrNameConDecl }
827 : srcloc forall context '=>' constr_stuff
828 { ConDecl (fst $5) $2 $3 (snd $5) $1 }
829 | srcloc forall constr_stuff
830 { ConDecl (fst $3) $2 [] (snd $3) $1 }
832 forall :: { [RdrNameHsTyVar] }
833 : 'forall' tv_bndrs '.' { $2 }
836 constr_stuff :: { (RdrName, RdrNameConDetails) }
837 : btype {% mkPrefixCon $1 [] }
838 | btype '!' atype satypes {% mkPrefixCon $1 (BangType MarkedUserStrict $3 : $4) }
839 | oqtycon '{' '}' {% mkRecCon $1 [] }
840 | oqtycon '{' fielddecls '}' {% mkRecCon $1 $3 }
841 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
843 satypes :: { [RdrNameBangType] }
844 : atype satypes { unbangedType $1 : $2 }
845 | '!' atype satypes { BangType MarkedUserStrict $2 : $3 }
848 sbtype :: { RdrNameBangType }
849 : btype { unbangedType $1 }
850 | '!' atype { BangType MarkedUserStrict $2 }
852 fielddecls :: { [([RdrName],RdrNameBangType)] }
853 : fielddecl ',' fielddecls { $1 : $3 }
856 fielddecl :: { ([RdrName],RdrNameBangType) }
857 : sig_vars '::' stype { (reverse $1, $3) }
859 stype :: { RdrNameBangType }
860 : ctype { unbangedType $1 }
861 | '!' atype { BangType MarkedUserStrict $2 }
863 deriving :: { Maybe RdrNameContext }
864 : {- empty -} { Nothing }
865 | 'deriving' context { Just $2 }
866 -- Glasgow extension: allow partial
867 -- applications in derivings
869 -----------------------------------------------------------------------------
872 {- There's an awkward overlap with a type signature. Consider
873 f :: Int -> Int = ...rhs...
874 Then we can't tell whether it's a type signature or a value
875 definition with a result signature until we see the '='.
876 So we have to inline enough to postpone reductions until we know.
880 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
881 instead of qvar, we get another shift/reduce-conflict. Consider the
884 { (^^) :: Int->Int ; } Type signature; only var allowed
886 { (^^) :: Int->Int = ... ; } Value defn with result signature;
887 qvar allowed (because of instance decls)
889 We can't tell whether to reduce var to qvar until after we've read the signatures.
892 decl :: { RdrBinding }
894 | infixexp srcloc opt_sig rhs {% checkValDef $1 $3 $4 $2 }
896 rhs :: { RdrNameGRHSs }
897 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2) $4 placeHolderType }
898 | gdrhs wherebinds { GRHSs (reverse $1) $2 placeHolderType }
900 gdrhs :: { [RdrNameGRHS] }
901 : gdrhs gdrh { $2 : $1 }
904 gdrh :: { RdrNameGRHS }
905 : '|' srcloc quals '=' exp { GRHS (reverse (ResultStmt $5 $2 : $3)) $2 }
907 sigdecl :: { RdrBinding }
908 : infixexp srcloc '::' sigtype
909 {% checkValSig $1 $4 $2 }
910 -- See the above notes for why we need infixexp here
911 | var ',' sig_vars srcloc '::' sigtype
912 { mkSigDecls [ Sig n $6 $4 | n <- $1:$3 ] }
913 | srcloc infix prec ops { mkSigDecls [ FixSig (FixitySig n (Fixity $3 $2) $1)
915 | '{-# INLINE' srcloc activation qvar '#-}'
916 { RdrHsDecl (SigD (InlineSig True $4 $3 $2)) }
917 | '{-# NOINLINE' srcloc inverse_activation qvar '#-}'
918 { RdrHsDecl (SigD (InlineSig False $4 $3 $2)) }
919 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
920 { mkSigDecls [ SpecSig $3 t $2 | t <- $5] }
921 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
922 { RdrHsDecl (SigD (SpecInstSig $4 $2)) }
924 -----------------------------------------------------------------------------
927 exp :: { RdrNameHsExpr }
928 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
929 | infixexp 'with' dbinding { HsLet (IPBinds $3 True{-not a let-}) $1 }
932 infixexp :: { RdrNameHsExpr }
934 | infixexp qop exp10 { (OpApp $1 (HsVar $2)
935 (panic "fixity") $3 )}
937 exp10 :: { RdrNameHsExpr }
938 : '\\' srcloc aexp aexps opt_asig '->' srcloc exp
939 {% checkPatterns $2 ($3 : reverse $4) `thenP` \ ps ->
940 returnP (HsLam (Match ps $5
941 (GRHSs (unguardedRHS $8 $7)
942 EmptyBinds placeHolderType))) }
943 | 'let' binds 'in' exp { HsLet $2 $4 }
944 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
945 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
946 | '-' fexp { mkHsNegApp $2 }
947 | srcloc 'do' stmtlist {% checkDo $3 `thenP` \ stmts ->
948 returnP (mkHsDo DoExpr stmts $1) }
949 | srcloc 'mdo' stmtlist {% checkMDo $3 `thenP` \ stmts ->
950 returnP (mkHsDo MDoExpr stmts $1) }
952 | '_ccall_' ccallid aexps0 { HsCCall $2 $3 PlayRisky False placeHolderType }
953 | '_ccall_GC_' ccallid aexps0 { HsCCall $2 $3 (PlaySafe False) False placeHolderType }
954 | '_casm_' CLITLIT aexps0 { HsCCall $2 $3 PlayRisky True placeHolderType }
955 | '_casm_GC_' CLITLIT aexps0 { HsCCall $2 $3 (PlaySafe False) True placeHolderType }
957 | scc_annot exp { if opt_SccProfilingOn
961 | reifyexp { HsReify $1 }
964 scc_annot :: { FastString }
965 : '_scc_' STRING { $2 }
966 | '{-# SCC' STRING '#-}' { $2 }
968 ccallid :: { FastString }
972 fexp :: { RdrNameHsExpr }
973 : fexp aexp { (HsApp $1 $2) }
976 reifyexp :: { HsReify RdrName }
977 : REIFY_DECL gtycon { Reify ReifyDecl $2 }
978 | REIFY_DECL qvar { Reify ReifyDecl $2 }
979 | REIFY_TYPE qcname { Reify ReifyType $2 }
980 | REIFY_FIXITY qcname { Reify ReifyFixity $2 }
982 aexps0 :: { [RdrNameHsExpr] }
983 : aexps { reverse $1 }
985 aexps :: { [RdrNameHsExpr] }
986 : aexps aexp { $2 : $1 }
989 aexp :: { RdrNameHsExpr }
990 : qvar '@' aexp { EAsPat $1 $3 }
991 | '~' aexp { ELazyPat $2 }
994 aexp1 :: { RdrNameHsExpr }
995 : aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1 (reverse $3)) }
998 -- Here was the syntax for type applications that I was planning
999 -- but there are difficulties (e.g. what order for type args)
1000 -- so it's not enabled yet.
1001 | qcname '{|' gentype '|}' { (HsApp (HsVar $1) (HsType $3)) }
1003 aexp2 :: { RdrNameHsExpr }
1004 : ipvar { HsIPVar $1 }
1005 | qcname { HsVar $1 }
1006 | literal { HsLit $1 }
1007 | INTEGER { HsOverLit (mkHsIntegral $1) }
1008 | RATIONAL { HsOverLit (mkHsFractional $1) }
1009 | '(' exp ')' { HsPar $2 }
1010 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) Boxed}
1011 | '(#' texps '#)' { ExplicitTuple (reverse $2) Unboxed }
1012 | '[' list ']' { $2 }
1013 | '[:' parr ':]' { $2 }
1014 | '(' infixexp qop ')' { (SectionL $2 (HsVar $3)) }
1015 | '(' qopm infixexp ')' { (SectionR $2 $3) }
1018 -- MetaHaskell Extension
1019 | srcloc ID_SPLICE { mkHsSplice (HsVar (mkUnqual varName $2)) $1 } -- $x
1020 | srcloc '$(' exp ')' { mkHsSplice $3 $1 } -- $( exp )
1021 | srcloc '[|' exp '|]' { HsBracket (ExpBr $3) $1 }
1022 | srcloc '[t|' ctype '|]' { HsBracket (TypBr $3) $1 }
1023 | srcloc '[p|' infixexp '|]' {% checkPattern $1 $3 `thenP` \p ->
1024 returnP (HsBracket (PatBr p) $1) }
1025 | srcloc '[d|' cvtopbody '|]' { HsBracket (DecBr (mkGroup $3)) $1 }
1027 cvtopbody :: { [RdrNameHsDecl] }
1028 : '{' cvtopdecls '}' { $2 }
1029 | layout_on cvtopdecls close { $2 }
1031 texps :: { [RdrNameHsExpr] }
1032 : texps ',' exp { $3 : $1 }
1036 -----------------------------------------------------------------------------
1039 -- The rules below are little bit contorted to keep lexps left-recursive while
1040 -- avoiding another shift/reduce-conflict.
1042 list :: { RdrNameHsExpr }
1043 : exp { ExplicitList placeHolderType [$1] }
1044 | lexps { ExplicitList placeHolderType (reverse $1) }
1045 | exp '..' { ArithSeqIn (From $1) }
1046 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
1047 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
1048 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
1049 | exp srcloc pquals {% let { body [qs] = qs;
1050 body qss = [ParStmt (map reverse qss)] }
1052 returnP ( mkHsDo ListComp
1053 (reverse (ResultStmt $1 $2 : body $3))
1058 lexps :: { [RdrNameHsExpr] }
1059 : lexps ',' exp { $3 : $1 }
1060 | exp ',' exp { [$3,$1] }
1062 -----------------------------------------------------------------------------
1063 -- List Comprehensions
1065 pquals :: { [[RdrNameStmt]] }
1066 : pquals '|' quals { $3 : $1 }
1067 | '|' quals { [$2] }
1069 quals :: { [RdrNameStmt] }
1070 : quals ',' stmt { $3 : $1 }
1073 -----------------------------------------------------------------------------
1074 -- Parallel array expressions
1076 -- The rules below are little bit contorted; see the list case for details.
1077 -- Note that, in contrast to lists, we only have finite arithmetic sequences.
1078 -- Moreover, we allow explicit arrays with no element (represented by the nil
1079 -- constructor in the list case).
1081 parr :: { RdrNameHsExpr }
1082 : { ExplicitPArr placeHolderType [] }
1083 | exp { ExplicitPArr placeHolderType [$1] }
1084 | lexps { ExplicitPArr placeHolderType
1086 | exp '..' exp { PArrSeqIn (FromTo $1 $3) }
1087 | exp ',' exp '..' exp { PArrSeqIn (FromThenTo $1 $3 $5) }
1088 | exp srcloc pquals {% let {
1095 (reverse (ResultStmt $1 $2
1100 -- We are reusing `lexps' and `pquals' from the list case.
1102 -----------------------------------------------------------------------------
1103 -- Case alternatives
1105 altslist :: { [RdrNameMatch] }
1106 : '{' alts '}' { reverse $2 }
1107 | layout_on alts close { reverse $2 }
1109 alts :: { [RdrNameMatch] }
1113 alts1 :: { [RdrNameMatch] }
1114 : alts1 ';' alt { $3 : $1 }
1118 alt :: { RdrNameMatch }
1119 : srcloc infixexp opt_sig ralt wherebinds
1120 {% (checkPattern $1 $2 `thenP` \p ->
1121 returnP (Match [p] $3
1122 (GRHSs $4 $5 placeHolderType)) )}
1124 ralt :: { [RdrNameGRHS] }
1125 : '->' srcloc exp { [GRHS [ResultStmt $3 $2] $2] }
1126 | gdpats { reverse $1 }
1128 gdpats :: { [RdrNameGRHS] }
1129 : gdpats gdpat { $2 : $1 }
1132 gdpat :: { RdrNameGRHS }
1133 : srcloc '|' quals '->' exp { GRHS (reverse (ResultStmt $5 $1:$3)) $1}
1135 -----------------------------------------------------------------------------
1136 -- Statement sequences
1138 stmtlist :: { [RdrNameStmt] }
1139 : '{' stmts '}' { $2 }
1140 | layout_on_for_do stmts close { $2 }
1142 -- do { ;; s ; s ; ; s ;; }
1143 -- The last Stmt should be a ResultStmt, but that's hard to enforce
1144 -- here, because we need too much lookahead if we see do { e ; }
1145 -- So we use ExprStmts throughout, and switch the last one over
1146 -- in ParseUtils.checkDo instead
1147 stmts :: { [RdrNameStmt] }
1148 : stmt stmts_help { $1 : $2 }
1150 | {- empty -} { [] }
1152 stmts_help :: { [RdrNameStmt] }
1154 | {- empty -} { [] }
1156 -- For typing stmts at the GHCi prompt, where
1157 -- the input may consist of just comments.
1158 maybe_stmt :: { Maybe RdrNameStmt }
1160 | {- nothing -} { Nothing }
1162 stmt :: { RdrNameStmt }
1163 : srcloc infixexp '<-' exp {% checkPattern $1 $2 `thenP` \p ->
1164 returnP (BindStmt p $4 $1) }
1165 | srcloc exp { ExprStmt $2 placeHolderType $1 }
1166 | srcloc 'let' binds { LetStmt $3 }
1168 -----------------------------------------------------------------------------
1169 -- Record Field Update/Construction
1171 fbinds :: { RdrNameHsRecordBinds }
1172 : fbinds ',' fbind { $3 : $1 }
1175 | {- empty -} { [] }
1177 fbind :: { (RdrName, RdrNameHsExpr) }
1178 : qvar '=' exp { ($1,$3) }
1180 -----------------------------------------------------------------------------
1181 -- Implicit Parameter Bindings
1183 dbinding :: { [(IPName RdrName, RdrNameHsExpr)] }
1184 : '{' dbinds '}' { $2 }
1185 | layout_on dbinds close { $2 }
1187 dbinds :: { [(IPName RdrName, RdrNameHsExpr)] }
1188 : dbinds ';' dbind { $3 : $1 }
1191 -- | {- empty -} { [] }
1193 dbind :: { (IPName RdrName, RdrNameHsExpr) }
1194 dbind : ipvar '=' exp { ($1, $3) }
1196 -----------------------------------------------------------------------------
1197 -- Variables, Constructors and Operators.
1199 identifier :: { RdrName }
1204 depreclist :: { [RdrName] }
1205 depreclist : deprec_var { [$1] }
1206 | deprec_var ',' depreclist { $1 : $3 }
1208 deprec_var :: { RdrName }
1209 deprec_var : var { $1 }
1212 gcon :: { RdrName } -- Data constructor namespace
1213 : sysdcon { nameRdrName (dataConName $1) }
1215 -- the case of '[:' ':]' is part of the production `parr'
1217 sysdcon :: { DataCon } -- Wired in data constructors
1218 : '(' ')' { unitDataCon }
1219 | '(' commas ')' { tupleCon Boxed $2 }
1220 | '[' ']' { nilDataCon }
1224 | '(' varsym ')' { $2 }
1228 | '(' varsym ')' { $2 }
1229 | '(' qvarsym1 ')' { $2 }
1230 -- We've inlined qvarsym here so that the decision about
1231 -- whether it's a qvar or a var can be postponed until
1232 -- *after* we see the close paren.
1234 ipvar :: { IPName RdrName }
1235 : IPDUPVARID { Dupable (mkUnqual varName $1) }
1236 | IPSPLITVARID { Linear (mkUnqual varName $1) }
1240 | '(' qconsym ')' { $2 }
1242 varop :: { RdrName }
1244 | '`' varid '`' { $2 }
1246 qvarop :: { RdrName }
1248 | '`' qvarid '`' { $2 }
1250 qvaropm :: { RdrName }
1251 : qvarsym_no_minus { $1 }
1252 | '`' qvarid '`' { $2 }
1254 conop :: { RdrName }
1256 | '`' conid '`' { $2 }
1258 qconop :: { RdrName }
1260 | '`' qconid '`' { $2 }
1262 -----------------------------------------------------------------------------
1263 -- Type constructors
1265 gtycon :: { RdrName } -- A "general" qualified tycon
1267 | '(' ')' { getRdrName unitTyCon }
1268 | '(' commas ')' { getRdrName (tupleTyCon Boxed $2) }
1269 | '(' '->' ')' { nameRdrName funTyConName }
1270 | '[' ']' { nameRdrName listTyConName }
1271 | '[:' ':]' { nameRdrName parrTyConName }
1273 oqtycon :: { RdrName } -- An "ordinary" qualified tycon
1275 | '(' qtyconsym ')' { $2 }
1277 qtyconop :: { RdrName } -- Qualified or unqualified
1279 | '`' qtycon '`' { $2 }
1281 tyconop :: { RdrName } -- Unqualified
1283 | '`' tycon '`' { $2 }
1285 qtycon :: { RdrName } -- Qualified or unqualified
1286 : QCONID { mkQual tcClsName $1 }
1289 tycon :: { RdrName } -- Unqualified
1290 : CONID { mkUnqual tcClsName $1 }
1292 qtyconsym :: { RdrName }
1293 : QCONSYM { mkQual tcClsName $1 }
1296 tyconsym :: { RdrName }
1297 : CONSYM { mkUnqual tcClsName $1 }
1299 -----------------------------------------------------------------------------
1302 op :: { RdrName } -- used in infix decls
1306 qop :: { RdrName {-HsExpr-} } -- used in sections
1310 qopm :: { RdrNameHsExpr } -- used in sections
1311 : qvaropm { HsVar $1 }
1312 | qconop { HsVar $1 }
1314 -----------------------------------------------------------------------------
1317 qvarid :: { RdrName }
1319 | QVARID { mkQual varName $1 }
1321 varid :: { RdrName }
1322 : varid_no_unsafe { $1 }
1323 | 'unsafe' { mkUnqual varName FSLIT("unsafe") }
1324 | 'safe' { mkUnqual varName FSLIT("safe") }
1325 | 'threadsafe' { mkUnqual varName FSLIT("threadsafe") }
1327 varid_no_unsafe :: { RdrName }
1328 : VARID { mkUnqual varName $1 }
1329 | special_id { mkUnqual varName $1 }
1330 | 'forall' { mkUnqual varName FSLIT("forall") }
1332 tyvar :: { RdrName }
1333 : VARID { mkUnqual tvName $1 }
1334 | special_id { mkUnqual tvName $1 }
1335 | 'unsafe' { mkUnqual tvName FSLIT("unsafe") }
1336 | 'safe' { mkUnqual tvName FSLIT("safe") }
1337 | 'threadsafe' { mkUnqual tvName FSLIT("threadsafe") }
1339 -- These special_ids are treated as keywords in various places,
1340 -- but as ordinary ids elsewhere. 'special_id' collects all these
1341 -- except 'unsafe' and 'forall' whose treatment differs depending on context
1342 special_id :: { UserFS }
1344 : 'as' { FSLIT("as") }
1345 | 'qualified' { FSLIT("qualified") }
1346 | 'hiding' { FSLIT("hiding") }
1347 | 'export' { FSLIT("export") }
1348 | 'label' { FSLIT("label") }
1349 | 'dynamic' { FSLIT("dynamic") }
1350 | 'stdcall' { FSLIT("stdcall") }
1351 | 'ccall' { FSLIT("ccall") }
1353 -----------------------------------------------------------------------------
1356 qvarsym :: { RdrName }
1360 qvarsym_no_minus :: { RdrName }
1361 : varsym_no_minus { $1 }
1364 qvarsym1 :: { RdrName }
1365 qvarsym1 : QVARSYM { mkQual varName $1 }
1367 varsym :: { RdrName }
1368 : varsym_no_minus { $1 }
1369 | '-' { mkUnqual varName FSLIT("-") }
1371 varsym_no_minus :: { RdrName } -- varsym not including '-'
1372 : VARSYM { mkUnqual varName $1 }
1373 | special_sym { mkUnqual varName $1 }
1376 -- See comments with special_id
1377 special_sym :: { UserFS }
1378 special_sym : '!' { FSLIT("!") }
1379 | '.' { FSLIT(".") }
1380 | '*' { FSLIT("*") }
1382 -----------------------------------------------------------------------------
1383 -- Data constructors
1385 qconid :: { RdrName } -- Qualified or unqualifiedb
1387 | QCONID { mkQual dataName $1 }
1389 conid :: { RdrName }
1390 : CONID { mkUnqual dataName $1 }
1392 qconsym :: { RdrName } -- Qualified or unqualified
1394 | QCONSYM { mkQual dataName $1 }
1396 consym :: { RdrName }
1397 : CONSYM { mkUnqual dataName $1 }
1399 -- ':' means only list cons
1400 | ':' { nameRdrName consDataConName }
1401 -- NB: SrcName because we are reading source
1404 -----------------------------------------------------------------------------
1407 literal :: { HsLit }
1408 : CHAR { HsChar $1 }
1409 | STRING { HsString $1 }
1410 | PRIMINTEGER { HsIntPrim $1 }
1411 | PRIMCHAR { HsCharPrim $1 }
1412 | PRIMSTRING { HsStringPrim $1 }
1413 | PRIMFLOAT { HsFloatPrim $1 }
1414 | PRIMDOUBLE { HsDoublePrim $1 }
1415 | CLITLIT { HsLitLit $1 placeHolderType }
1417 srcloc :: { SrcLoc } : {% getSrcLocP }
1419 -----------------------------------------------------------------------------
1423 : vccurly { () } -- context popped in lexer.
1424 | error {% popContext }
1426 layout_on :: { () } : {% layoutOn True{-strict-} }
1427 layout_on_for_do :: { () } : {% layoutOn False }
1429 -----------------------------------------------------------------------------
1430 -- Miscellaneous (mostly renamings)
1432 modid :: { ModuleName }
1433 : CONID { mkModuleNameFS $1 }
1434 | QCONID { mkModuleNameFS
1436 (unpackFS (fst $1) ++
1437 '.':unpackFS (snd $1)))
1441 : commas ',' { $1 + 1 }
1444 -----------------------------------------------------------------------------
1448 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)