2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.116 2003/02/20 18:33:53 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 '{-# CORE' { ITcore_prag } -- hdaume: annotated core
144 '{-# SCC' { ITscc_prag }
145 '{-# DEPRECATED' { ITdeprecated_prag }
146 '#-}' { ITclose_prag }
149 '__interface' { ITinterface } -- interface keywords
150 '__export' { IT__export }
151 '__instimport' { ITinstimport }
152 '__forall' { IT__forall }
153 '__letrec' { ITletrec }
154 '__coerce' { ITcoerce }
155 '__depends' { ITdepends }
156 '__inline' { ITinline }
157 '__DEFAULT' { ITdefaultbranch }
159 '__integer' { ITinteger_lit }
160 '__float' { ITfloat_lit }
161 '__rational' { ITrational_lit }
162 '__addr' { ITaddr_lit }
163 '__label' { ITlabel_lit }
164 '__litlit' { ITlit_lit }
165 '__string' { ITstring_lit }
166 '__ccall' { ITccall $$ }
168 '__sccC' { ITsccAllCafs }
171 '__P' { ITspecialise }
174 '__S' { ITstrict $$ }
175 '__M' { ITcprinfo $$ }
178 '..' { ITdotdot } -- reserved symbols
194 '{' { ITocurly } -- special symbols
198 vccurly { ITvccurly } -- virtual close curly (from layout)
211 VARID { ITvarid $$ } -- identifiers
213 VARSYM { ITvarsym $$ }
214 CONSYM { ITconsym $$ }
215 QVARID { ITqvarid $$ }
216 QCONID { ITqconid $$ }
217 QVARSYM { ITqvarsym $$ }
218 QCONSYM { ITqconsym $$ }
220 IPDUPVARID { ITdupipvarid $$ } -- GHC extension
221 IPSPLITVARID { ITsplitipvarid $$ } -- GHC extension
224 STRING { ITstring $$ }
225 INTEGER { ITinteger $$ }
226 RATIONAL { ITrational $$ }
228 PRIMCHAR { ITprimchar $$ }
229 PRIMSTRING { ITprimstring $$ }
230 PRIMINTEGER { ITprimint $$ }
231 PRIMFLOAT { ITprimfloat $$ }
232 PRIMDOUBLE { ITprimdouble $$ }
233 CLITLIT { ITlitlit $$ }
236 '[|' { ITopenExpQuote }
237 '[p|' { ITopenPatQuote }
238 '[t|' { ITopenTypQuote }
239 '[d|' { ITopenDecQuote }
240 '|]' { ITcloseQuote }
241 ID_SPLICE { ITidEscape $$ } -- $x
242 '$(' { ITparenEscape } -- $( exp )
243 REIFY_TYPE { ITreifyType }
244 REIFY_DECL { ITreifyDecl }
245 REIFY_FIXITY { ITreifyFixity }
247 %monad { P } { thenP } { returnP }
248 %lexer { lexer } { ITeof }
249 %name parseModule module
250 %name parseStmt maybe_stmt
251 %name parseIdentifier identifier
252 %name parseIface iface
256 -----------------------------------------------------------------------------
259 -- The place for module deprecation is really too restrictive, but if it
260 -- was allowed at its natural place just before 'module', we get an ugly
261 -- s/r conflict with the second alternative. Another solution would be the
262 -- introduction of a new pragma DEPRECATED_MODULE, but this is not very nice,
263 -- either, and DEPRECATED is only expected to be used by people who really
264 -- know what they are doing. :-)
266 module :: { RdrNameHsModule }
267 : srcloc 'module' modid maybemoddeprec maybeexports 'where' body
268 { HsModule (mkHomeModule $3) Nothing $5 (fst $7) (snd $7) $4 $1 }
270 { HsModule (mkHomeModule mAIN_Name) Nothing Nothing
271 (fst $2) (snd $2) Nothing $1 }
273 maybemoddeprec :: { Maybe DeprecTxt }
274 : '{-# DEPRECATED' STRING '#-}' { Just $2 }
275 | {- empty -} { Nothing }
277 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
279 | layout_on top close { $2 }
281 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
282 : importdecls { (reverse $1,[]) }
283 | importdecls ';' cvtopdecls { (reverse $1,$3) }
284 | cvtopdecls { ([],$1) }
286 cvtopdecls :: { [RdrNameHsDecl] }
287 : topdecls { cvTopDecls $1 }
289 -----------------------------------------------------------------------------
290 -- Interfaces (.hi-boot files)
292 iface :: { ParsedIface }
293 : 'module' modid 'where' ifacebody
296 pi_pkg = opt_InPackage,
297 pi_vers = 1, -- Module version
299 pi_exports = (1,[($2,mkIfaceExports $4)]),
300 pi_deps = noDependencies,
304 pi_decls = map (\x -> (1,x)) $4,
310 ifacebody :: { [RdrNameTyClDecl] }
311 : '{' ifacedecls '}' { $2 }
312 | layout_on ifacedecls close { $2 }
314 ifacedecls :: { [RdrNameTyClDecl] }
315 : ifacedecl ';' ifacedecls { $1 : $3 }
316 | ';' ifacedecls { $2 }
320 ifacedecl :: { RdrNameTyClDecl }
322 | srcloc var '::' sigtype { IfaceSig $2 $4 [] $1 }
324 -----------------------------------------------------------------------------
327 maybeexports :: { Maybe [RdrNameIE] }
328 : '(' exportlist ')' { Just $2 }
329 | {- empty -} { Nothing }
331 exportlist :: { [RdrNameIE] }
332 : exportlist ',' export { $3 : $1 }
333 | exportlist ',' { $1 }
337 -- No longer allow things like [] and (,,,) to be exported
338 -- They are built in syntax, always available
339 export :: { RdrNameIE }
341 | oqtycon { IEThingAbs $1 }
342 | oqtycon '(' '..' ')' { IEThingAll $1 }
343 | oqtycon '(' ')' { IEThingWith $1 [] }
344 | oqtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
345 | 'module' modid { IEModuleContents $2 }
347 qcnames :: { [RdrName] }
348 : qcnames ',' qcname { $3 : $1 }
351 qcname :: { RdrName } -- Variable or data constructor
355 -----------------------------------------------------------------------------
356 -- Import Declarations
358 -- import decls can be *empty*, or even just a string of semicolons
359 -- whereas topdecls must contain at least one topdecl.
361 importdecls :: { [RdrNameImportDecl] }
362 : importdecls ';' importdecl { $3 : $1 }
363 | importdecls ';' { $1 }
364 | importdecl { [ $1 ] }
367 importdecl :: { RdrNameImportDecl }
368 : 'import' srcloc maybe_src optqualified modid maybeas maybeimpspec
369 { ImportDecl $5 $3 $4 $6 $7 $2 }
371 maybe_src :: { IsBootInterface }
372 : '{-# SOURCE' '#-}' { True }
373 | {- empty -} { False }
375 optqualified :: { Bool }
376 : 'qualified' { True }
377 | {- empty -} { False }
379 maybeas :: { Maybe ModuleName }
380 : 'as' modid { Just $2 }
381 | {- empty -} { Nothing }
383 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
384 : impspec { Just $1 }
385 | {- empty -} { Nothing }
387 impspec :: { (Bool, [RdrNameIE]) }
388 : '(' exportlist ')' { (False, reverse $2) }
389 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
391 -----------------------------------------------------------------------------
392 -- Fixity Declarations
396 | INTEGER {% checkPrecP (fromInteger $1) }
398 infix :: { FixityDirection }
400 | 'infixl' { InfixL }
401 | 'infixr' { InfixR }
404 : ops ',' op { $3 : $1 }
407 -----------------------------------------------------------------------------
408 -- Top-Level Declarations
410 topdecls :: { [RdrBinding] } -- Reversed
411 : topdecls ';' topdecl { $3 : $1 }
412 | topdecls ';' { $1 }
415 topdecl :: { RdrBinding }
416 : tycl_decl { RdrHsDecl (TyClD $1) }
417 | srcloc 'instance' inst_type where
418 { let (binds,sigs) = cvMonoBindsAndSigs $4
419 in RdrHsDecl (InstD (InstDecl $3 binds sigs Nothing $1)) }
420 | srcloc 'default' '(' comma_types0 ')' { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
421 | 'foreign' fdecl { RdrHsDecl $2 }
422 | '{-# DEPRECATED' deprecations '#-}' { RdrBindings (reverse $2) }
423 | '{-# RULES' rules '#-}' { RdrBindings (reverse $2) }
424 | srcloc '$(' exp ')' { RdrHsDecl (SpliceD (SpliceDecl $3 $1)) }
427 tycl_decl :: { RdrNameTyClDecl }
428 : srcloc 'type' syn_hdr '=' ctype
429 -- Note ctype, not sigtype.
430 -- We allow an explicit for-all but we don't insert one
431 -- in type Foo a = (b,b)
432 -- Instead we just say b is out of scope
433 { let (tc,tvs) = $3 in TySynonym tc tvs $5 $1 }
436 | srcloc 'data' tycl_hdr constrs deriving
437 { mkTyData DataType $3 (DataCons (reverse $4)) $5 $1 }
439 | srcloc 'newtype' tycl_hdr '=' newconstr deriving
440 { mkTyData NewType $3 (DataCons [$5]) $6 $1 }
442 | srcloc 'class' tycl_hdr fds where
444 (binds,sigs) = cvMonoBindsAndSigs $5
446 mkClassDecl $3 $4 (map cvClassOpSig sigs) (Just binds) $1 }
448 syn_hdr :: { (RdrName, [RdrNameHsTyVar]) } -- We don't retain the syntax of an infix
449 -- type synonym declaration. Oh well.
450 : tycon tv_bndrs { ($1, $2) }
451 | tv_bndr tyconop tv_bndr { ($2, [$1,$3]) }
453 -- tycl_hdr parses the header of a type or class decl,
454 -- which takes the form
457 -- (Eq a, Ord b) => T a b
458 -- Rather a lot of inlining here, else we get reduce/reduce errors
459 tycl_hdr :: { (RdrNameContext, RdrName, [RdrNameHsTyVar]) }
460 : context '=>' type {% checkTyClHdr $3 `thenP` \ (tc,tvs) ->
461 returnP ($1, tc, tvs) }
462 | type {% checkTyClHdr $1 `thenP` \ (tc,tvs) ->
463 returnP ([], tc, tvs) }
465 -----------------------------------------------------------------------------
466 -- Nested declarations
468 decls :: { [RdrBinding] } -- Reversed
469 : decls ';' decl { $3 : $1 }
475 decllist :: { [RdrBinding] } -- Reversed
476 : '{' decls '}' { $2 }
477 | layout_on decls close { $2 }
479 where :: { [RdrBinding] } -- Reversed
480 -- No implicit parameters
481 : 'where' decllist { $2 }
484 binds :: { RdrNameHsBinds } -- May have implicit parameters
485 : decllist { cvBinds $1 }
486 | '{' dbinds '}' { IPBinds $2 False{-not with-} }
487 | layout_on dbinds close { IPBinds $2 False{-not with-} }
489 wherebinds :: { RdrNameHsBinds } -- May have implicit parameters
490 : 'where' binds { $2 }
491 | {- empty -} { EmptyBinds }
495 -----------------------------------------------------------------------------
496 -- Transformation Rules
498 rules :: { [RdrBinding] } -- Reversed
499 : rules ';' rule { $3 : $1 }
504 rule :: { RdrBinding }
505 : STRING activation rule_forall infixexp '=' srcloc exp
506 { RdrHsDecl (RuleD (HsRule $1 $2 $3 $4 $7 $6)) }
508 activation :: { Activation } -- Omitted means AlwaysActive
509 : {- empty -} { AlwaysActive }
510 | explicit_activation { $1 }
512 inverse_activation :: { Activation } -- Omitted means NeverActive
513 : {- empty -} { NeverActive }
514 | explicit_activation { $1 }
516 explicit_activation :: { Activation } -- In brackets
517 : '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
518 | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
520 rule_forall :: { [RdrNameRuleBndr] }
521 : 'forall' rule_var_list '.' { $2 }
524 rule_var_list :: { [RdrNameRuleBndr] }
526 | rule_var rule_var_list { $1 : $2 }
528 rule_var :: { RdrNameRuleBndr }
529 : varid { RuleBndr $1 }
530 | '(' varid '::' ctype ')' { RuleBndrSig $2 $4 }
532 -----------------------------------------------------------------------------
533 -- Deprecations (c.f. rules)
535 deprecations :: { [RdrBinding] } -- Reversed
536 : deprecations ';' deprecation { $3 : $1 }
537 | deprecations ';' { $1 }
538 | deprecation { [$1] }
541 -- SUP: TEMPORARY HACK, not checking for `module Foo'
542 deprecation :: { RdrBinding }
543 : srcloc depreclist STRING
545 [ RdrHsDecl (DeprecD (Deprecation n $3 $1)) | n <- $2 ] }
548 -----------------------------------------------------------------------------
549 -- Foreign import and export declarations
551 -- for the time being, the following accepts foreign declarations conforming
552 -- to the FFI Addendum, Version 1.0 as well as pre-standard declarations
554 -- * a flag indicates whether pre-standard declarations have been used and
555 -- triggers a deprecation warning further down the road
557 -- NB: The first two rules could be combined into one by replacing `safety1'
558 -- with `safety'. However, the combined rule conflicts with the
561 fdecl :: { RdrNameHsDecl }
562 fdecl : srcloc 'import' callconv safety1 fspec {% mkImport $3 $4 $5 $1 }
563 | srcloc 'import' callconv fspec {% mkImport $3 (PlaySafe False) $4 $1 }
564 | srcloc 'export' callconv fspec {% mkExport $3 $4 $1 }
565 -- the following syntax is DEPRECATED
566 | srcloc fdecl1DEPRECATED { ForD ($2 True $1) }
567 | srcloc fdecl2DEPRECATED { $2 $1 }
569 fdecl1DEPRECATED :: { Bool -> SrcLoc -> ForeignDecl RdrName }
571 ----------- DEPRECATED label decls ------------
572 : 'label' ext_name varid '::' sigtype
573 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
574 (CLabel ($2 `orElse` mkExtName $3))) }
576 ----------- DEPRECATED ccall/stdcall decls ------------
578 -- NB: This business with the case expression below may seem overly
579 -- complicated, but it is necessary to avoid some conflicts.
581 -- DEPRECATED variant #1: lack of a calling convention specification
583 | 'import' {-no callconv-} ext_name safety varid_no_unsafe '::' sigtype
585 target = StaticTarget ($2 `orElse` mkExtName $4)
587 ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
588 (CFunction target)) }
590 -- DEPRECATED variant #2: external name consists of two separate strings
591 -- (module name and function name) (import)
592 | 'import' callconv STRING STRING safety varid_no_unsafe '::' sigtype
594 DNCall -> parseError "Illegal format of .NET foreign import"
595 CCall cconv -> returnP $
597 imp = CFunction (StaticTarget $4)
599 ForeignImport $6 $8 (CImport cconv $5 nilFS nilFS imp) }
601 -- DEPRECATED variant #3: `unsafe' after entity
602 | 'import' callconv STRING 'unsafe' varid_no_unsafe '::' sigtype
604 DNCall -> parseError "Illegal format of .NET foreign import"
605 CCall cconv -> returnP $
607 imp = CFunction (StaticTarget $3)
609 ForeignImport $5 $7 (CImport cconv PlayRisky nilFS nilFS imp) }
611 -- DEPRECATED variant #4: use of the special identifier `dynamic' without
612 -- an explicit calling convention (import)
613 | 'import' {-no callconv-} 'dynamic' safety varid_no_unsafe '::' sigtype
614 { ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
615 (CFunction DynamicTarget)) }
617 -- DEPRECATED variant #5: use of the special identifier `dynamic' (import)
618 | 'import' callconv 'dynamic' safety varid_no_unsafe '::' sigtype
620 DNCall -> parseError "Illegal format of .NET foreign import"
621 CCall cconv -> returnP $
622 ForeignImport $5 $7 (CImport cconv $4 nilFS nilFS
623 (CFunction DynamicTarget)) }
625 -- DEPRECATED variant #6: lack of a calling convention specification
627 | 'export' {-no callconv-} ext_name varid '::' sigtype
628 { ForeignExport $3 $5 (CExport (CExportStatic ($2 `orElse` mkExtName $3)
631 -- DEPRECATED variant #7: external name consists of two separate strings
632 -- (module name and function name) (export)
633 | 'export' callconv STRING STRING varid '::' sigtype
635 DNCall -> parseError "Illegal format of .NET foreign import"
636 CCall cconv -> returnP $
638 (CExport (CExportStatic $4 cconv)) }
640 -- DEPRECATED variant #8: use of the special identifier `dynamic' without
641 -- an explicit calling convention (export)
642 | 'export' {-no callconv-} 'dynamic' varid '::' sigtype
643 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
646 -- DEPRECATED variant #9: use of the special identifier `dynamic' (export)
647 | 'export' callconv 'dynamic' varid '::' sigtype
649 DNCall -> parseError "Illegal format of .NET foreign import"
650 CCall cconv -> returnP $
651 ForeignImport $4 $6 (CImport cconv (PlaySafe False) nilFS nilFS CWrapper) }
653 ----------- DEPRECATED .NET decls ------------
654 -- NB: removed the .NET call declaration, as it is entirely subsumed
655 -- by the new standard FFI declarations
657 fdecl2DEPRECATED :: { SrcLoc -> RdrNameHsDecl }
659 : 'import' 'dotnet' 'type' ext_name tycon
660 { \loc -> TyClD (ForeignType $5 $4 DNType loc) }
661 -- left this one unchanged for the moment as type imports are not
662 -- covered currently by the FFI standard -=chak
665 callconv :: { CallConv }
666 : 'stdcall' { CCall StdCallConv }
667 | 'ccall' { CCall CCallConv }
668 | 'dotnet' { DNCall }
671 : 'unsafe' { PlayRisky }
672 | 'safe' { PlaySafe False }
673 | 'threadsafe' { PlaySafe True }
674 | {- empty -} { PlaySafe False }
676 safety1 :: { Safety }
677 : 'unsafe' { PlayRisky }
678 | 'safe' { PlaySafe False }
679 | 'threadsafe' { PlaySafe True }
680 -- only needed to avoid conflicts with the DEPRECATED rules
682 fspec :: { (FastString, RdrName, RdrNameHsType) }
683 : STRING var '::' sigtype { ($1 , $2, $4) }
684 | var '::' sigtype { (nilFS, $1, $3) }
685 -- if the entity string is missing, it defaults to the empty string;
686 -- the meaning of an empty entity string depends on the calling
690 ext_name :: { Maybe CLabelString }
692 | STRING STRING { Just $2 } -- Ignore "module name" for now
693 | {- empty -} { Nothing }
696 -----------------------------------------------------------------------------
699 opt_sig :: { Maybe RdrNameHsType }
700 : {- empty -} { Nothing }
701 | '::' sigtype { Just $2 }
703 opt_asig :: { Maybe RdrNameHsType }
704 : {- empty -} { Nothing }
705 | '::' atype { Just $2 }
707 sigtypes :: { [RdrNameHsType] }
709 | sigtypes ',' sigtype { $3 : $1 }
711 sigtype :: { RdrNameHsType }
712 : ctype { mkHsForAllTy Nothing [] $1 }
714 sig_vars :: { [RdrName] }
715 : sig_vars ',' var { $3 : $1 }
718 -----------------------------------------------------------------------------
721 -- A ctype is a for-all type
722 ctype :: { RdrNameHsType }
723 : 'forall' tv_bndrs '.' ctype { mkHsForAllTy (Just $2) [] $4 }
724 | context '=>' type { mkHsForAllTy Nothing $1 $3 }
725 -- A type of form (context => type) is an *implicit* HsForAllTy
728 -- We parse a context as a btype so that we don't get reduce/reduce
729 -- errors in ctype. The basic problem is that
731 -- looks so much like a tuple type. We can't tell until we find the =>
732 context :: { RdrNameContext }
733 : btype {% checkContext $1 }
735 type :: { RdrNameHsType }
736 : ipvar '::' gentype { mkHsIParamTy $1 $3 }
739 gentype :: { RdrNameHsType }
741 | btype qtyconop gentype { HsOpTy $1 (HsTyOp $2) $3 }
742 | btype '`' tyvar '`' gentype { HsOpTy $1 (HsTyOp $3) $5 }
743 | btype '->' gentype { HsOpTy $1 HsArrow $3 }
745 btype :: { RdrNameHsType }
746 : btype atype { HsAppTy $1 $2 }
749 atype :: { RdrNameHsType }
750 : gtycon { HsTyVar $1 }
751 | tyvar { HsTyVar $1 }
752 | '(' type ',' comma_types1 ')' { HsTupleTy (mkHsTupCon tcName Boxed ($2:$4)) ($2:$4) }
753 | '(#' comma_types1 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
754 | '[' type ']' { HsListTy $2 }
755 | '[:' type ':]' { HsPArrTy $2 }
756 | '(' ctype ')' { HsParTy $2 }
757 | '(' ctype '::' kind ')' { HsKindSig $2 $4 }
759 | INTEGER { HsNumTy $1 }
761 -- An inst_type is what occurs in the head of an instance decl
762 -- e.g. (Foo a, Gaz b) => Wibble a b
763 -- It's kept as a single type, with a MonoDictTy at the right
764 -- hand corner, for convenience.
765 inst_type :: { RdrNameHsType }
766 : ctype {% checkInstType $1 }
768 comma_types0 :: { [RdrNameHsType] }
769 : comma_types1 { $1 }
772 comma_types1 :: { [RdrNameHsType] }
774 | type ',' comma_types1 { $1 : $3 }
776 tv_bndrs :: { [RdrNameHsTyVar] }
777 : tv_bndr tv_bndrs { $1 : $2 }
780 tv_bndr :: { RdrNameHsTyVar }
781 : tyvar { UserTyVar $1 }
782 | '(' tyvar '::' kind ')' { IfaceTyVar $2 $4 }
784 fds :: { [([RdrName], [RdrName])] }
786 | '|' fds1 { reverse $2 }
788 fds1 :: { [([RdrName], [RdrName])] }
789 : fds1 ',' fd { $3 : $1 }
792 fd :: { ([RdrName], [RdrName]) }
793 : varids0 '->' varids0 { (reverse $1, reverse $3) }
795 varids0 :: { [RdrName] }
797 | varids0 tyvar { $2 : $1 }
799 -----------------------------------------------------------------------------
804 | akind '->' kind { mkArrowKind $1 $3 }
807 : '*' { liftedTypeKind }
808 | '(' kind ')' { $2 }
811 -----------------------------------------------------------------------------
812 -- Datatype declarations
814 newconstr :: { RdrNameConDecl }
815 : srcloc conid atype { ConDecl $2 [] [] (PrefixCon [unbangedType $3]) $1 }
816 | srcloc conid '{' var '::' ctype '}'
817 { ConDecl $2 [] [] (RecCon [($4, unbangedType $6)]) $1 }
819 constrs :: { [RdrNameConDecl] }
820 : {- empty; a GHC extension -} { [] }
821 | '=' constrs1 { $2 }
823 constrs1 :: { [RdrNameConDecl] }
824 : constrs1 '|' constr { $3 : $1 }
827 constr :: { RdrNameConDecl }
828 : srcloc forall context '=>' constr_stuff
829 { ConDecl (fst $5) $2 $3 (snd $5) $1 }
830 | srcloc forall constr_stuff
831 { ConDecl (fst $3) $2 [] (snd $3) $1 }
833 forall :: { [RdrNameHsTyVar] }
834 : 'forall' tv_bndrs '.' { $2 }
837 constr_stuff :: { (RdrName, RdrNameConDetails) }
838 : btype {% mkPrefixCon $1 [] }
839 | btype '!' atype satypes {% mkPrefixCon $1 (BangType MarkedUserStrict $3 : $4) }
840 | oqtycon '{' '}' {% mkRecCon $1 [] }
841 | oqtycon '{' fielddecls '}' {% mkRecCon $1 $3 }
842 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
844 satypes :: { [RdrNameBangType] }
845 : atype satypes { unbangedType $1 : $2 }
846 | '!' atype satypes { BangType MarkedUserStrict $2 : $3 }
849 sbtype :: { RdrNameBangType }
850 : btype { unbangedType $1 }
851 | '!' atype { BangType MarkedUserStrict $2 }
853 fielddecls :: { [([RdrName],RdrNameBangType)] }
854 : fielddecl ',' fielddecls { $1 : $3 }
857 fielddecl :: { ([RdrName],RdrNameBangType) }
858 : sig_vars '::' stype { (reverse $1, $3) }
860 stype :: { RdrNameBangType }
861 : ctype { unbangedType $1 }
862 | '!' atype { BangType MarkedUserStrict $2 }
864 deriving :: { Maybe RdrNameContext }
865 : {- empty -} { Nothing }
866 | 'deriving' context { Just $2 }
867 -- Glasgow extension: allow partial
868 -- applications in derivings
870 -----------------------------------------------------------------------------
873 {- There's an awkward overlap with a type signature. Consider
874 f :: Int -> Int = ...rhs...
875 Then we can't tell whether it's a type signature or a value
876 definition with a result signature until we see the '='.
877 So we have to inline enough to postpone reductions until we know.
881 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
882 instead of qvar, we get another shift/reduce-conflict. Consider the
885 { (^^) :: Int->Int ; } Type signature; only var allowed
887 { (^^) :: Int->Int = ... ; } Value defn with result signature;
888 qvar allowed (because of instance decls)
890 We can't tell whether to reduce var to qvar until after we've read the signatures.
893 decl :: { RdrBinding }
895 | infixexp srcloc opt_sig rhs {% checkValDef $1 $3 $4 $2 }
897 rhs :: { RdrNameGRHSs }
898 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2) $4 placeHolderType }
899 | gdrhs wherebinds { GRHSs (reverse $1) $2 placeHolderType }
901 gdrhs :: { [RdrNameGRHS] }
902 : gdrhs gdrh { $2 : $1 }
905 gdrh :: { RdrNameGRHS }
906 : '|' srcloc quals '=' exp { GRHS (reverse (ResultStmt $5 $2 : $3)) $2 }
908 sigdecl :: { RdrBinding }
909 : infixexp srcloc '::' sigtype
910 {% checkValSig $1 $4 $2 }
911 -- See the above notes for why we need infixexp here
912 | var ',' sig_vars srcloc '::' sigtype
913 { mkSigDecls [ Sig n $6 $4 | n <- $1:$3 ] }
914 | srcloc infix prec ops { mkSigDecls [ FixSig (FixitySig n (Fixity $3 $2) $1)
916 | '{-# INLINE' srcloc activation qvar '#-}'
917 { RdrHsDecl (SigD (InlineSig True $4 $3 $2)) }
918 | '{-# NOINLINE' srcloc inverse_activation qvar '#-}'
919 { RdrHsDecl (SigD (InlineSig False $4 $3 $2)) }
920 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
921 { mkSigDecls [ SpecSig $3 t $2 | t <- $5] }
922 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
923 { RdrHsDecl (SigD (SpecInstSig $4 $2)) }
925 -----------------------------------------------------------------------------
928 exp :: { RdrNameHsExpr }
929 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
930 | infixexp 'with' dbinding { HsLet (IPBinds $3 True{-not a let-}) $1 }
933 infixexp :: { RdrNameHsExpr }
935 | infixexp qop exp10 { (OpApp $1 (HsVar $2)
936 (panic "fixity") $3 )}
938 exp10 :: { RdrNameHsExpr }
939 : '\\' srcloc aexp aexps opt_asig '->' srcloc exp
940 {% checkPatterns $2 ($3 : reverse $4) `thenP` \ ps ->
941 returnP (HsLam (Match ps $5
942 (GRHSs (unguardedRHS $8 $7)
943 EmptyBinds placeHolderType))) }
944 | 'let' binds 'in' exp { HsLet $2 $4 }
945 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
946 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
947 | '-' fexp { mkHsNegApp $2 }
948 | srcloc 'do' stmtlist {% checkDo $3 `thenP` \ stmts ->
949 returnP (mkHsDo DoExpr stmts $1) }
950 | srcloc 'mdo' stmtlist {% checkMDo $3 `thenP` \ stmts ->
951 returnP (mkHsDo MDoExpr stmts $1) }
953 | '_ccall_' ccallid aexps0 { HsCCall $2 $3 PlayRisky False placeHolderType }
954 | '_ccall_GC_' ccallid aexps0 { HsCCall $2 $3 (PlaySafe False) False placeHolderType }
955 | '_casm_' CLITLIT aexps0 { HsCCall $2 $3 PlayRisky True placeHolderType }
956 | '_casm_GC_' CLITLIT aexps0 { HsCCall $2 $3 (PlaySafe False) True placeHolderType }
958 | scc_annot exp { if opt_SccProfilingOn
962 | '{-# CORE' STRING '#-}' exp { HsCoreAnn $2 $4 } -- hdaume: core annotation
964 | reifyexp { HsReify $1 }
967 scc_annot :: { FastString }
968 : '_scc_' STRING { $2 }
969 | '{-# SCC' STRING '#-}' { $2 }
971 ccallid :: { FastString }
975 fexp :: { RdrNameHsExpr }
976 : fexp aexp { (HsApp $1 $2) }
979 reifyexp :: { HsReify RdrName }
980 : REIFY_DECL gtycon { Reify ReifyDecl $2 }
981 | REIFY_DECL qvar { Reify ReifyDecl $2 }
982 | REIFY_TYPE qcname { Reify ReifyType $2 }
983 | REIFY_FIXITY qcname { Reify ReifyFixity $2 }
985 aexps0 :: { [RdrNameHsExpr] }
986 : aexps { reverse $1 }
988 aexps :: { [RdrNameHsExpr] }
989 : aexps aexp { $2 : $1 }
992 aexp :: { RdrNameHsExpr }
993 : qvar '@' aexp { EAsPat $1 $3 }
994 | '~' aexp { ELazyPat $2 }
997 aexp1 :: { RdrNameHsExpr }
998 : aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1 (reverse $3)) }
1001 -- Here was the syntax for type applications that I was planning
1002 -- but there are difficulties (e.g. what order for type args)
1003 -- so it's not enabled yet.
1004 | qcname '{|' gentype '|}' { (HsApp (HsVar $1) (HsType $3)) }
1006 aexp2 :: { RdrNameHsExpr }
1007 : ipvar { HsIPVar $1 }
1008 | qcname { HsVar $1 }
1009 | literal { HsLit $1 }
1010 | INTEGER { HsOverLit (mkHsIntegral $1) }
1011 | RATIONAL { HsOverLit (mkHsFractional $1) }
1012 | '(' exp ')' { HsPar $2 }
1013 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) Boxed}
1014 | '(#' texps '#)' { ExplicitTuple (reverse $2) Unboxed }
1015 | '[' list ']' { $2 }
1016 | '[:' parr ':]' { $2 }
1017 | '(' infixexp qop ')' { (SectionL $2 (HsVar $3)) }
1018 | '(' qopm infixexp ')' { (SectionR $2 $3) }
1021 -- MetaHaskell Extension
1022 | srcloc ID_SPLICE { mkHsSplice (HsVar (mkUnqual varName $2)) $1 } -- $x
1023 | srcloc '$(' exp ')' { mkHsSplice $3 $1 } -- $( exp )
1024 | srcloc '[|' exp '|]' { HsBracket (ExpBr $3) $1 }
1025 | srcloc '[t|' ctype '|]' { HsBracket (TypBr $3) $1 }
1026 | srcloc '[p|' infixexp '|]' {% checkPattern $1 $3 `thenP` \p ->
1027 returnP (HsBracket (PatBr p) $1) }
1028 | srcloc '[d|' cvtopbody '|]' { HsBracket (DecBr (mkGroup $3)) $1 }
1030 cvtopbody :: { [RdrNameHsDecl] }
1031 : '{' cvtopdecls '}' { $2 }
1032 | layout_on cvtopdecls close { $2 }
1034 texps :: { [RdrNameHsExpr] }
1035 : texps ',' exp { $3 : $1 }
1039 -----------------------------------------------------------------------------
1042 -- The rules below are little bit contorted to keep lexps left-recursive while
1043 -- avoiding another shift/reduce-conflict.
1045 list :: { RdrNameHsExpr }
1046 : exp { ExplicitList placeHolderType [$1] }
1047 | lexps { ExplicitList placeHolderType (reverse $1) }
1048 | exp '..' { ArithSeqIn (From $1) }
1049 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
1050 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
1051 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
1052 | exp srcloc pquals {% let { body [qs] = qs;
1053 body qss = [ParStmt (map reverse qss)] }
1055 returnP ( mkHsDo ListComp
1056 (reverse (ResultStmt $1 $2 : body $3))
1061 lexps :: { [RdrNameHsExpr] }
1062 : lexps ',' exp { $3 : $1 }
1063 | exp ',' exp { [$3,$1] }
1065 -----------------------------------------------------------------------------
1066 -- List Comprehensions
1068 pquals :: { [[RdrNameStmt]] }
1069 : pquals '|' quals { $3 : $1 }
1070 | '|' quals { [$2] }
1072 quals :: { [RdrNameStmt] }
1073 : quals ',' stmt { $3 : $1 }
1076 -----------------------------------------------------------------------------
1077 -- Parallel array expressions
1079 -- The rules below are little bit contorted; see the list case for details.
1080 -- Note that, in contrast to lists, we only have finite arithmetic sequences.
1081 -- Moreover, we allow explicit arrays with no element (represented by the nil
1082 -- constructor in the list case).
1084 parr :: { RdrNameHsExpr }
1085 : { ExplicitPArr placeHolderType [] }
1086 | exp { ExplicitPArr placeHolderType [$1] }
1087 | lexps { ExplicitPArr placeHolderType
1089 | exp '..' exp { PArrSeqIn (FromTo $1 $3) }
1090 | exp ',' exp '..' exp { PArrSeqIn (FromThenTo $1 $3 $5) }
1091 | exp srcloc pquals {% let {
1098 (reverse (ResultStmt $1 $2
1103 -- We are reusing `lexps' and `pquals' from the list case.
1105 -----------------------------------------------------------------------------
1106 -- Case alternatives
1108 altslist :: { [RdrNameMatch] }
1109 : '{' alts '}' { reverse $2 }
1110 | layout_on alts close { reverse $2 }
1112 alts :: { [RdrNameMatch] }
1116 alts1 :: { [RdrNameMatch] }
1117 : alts1 ';' alt { $3 : $1 }
1121 alt :: { RdrNameMatch }
1122 : srcloc infixexp opt_sig ralt wherebinds
1123 {% (checkPattern $1 $2 `thenP` \p ->
1124 returnP (Match [p] $3
1125 (GRHSs $4 $5 placeHolderType)) )}
1127 ralt :: { [RdrNameGRHS] }
1128 : '->' srcloc exp { [GRHS [ResultStmt $3 $2] $2] }
1129 | gdpats { reverse $1 }
1131 gdpats :: { [RdrNameGRHS] }
1132 : gdpats gdpat { $2 : $1 }
1135 gdpat :: { RdrNameGRHS }
1136 : srcloc '|' quals '->' exp { GRHS (reverse (ResultStmt $5 $1:$3)) $1}
1138 -----------------------------------------------------------------------------
1139 -- Statement sequences
1141 stmtlist :: { [RdrNameStmt] }
1142 : '{' stmts '}' { $2 }
1143 | layout_on_for_do stmts close { $2 }
1145 -- do { ;; s ; s ; ; s ;; }
1146 -- The last Stmt should be a ResultStmt, but that's hard to enforce
1147 -- here, because we need too much lookahead if we see do { e ; }
1148 -- So we use ExprStmts throughout, and switch the last one over
1149 -- in ParseUtils.checkDo instead
1150 stmts :: { [RdrNameStmt] }
1151 : stmt stmts_help { $1 : $2 }
1153 | {- empty -} { [] }
1155 stmts_help :: { [RdrNameStmt] }
1157 | {- empty -} { [] }
1159 -- For typing stmts at the GHCi prompt, where
1160 -- the input may consist of just comments.
1161 maybe_stmt :: { Maybe RdrNameStmt }
1163 | {- nothing -} { Nothing }
1165 stmt :: { RdrNameStmt }
1166 : srcloc infixexp '<-' exp {% checkPattern $1 $2 `thenP` \p ->
1167 returnP (BindStmt p $4 $1) }
1168 | srcloc exp { ExprStmt $2 placeHolderType $1 }
1169 | srcloc 'let' binds { LetStmt $3 }
1171 -----------------------------------------------------------------------------
1172 -- Record Field Update/Construction
1174 fbinds :: { RdrNameHsRecordBinds }
1175 : fbinds ',' fbind { $3 : $1 }
1178 | {- empty -} { [] }
1180 fbind :: { (RdrName, RdrNameHsExpr) }
1181 : qvar '=' exp { ($1,$3) }
1183 -----------------------------------------------------------------------------
1184 -- Implicit Parameter Bindings
1186 dbinding :: { [(IPName RdrName, RdrNameHsExpr)] }
1187 : '{' dbinds '}' { $2 }
1188 | layout_on dbinds close { $2 }
1190 dbinds :: { [(IPName RdrName, RdrNameHsExpr)] }
1191 : dbinds ';' dbind { $3 : $1 }
1194 -- | {- empty -} { [] }
1196 dbind :: { (IPName RdrName, RdrNameHsExpr) }
1197 dbind : ipvar '=' exp { ($1, $3) }
1199 -----------------------------------------------------------------------------
1200 -- Variables, Constructors and Operators.
1202 identifier :: { RdrName }
1207 depreclist :: { [RdrName] }
1208 depreclist : deprec_var { [$1] }
1209 | deprec_var ',' depreclist { $1 : $3 }
1211 deprec_var :: { RdrName }
1212 deprec_var : var { $1 }
1215 gcon :: { RdrName } -- Data constructor namespace
1216 : sysdcon { nameRdrName (dataConName $1) }
1218 -- the case of '[:' ':]' is part of the production `parr'
1220 sysdcon :: { DataCon } -- Wired in data constructors
1221 : '(' ')' { unitDataCon }
1222 | '(' commas ')' { tupleCon Boxed $2 }
1223 | '[' ']' { nilDataCon }
1227 | '(' varsym ')' { $2 }
1231 | '(' varsym ')' { $2 }
1232 | '(' qvarsym1 ')' { $2 }
1233 -- We've inlined qvarsym here so that the decision about
1234 -- whether it's a qvar or a var can be postponed until
1235 -- *after* we see the close paren.
1237 ipvar :: { IPName RdrName }
1238 : IPDUPVARID { Dupable (mkUnqual varName $1) }
1239 | IPSPLITVARID { Linear (mkUnqual varName $1) }
1243 | '(' qconsym ')' { $2 }
1245 varop :: { RdrName }
1247 | '`' varid '`' { $2 }
1249 qvarop :: { RdrName }
1251 | '`' qvarid '`' { $2 }
1253 qvaropm :: { RdrName }
1254 : qvarsym_no_minus { $1 }
1255 | '`' qvarid '`' { $2 }
1257 conop :: { RdrName }
1259 | '`' conid '`' { $2 }
1261 qconop :: { RdrName }
1263 | '`' qconid '`' { $2 }
1265 -----------------------------------------------------------------------------
1266 -- Type constructors
1268 gtycon :: { RdrName } -- A "general" qualified tycon
1270 | '(' ')' { getRdrName unitTyCon }
1271 | '(' commas ')' { getRdrName (tupleTyCon Boxed $2) }
1272 | '(' '->' ')' { nameRdrName funTyConName }
1273 | '[' ']' { nameRdrName listTyConName }
1274 | '[:' ':]' { nameRdrName parrTyConName }
1276 oqtycon :: { RdrName } -- An "ordinary" qualified tycon
1278 | '(' qtyconsym ')' { $2 }
1280 qtyconop :: { RdrName } -- Qualified or unqualified
1282 | '`' qtycon '`' { $2 }
1284 tyconop :: { RdrName } -- Unqualified
1286 | '`' tycon '`' { $2 }
1288 qtycon :: { RdrName } -- Qualified or unqualified
1289 : QCONID { mkQual tcClsName $1 }
1292 tycon :: { RdrName } -- Unqualified
1293 : CONID { mkUnqual tcClsName $1 }
1295 qtyconsym :: { RdrName }
1296 : QCONSYM { mkQual tcClsName $1 }
1299 tyconsym :: { RdrName }
1300 : CONSYM { mkUnqual tcClsName $1 }
1302 -----------------------------------------------------------------------------
1305 op :: { RdrName } -- used in infix decls
1309 qop :: { RdrName {-HsExpr-} } -- used in sections
1313 qopm :: { RdrNameHsExpr } -- used in sections
1314 : qvaropm { HsVar $1 }
1315 | qconop { HsVar $1 }
1317 -----------------------------------------------------------------------------
1320 qvarid :: { RdrName }
1322 | QVARID { mkQual varName $1 }
1324 varid :: { RdrName }
1325 : varid_no_unsafe { $1 }
1326 | 'unsafe' { mkUnqual varName FSLIT("unsafe") }
1327 | 'safe' { mkUnqual varName FSLIT("safe") }
1328 | 'threadsafe' { mkUnqual varName FSLIT("threadsafe") }
1330 varid_no_unsafe :: { RdrName }
1331 : VARID { mkUnqual varName $1 }
1332 | special_id { mkUnqual varName $1 }
1333 | 'forall' { mkUnqual varName FSLIT("forall") }
1335 tyvar :: { RdrName }
1336 : VARID { mkUnqual tvName $1 }
1337 | special_id { mkUnqual tvName $1 }
1338 | 'unsafe' { mkUnqual tvName FSLIT("unsafe") }
1339 | 'safe' { mkUnqual tvName FSLIT("safe") }
1340 | 'threadsafe' { mkUnqual tvName FSLIT("threadsafe") }
1342 -- These special_ids are treated as keywords in various places,
1343 -- but as ordinary ids elsewhere. 'special_id' collects all these
1344 -- except 'unsafe' and 'forall' whose treatment differs depending on context
1345 special_id :: { UserFS }
1347 : 'as' { FSLIT("as") }
1348 | 'qualified' { FSLIT("qualified") }
1349 | 'hiding' { FSLIT("hiding") }
1350 | 'export' { FSLIT("export") }
1351 | 'label' { FSLIT("label") }
1352 | 'dynamic' { FSLIT("dynamic") }
1353 | 'stdcall' { FSLIT("stdcall") }
1354 | 'ccall' { FSLIT("ccall") }
1356 -----------------------------------------------------------------------------
1359 qvarsym :: { RdrName }
1363 qvarsym_no_minus :: { RdrName }
1364 : varsym_no_minus { $1 }
1367 qvarsym1 :: { RdrName }
1368 qvarsym1 : QVARSYM { mkQual varName $1 }
1370 varsym :: { RdrName }
1371 : varsym_no_minus { $1 }
1372 | '-' { mkUnqual varName FSLIT("-") }
1374 varsym_no_minus :: { RdrName } -- varsym not including '-'
1375 : VARSYM { mkUnqual varName $1 }
1376 | special_sym { mkUnqual varName $1 }
1379 -- See comments with special_id
1380 special_sym :: { UserFS }
1381 special_sym : '!' { FSLIT("!") }
1382 | '.' { FSLIT(".") }
1383 | '*' { FSLIT("*") }
1385 -----------------------------------------------------------------------------
1386 -- Data constructors
1388 qconid :: { RdrName } -- Qualified or unqualifiedb
1390 | QCONID { mkQual dataName $1 }
1392 conid :: { RdrName }
1393 : CONID { mkUnqual dataName $1 }
1395 qconsym :: { RdrName } -- Qualified or unqualified
1397 | QCONSYM { mkQual dataName $1 }
1399 consym :: { RdrName }
1400 : CONSYM { mkUnqual dataName $1 }
1402 -- ':' means only list cons
1403 | ':' { nameRdrName consDataConName }
1404 -- NB: SrcName because we are reading source
1407 -----------------------------------------------------------------------------
1410 literal :: { HsLit }
1411 : CHAR { HsChar $1 }
1412 | STRING { HsString $1 }
1413 | PRIMINTEGER { HsIntPrim $1 }
1414 | PRIMCHAR { HsCharPrim $1 }
1415 | PRIMSTRING { HsStringPrim $1 }
1416 | PRIMFLOAT { HsFloatPrim $1 }
1417 | PRIMDOUBLE { HsDoublePrim $1 }
1418 | CLITLIT { HsLitLit $1 placeHolderType }
1420 srcloc :: { SrcLoc } : {% getSrcLocP }
1422 -----------------------------------------------------------------------------
1426 : vccurly { () } -- context popped in lexer.
1427 | error {% popContext }
1429 layout_on :: { () } : {% layoutOn True{-strict-} }
1430 layout_on_for_do :: { () } : {% layoutOn False }
1432 -----------------------------------------------------------------------------
1433 -- Miscellaneous (mostly renamings)
1435 modid :: { ModuleName }
1436 : CONID { mkModuleNameFS $1 }
1437 | QCONID { mkModuleNameFS
1439 (unpackFS (fst $1) ++
1440 '.':unpackFS (snd $1)))
1444 : commas ',' { $1 + 1 }
1447 -----------------------------------------------------------------------------
1451 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)