2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.110 2002/10/11 14:46:04 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 )
23 import PrelNames ( mAIN_Name, funTyConName, listTyConName,
24 parrTyConName, consDataConName, nilDataConName )
25 import TysWiredIn ( unitTyCon, unitDataCon, tupleTyCon, tupleCon )
26 import ForeignCall ( Safety(..), CExportSpec(..),
27 CCallConv(..), CCallTarget(..), defaultCCallConv,
29 import OccName ( UserFS, varName, tcName, dataName, tcClsName, tvName )
30 import TyCon ( DataConDetails(..) )
31 import SrcLoc ( SrcLoc )
33 import CmdLineOpts ( opt_SccProfilingOn, opt_InPackage )
34 import Type ( Kind, mkArrowKind, liftedTypeKind )
35 import BasicTypes ( Boxity(..), Fixity(..), FixityDirection(..), IPName(..),
36 NewOrData(..), StrictnessMark(..), Activation(..),
41 import CStrings ( CLabelString )
43 import Maybes ( orElse )
49 -----------------------------------------------------------------------------
50 Conflicts: 29 shift/reduce, [SDM 19/9/2002]
52 10 for abiguity in 'if x then y else z + 1' [State 136]
53 (shift parses as 'if x then y else (z + 1)', as per longest-parse rule)
54 10 because op might be: : - ! * . `x` VARSYM CONSYM QVARSYM QCONSYM
56 1 for ambiguity in 'if x then y else z with ?x=3' [State 136]
57 (shift parses as 'if x then y else (z with ?x=3)'
59 1 for ambiguity in 'if x then y else z :: T' [State 136]
60 (shift parses as 'if x then y else (z :: T)', as per longest-parse rule)
62 8 for ambiguity in 'e :: a `b` c'. Does this mean [States 160,246]
66 1 for ambiguity in 'let ?x ...' [State 268]
67 the parser can't tell whether the ?x is the lhs of a normal binding or
68 an implicit binding. Fortunately resolving as shift gives it the only
69 sensible meaning, namely the lhs of an implicit binding.
71 1 for ambiguity in '{-# RULES "name" [ ... #-} [State 332]
72 we don't know whether the '[' starts the activation or not: it
73 might be the start of the declaration with the activation being
76 1 for ambiguity in '{-# RULES "name" forall = ... #-}' [State 394]
77 since 'forall' is a valid variable name, we don't know whether
78 to treat a forall on the input as the beginning of a quantifier
79 or the beginning of the rule itself. Resolving to shift means
80 it's always treated as a quantifier, hence the above is disallowed.
81 This saves explicitly defining a grammar for the rule lhs that
82 doesn't include 'forall'.
84 6 for conflicts between `fdecl' and `fdeclDEPRECATED', [States 384,385]
85 which are resolved correctly, and moreover,
86 should go away when `fdeclDEPRECATED' is removed.
88 -----------------------------------------------------------------------------
92 '_' { ITunderscore } -- Haskell keywords
97 'default' { ITdefault }
98 'deriving' { ITderiving }
101 'hiding' { IThiding }
103 'import' { ITimport }
106 'infixl' { ITinfixl }
107 'infixr' { ITinfixr }
108 'instance' { ITinstance }
110 'module' { ITmodule }
111 'newtype' { ITnewtype }
113 'qualified' { ITqualified }
117 '_scc_' { ITscc } -- ToDo: remove
119 'forall' { ITforall } -- GHC extension keywords
120 'foreign' { ITforeign }
121 'export' { ITexport }
123 'dynamic' { ITdynamic }
125 'threadsafe' { ITthreadsafe }
126 'unsafe' { ITunsafe }
129 'stdcall' { ITstdcallconv }
130 'ccall' { ITccallconv }
131 'dotnet' { ITdotnet }
132 '_ccall_' { ITccall (False, False, PlayRisky) }
133 '_ccall_GC_' { ITccall (False, False, PlaySafe False) }
134 '_casm_' { ITccall (False, True, PlayRisky) }
135 '_casm_GC_' { ITccall (False, True, PlaySafe False) }
137 '{-# SPECIALISE' { ITspecialise_prag }
138 '{-# SOURCE' { ITsource_prag }
139 '{-# INLINE' { ITinline_prag }
140 '{-# NOINLINE' { ITnoinline_prag }
141 '{-# RULES' { ITrules_prag }
142 '{-# SCC' { ITscc_prag }
143 '{-# DEPRECATED' { ITdeprecated_prag }
144 '#-}' { ITclose_prag }
147 '__interface' { ITinterface } -- interface keywords
148 '__export' { IT__export }
149 '__instimport' { ITinstimport }
150 '__forall' { IT__forall }
151 '__letrec' { ITletrec }
152 '__coerce' { ITcoerce }
153 '__depends' { ITdepends }
154 '__inline' { ITinline }
155 '__DEFAULT' { ITdefaultbranch }
157 '__integer' { ITinteger_lit }
158 '__float' { ITfloat_lit }
159 '__rational' { ITrational_lit }
160 '__addr' { ITaddr_lit }
161 '__label' { ITlabel_lit }
162 '__litlit' { ITlit_lit }
163 '__string' { ITstring_lit }
164 '__ccall' { ITccall $$ }
166 '__sccC' { ITsccAllCafs }
169 '__P' { ITspecialise }
172 '__S' { ITstrict $$ }
173 '__M' { ITcprinfo $$ }
176 '..' { ITdotdot } -- reserved symbols
192 '{' { ITocurly } -- special symbols
196 vccurly { ITvccurly } -- virtual close curly (from layout)
209 VARID { ITvarid $$ } -- identifiers
211 VARSYM { ITvarsym $$ }
212 CONSYM { ITconsym $$ }
213 QVARID { ITqvarid $$ }
214 QCONID { ITqconid $$ }
215 QVARSYM { ITqvarsym $$ }
216 QCONSYM { ITqconsym $$ }
218 IPDUPVARID { ITdupipvarid $$ } -- GHC extension
219 IPSPLITVARID { ITsplitipvarid $$ } -- GHC extension
222 STRING { ITstring $$ }
223 INTEGER { ITinteger $$ }
224 RATIONAL { ITrational $$ }
226 PRIMCHAR { ITprimchar $$ }
227 PRIMSTRING { ITprimstring $$ }
228 PRIMINTEGER { ITprimint $$ }
229 PRIMFLOAT { ITprimfloat $$ }
230 PRIMDOUBLE { ITprimdouble $$ }
231 CLITLIT { ITlitlit $$ }
234 '[|' { ITopenExpQuote }
235 '[p|' { ITopenPatQuote }
236 '[t|' { ITopenTypQuote }
237 '[d|' { ITopenDecQuote }
238 '|]' { ITcloseQuote }
239 ID_SPLICE { ITidEscape $$ } -- $x
240 '$(' { ITparenEscape } -- $( exp )
241 REIFY_TYPE { ITreifyType }
242 REIFY_DECL { ITreifyDecl }
243 REIFY_FIXITY { ITreifyFixity }
245 %monad { P } { thenP } { returnP }
246 %lexer { lexer } { ITeof }
247 %name parseModule module
248 %name parseStmt maybe_stmt
249 %name parseIdentifier identifier
250 %name parseIface iface
254 -----------------------------------------------------------------------------
257 -- The place for module deprecation is really too restrictive, but if it
258 -- was allowed at its natural place just before 'module', we get an ugly
259 -- s/r conflict with the second alternative. Another solution would be the
260 -- introduction of a new pragma DEPRECATED_MODULE, but this is not very nice,
261 -- either, and DEPRECATED is only expected to be used by people who really
262 -- know what they are doing. :-)
264 module :: { RdrNameHsModule }
265 : srcloc 'module' modid maybemoddeprec maybeexports 'where' body
266 { HsModule (mkHomeModule $3) Nothing $5 (fst $7) (snd $7) $4 $1 }
268 { HsModule (mkHomeModule mAIN_Name) Nothing Nothing
269 (fst $2) (snd $2) Nothing $1 }
271 maybemoddeprec :: { Maybe DeprecTxt }
272 : '{-# DEPRECATED' STRING '#-}' { Just $2 }
273 | {- empty -} { Nothing }
275 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
277 | layout_on top close { $2 }
279 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
280 : importdecls { (reverse $1,[]) }
281 | importdecls ';' cvtopdecls { (reverse $1,$3) }
282 | cvtopdecls { ([],$1) }
284 cvtopdecls :: { [RdrNameHsDecl] }
285 : topdecls { cvTopDecls $1 }
287 -----------------------------------------------------------------------------
288 -- Interfaces (.hi-boot files)
290 iface :: { ParsedIface }
291 : 'module' modid 'where' ifacebody
294 pi_pkg = opt_InPackage,
295 pi_vers = 1, -- Module version
297 pi_exports = (1,[($2,mkIfaceExports $4)]),
301 pi_decls = map (\x -> (1,x)) $4,
307 ifacebody :: { [RdrNameTyClDecl] }
308 : '{' ifacedecls '}' { $2 }
309 | layout_on ifacedecls close { $2 }
311 ifacedecls :: { [RdrNameTyClDecl] }
312 : ifacedecl ';' ifacedecls { $1 : $3 }
313 | ';' ifacedecls { $2 }
317 ifacedecl :: { RdrNameTyClDecl }
319 | srcloc var '::' sigtype { IfaceSig $2 $4 [] $1 }
321 -----------------------------------------------------------------------------
324 maybeexports :: { Maybe [RdrNameIE] }
325 : '(' exportlist ')' { Just $2 }
326 | {- empty -} { Nothing }
328 exportlist :: { [RdrNameIE] }
329 : exportlist ',' export { $3 : $1 }
330 | exportlist ',' { $1 }
334 -- No longer allow things like [] and (,,,) to be exported
335 -- They are built in syntax, always available
336 export :: { RdrNameIE }
338 | oqtycon { IEThingAbs $1 }
339 | oqtycon '(' '..' ')' { IEThingAll $1 }
340 | oqtycon '(' ')' { IEThingWith $1 [] }
341 | oqtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
342 | 'module' modid { IEModuleContents $2 }
344 qcnames :: { [RdrName] }
345 : qcnames ',' qcname { $3 : $1 }
348 qcname :: { RdrName } -- Variable or data constructor
352 -----------------------------------------------------------------------------
353 -- Import Declarations
355 -- import decls can be *empty*, or even just a string of semicolons
356 -- whereas topdecls must contain at least one topdecl.
358 importdecls :: { [RdrNameImportDecl] }
359 : importdecls ';' importdecl { $3 : $1 }
360 | importdecls ';' { $1 }
361 | importdecl { [ $1 ] }
364 importdecl :: { RdrNameImportDecl }
365 : 'import' srcloc maybe_src optqualified modid maybeas maybeimpspec
366 { ImportDecl $5 $3 $4 $6 $7 $2 }
368 maybe_src :: { IsBootInterface }
369 : '{-# SOURCE' '#-}' { True }
370 | {- empty -} { False }
372 optqualified :: { Bool }
373 : 'qualified' { True }
374 | {- empty -} { False }
376 maybeas :: { Maybe ModuleName }
377 : 'as' modid { Just $2 }
378 | {- empty -} { Nothing }
380 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
381 : impspec { Just $1 }
382 | {- empty -} { Nothing }
384 impspec :: { (Bool, [RdrNameIE]) }
385 : '(' exportlist ')' { (False, reverse $2) }
386 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
388 -----------------------------------------------------------------------------
389 -- Fixity Declarations
393 | INTEGER {% checkPrecP (fromInteger $1) }
395 infix :: { FixityDirection }
397 | 'infixl' { InfixL }
398 | 'infixr' { InfixR }
401 : ops ',' op { $3 : $1 }
404 -----------------------------------------------------------------------------
405 -- Top-Level Declarations
407 topdecls :: { [RdrBinding] } -- Reversed
408 : topdecls ';' topdecl { $3 : $1 }
409 | topdecls ';' { $1 }
412 topdecl :: { RdrBinding }
413 : tycl_decl { RdrHsDecl (TyClD $1) }
414 | srcloc 'instance' inst_type where
415 { let (binds,sigs) = cvMonoBindsAndSigs $4
416 in RdrHsDecl (InstD (InstDecl $3 binds sigs Nothing $1)) }
417 | srcloc 'default' '(' comma_types0 ')' { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
418 | 'foreign' fdecl { RdrHsDecl $2 }
419 | '{-# DEPRECATED' deprecations '#-}' { RdrBindings (reverse $2) }
420 | '{-# RULES' rules '#-}' { RdrBindings (reverse $2) }
421 | srcloc '$(' exp ')' { RdrHsDecl (SpliceD (SpliceDecl $3 $1)) }
424 tycl_decl :: { RdrNameTyClDecl }
425 : srcloc 'type' syn_hdr '=' ctype
426 -- Note ctype, not sigtype.
427 -- We allow an explicit for-all but we don't insert one
428 -- in type Foo a = (b,b)
429 -- Instead we just say b is out of scope
430 { let (tc,tvs) = $3 in TySynonym tc tvs $5 $1 }
433 | srcloc 'data' tycl_hdr constrs deriving
434 { mkTyData DataType $3 (DataCons (reverse $4)) $5 $1 }
436 | srcloc 'newtype' tycl_hdr '=' newconstr deriving
437 { mkTyData NewType $3 (DataCons [$5]) $6 $1 }
439 | srcloc 'class' tycl_hdr fds where
441 (binds,sigs) = cvMonoBindsAndSigs $5
443 mkClassDecl $3 $4 (map cvClassOpSig sigs) (Just binds) $1 }
445 syn_hdr :: { (RdrName, [RdrNameHsTyVar]) } -- We don't retain the syntax of an infix
446 -- type synonym declaration. Oh well.
447 : tycon tv_bndrs { ($1, $2) }
448 | tv_bndr tyconop tv_bndr { ($2, [$1,$3]) }
450 -- tycl_hdr parses the header of a type or class decl,
451 -- which takes the form
454 -- (Eq a, Ord b) => T a b
455 -- Rather a lot of inlining here, else we get reduce/reduce errors
456 tycl_hdr :: { (RdrNameContext, RdrName, [RdrNameHsTyVar]) }
457 : context '=>' type {% checkTyClHdr $3 `thenP` \ (tc,tvs) ->
458 returnP ($1, tc, tvs) }
459 | type {% checkTyClHdr $1 `thenP` \ (tc,tvs) ->
460 returnP ([], tc, tvs) }
462 -----------------------------------------------------------------------------
463 -- Nested declarations
465 decls :: { [RdrBinding] } -- Reversed
466 : decls ';' decl { $3 : $1 }
472 wherebinds :: { RdrNameHsBinds }
473 : where { cvBinds $1 }
475 where :: { [RdrBinding] } -- Reversed
476 : 'where' decllist { $2 }
479 decllist :: { [RdrBinding] } -- Reversed
480 : '{' decls '}' { $2 }
481 | layout_on decls close { $2 }
483 letbinds :: { RdrNameHsExpr -> RdrNameHsExpr }
484 : decllist { HsLet (cvBinds $1) }
485 | '{' dbinds '}' { \e -> HsWith e $2 False{-not with-} }
486 | layout_on dbinds close { \e -> HsWith e $2 False{-not with-} }
490 -----------------------------------------------------------------------------
491 -- Transformation Rules
493 rules :: { [RdrBinding] } -- Reversed
494 : rules ';' rule { $3 : $1 }
499 rule :: { RdrBinding }
500 : STRING activation rule_forall infixexp '=' srcloc exp
501 { RdrHsDecl (RuleD (HsRule $1 $2 $3 $4 $7 $6)) }
503 activation :: { Activation } -- Omitted means AlwaysActive
504 : {- empty -} { AlwaysActive }
505 | explicit_activation { $1 }
507 inverse_activation :: { Activation } -- Omitted means NeverActive
508 : {- empty -} { NeverActive }
509 | explicit_activation { $1 }
511 explicit_activation :: { Activation } -- In brackets
512 : '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
513 | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
515 rule_forall :: { [RdrNameRuleBndr] }
516 : 'forall' rule_var_list '.' { $2 }
519 rule_var_list :: { [RdrNameRuleBndr] }
521 | rule_var rule_var_list { $1 : $2 }
523 rule_var :: { RdrNameRuleBndr }
524 : varid { RuleBndr $1 }
525 | '(' varid '::' ctype ')' { RuleBndrSig $2 $4 }
527 -----------------------------------------------------------------------------
528 -- Deprecations (c.f. rules)
530 deprecations :: { [RdrBinding] } -- Reversed
531 : deprecations ';' deprecation { $3 : $1 }
532 | deprecations ';' { $1 }
533 | deprecation { [$1] }
536 -- SUP: TEMPORARY HACK, not checking for `module Foo'
537 deprecation :: { RdrBinding }
538 : srcloc depreclist STRING
540 [ RdrHsDecl (DeprecD (Deprecation n $3 $1)) | n <- $2 ] }
543 -----------------------------------------------------------------------------
544 -- Foreign import and export declarations
546 -- for the time being, the following accepts foreign declarations conforming
547 -- to the FFI Addendum, Version 1.0 as well as pre-standard declarations
549 -- * a flag indicates whether pre-standard declarations have been used and
550 -- triggers a deprecation warning further down the road
552 -- NB: The first two rules could be combined into one by replacing `safety1'
553 -- with `safety'. However, the combined rule conflicts with the
556 fdecl :: { RdrNameHsDecl }
557 fdecl : srcloc 'import' callconv safety1 fspec {% mkImport $3 $4 $5 $1 }
558 | srcloc 'import' callconv fspec {% mkImport $3 (PlaySafe False) $4 $1 }
559 | srcloc 'export' callconv fspec {% mkExport $3 $4 $1 }
560 -- the following syntax is DEPRECATED
561 | srcloc fdecl1DEPRECATED { ForD ($2 True $1) }
562 | srcloc fdecl2DEPRECATED { $2 $1 }
564 fdecl1DEPRECATED :: { Bool -> SrcLoc -> ForeignDecl RdrName }
566 ----------- DEPRECATED label decls ------------
567 : 'label' ext_name varid '::' sigtype
568 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
569 (CLabel ($2 `orElse` mkExtName $3))) }
571 ----------- DEPRECATED ccall/stdcall decls ------------
573 -- NB: This business with the case expression below may seem overly
574 -- complicated, but it is necessary to avoid some conflicts.
576 -- DEPRECATED variant #1: lack of a calling convention specification
578 | 'import' {-no callconv-} ext_name safety varid_no_unsafe '::' sigtype
580 target = StaticTarget ($2 `orElse` mkExtName $4)
582 ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
583 (CFunction target)) }
585 -- DEPRECATED variant #2: external name consists of two separate strings
586 -- (module name and function name) (import)
587 | 'import' callconv STRING STRING safety varid_no_unsafe '::' sigtype
589 DNCall -> parseError "Illegal format of .NET foreign import"
590 CCall cconv -> returnP $
592 imp = CFunction (StaticTarget $4)
594 ForeignImport $6 $8 (CImport cconv $5 nilFS nilFS imp) }
596 -- DEPRECATED variant #3: `unsafe' after entity
597 | 'import' callconv STRING 'unsafe' varid_no_unsafe '::' sigtype
599 DNCall -> parseError "Illegal format of .NET foreign import"
600 CCall cconv -> returnP $
602 imp = CFunction (StaticTarget $3)
604 ForeignImport $5 $7 (CImport cconv PlayRisky nilFS nilFS imp) }
606 -- DEPRECATED variant #4: use of the special identifier `dynamic' without
607 -- an explicit calling convention (import)
608 | 'import' {-no callconv-} 'dynamic' safety varid_no_unsafe '::' sigtype
609 { ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
610 (CFunction DynamicTarget)) }
612 -- DEPRECATED variant #5: use of the special identifier `dynamic' (import)
613 | 'import' callconv 'dynamic' safety varid_no_unsafe '::' sigtype
615 DNCall -> parseError "Illegal format of .NET foreign import"
616 CCall cconv -> returnP $
617 ForeignImport $5 $7 (CImport cconv $4 nilFS nilFS
618 (CFunction DynamicTarget)) }
620 -- DEPRECATED variant #6: lack of a calling convention specification
622 | 'export' {-no callconv-} ext_name varid '::' sigtype
623 { ForeignExport $3 $5 (CExport (CExportStatic ($2 `orElse` mkExtName $3)
626 -- DEPRECATED variant #7: external name consists of two separate strings
627 -- (module name and function name) (export)
628 | 'export' callconv STRING STRING varid '::' sigtype
630 DNCall -> parseError "Illegal format of .NET foreign import"
631 CCall cconv -> returnP $
633 (CExport (CExportStatic $4 cconv)) }
635 -- DEPRECATED variant #8: use of the special identifier `dynamic' without
636 -- an explicit calling convention (export)
637 | 'export' {-no callconv-} 'dynamic' varid '::' sigtype
638 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
641 -- DEPRECATED variant #9: use of the special identifier `dynamic' (export)
642 | 'export' callconv 'dynamic' varid '::' sigtype
644 DNCall -> parseError "Illegal format of .NET foreign import"
645 CCall cconv -> returnP $
646 ForeignImport $4 $6 (CImport cconv (PlaySafe False) nilFS nilFS CWrapper) }
648 ----------- DEPRECATED .NET decls ------------
649 -- NB: removed the .NET call declaration, as it is entirely subsumed
650 -- by the new standard FFI declarations
652 fdecl2DEPRECATED :: { SrcLoc -> RdrNameHsDecl }
654 : 'import' 'dotnet' 'type' ext_name tycon
655 { \loc -> TyClD (ForeignType $5 $4 DNType loc) }
656 -- left this one unchanged for the moment as type imports are not
657 -- covered currently by the FFI standard -=chak
660 callconv :: { CallConv }
661 : 'stdcall' { CCall StdCallConv }
662 | 'ccall' { CCall CCallConv }
663 | 'dotnet' { DNCall }
666 : 'unsafe' { PlayRisky }
667 | 'safe' { PlaySafe False }
668 | 'threadsafe' { PlaySafe True }
669 | {- empty -} { PlaySafe False }
671 safety1 :: { Safety }
672 : 'unsafe' { PlayRisky }
673 | 'safe' { PlaySafe False }
674 | 'threadsafe' { PlaySafe True }
675 -- only needed to avoid conflicts with the DEPRECATED rules
677 fspec :: { (FastString, RdrName, RdrNameHsType) }
678 : STRING var '::' sigtype { ($1 , $2, $4) }
679 | var '::' sigtype { (nilFS, $1, $3) }
680 -- if the entity string is missing, it defaults to the empty string;
681 -- the meaning of an empty entity string depends on the calling
685 ext_name :: { Maybe CLabelString }
687 | STRING STRING { Just $2 } -- Ignore "module name" for now
688 | {- empty -} { Nothing }
691 -----------------------------------------------------------------------------
694 opt_sig :: { Maybe RdrNameHsType }
695 : {- empty -} { Nothing }
696 | '::' sigtype { Just $2 }
698 opt_asig :: { Maybe RdrNameHsType }
699 : {- empty -} { Nothing }
700 | '::' atype { Just $2 }
702 sigtypes :: { [RdrNameHsType] }
704 | sigtypes ',' sigtype { $3 : $1 }
706 sigtype :: { RdrNameHsType }
707 : ctype { mkHsForAllTy Nothing [] $1 }
709 sig_vars :: { [RdrName] }
710 : sig_vars ',' var { $3 : $1 }
713 -----------------------------------------------------------------------------
716 -- A ctype is a for-all type
717 ctype :: { RdrNameHsType }
718 : 'forall' tv_bndrs '.' ctype { mkHsForAllTy (Just $2) [] $4 }
719 | context '=>' type { mkHsForAllTy Nothing $1 $3 }
720 -- A type of form (context => type) is an *implicit* HsForAllTy
723 -- We parse a context as a btype so that we don't get reduce/reduce
724 -- errors in ctype. The basic problem is that
726 -- looks so much like a tuple type. We can't tell until we find the =>
727 context :: { RdrNameContext }
728 : btype {% checkContext $1 }
730 type :: { RdrNameHsType }
731 : ipvar '::' gentype { mkHsIParamTy $1 $3 }
734 gentype :: { RdrNameHsType }
736 | btype qtyconop gentype { HsOpTy $1 (HsTyOp $2) $3 }
737 | btype '`' tyvar '`' gentype { HsOpTy $1 (HsTyOp $3) $5 }
738 | btype '->' gentype { HsOpTy $1 HsArrow $3 }
740 btype :: { RdrNameHsType }
741 : btype atype { HsAppTy $1 $2 }
744 atype :: { RdrNameHsType }
745 : gtycon { HsTyVar $1 }
746 | tyvar { HsTyVar $1 }
747 | '(' type ',' comma_types1 ')' { HsTupleTy (mkHsTupCon tcName Boxed ($2:$4)) ($2:$4) }
748 | '(#' comma_types1 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
749 | '[' type ']' { HsListTy $2 }
750 | '[:' type ':]' { HsPArrTy $2 }
751 | '(' ctype ')' { HsParTy $2 }
752 | '(' ctype '::' kind ')' { HsKindSig $2 $4 }
754 | INTEGER { HsNumTy $1 }
756 -- An inst_type is what occurs in the head of an instance decl
757 -- e.g. (Foo a, Gaz b) => Wibble a b
758 -- It's kept as a single type, with a MonoDictTy at the right
759 -- hand corner, for convenience.
760 inst_type :: { RdrNameHsType }
761 : ctype {% checkInstType $1 }
763 comma_types0 :: { [RdrNameHsType] }
764 : comma_types1 { $1 }
767 comma_types1 :: { [RdrNameHsType] }
769 | type ',' comma_types1 { $1 : $3 }
771 tv_bndrs :: { [RdrNameHsTyVar] }
772 : tv_bndr tv_bndrs { $1 : $2 }
775 tv_bndr :: { RdrNameHsTyVar }
776 : tyvar { UserTyVar $1 }
777 | '(' tyvar '::' kind ')' { IfaceTyVar $2 $4 }
779 fds :: { [([RdrName], [RdrName])] }
781 | '|' fds1 { reverse $2 }
783 fds1 :: { [([RdrName], [RdrName])] }
784 : fds1 ',' fd { $3 : $1 }
787 fd :: { ([RdrName], [RdrName]) }
788 : varids0 '->' varids0 { (reverse $1, reverse $3) }
790 varids0 :: { [RdrName] }
792 | varids0 tyvar { $2 : $1 }
794 -----------------------------------------------------------------------------
799 | akind '->' kind { mkArrowKind $1 $3 }
802 : '*' { liftedTypeKind }
803 | '(' kind ')' { $2 }
806 -----------------------------------------------------------------------------
807 -- Datatype declarations
809 newconstr :: { RdrNameConDecl }
810 : srcloc conid atype { ConDecl $2 [] [] (PrefixCon [unbangedType $3]) $1 }
811 | srcloc conid '{' var '::' ctype '}'
812 { ConDecl $2 [] [] (RecCon [($4, unbangedType $6)]) $1 }
814 constrs :: { [RdrNameConDecl] }
815 : {- empty; a GHC extension -} { [] }
816 | '=' constrs1 { $2 }
818 constrs1 :: { [RdrNameConDecl] }
819 : constrs1 '|' constr { $3 : $1 }
822 constr :: { RdrNameConDecl }
823 : srcloc forall context '=>' constr_stuff
824 { ConDecl (fst $5) $2 $3 (snd $5) $1 }
825 | srcloc forall constr_stuff
826 { ConDecl (fst $3) $2 [] (snd $3) $1 }
828 forall :: { [RdrNameHsTyVar] }
829 : 'forall' tv_bndrs '.' { $2 }
832 constr_stuff :: { (RdrName, RdrNameConDetails) }
833 : btype {% mkPrefixCon $1 [] }
834 | btype '!' atype satypes {% mkPrefixCon $1 (BangType MarkedUserStrict $3 : $4) }
835 | oqtycon '{' '}' {% mkRecCon $1 [] }
836 | oqtycon '{' fielddecls '}' {% mkRecCon $1 $3 }
837 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
839 satypes :: { [RdrNameBangType] }
840 : atype satypes { unbangedType $1 : $2 }
841 | '!' atype satypes { BangType MarkedUserStrict $2 : $3 }
844 sbtype :: { RdrNameBangType }
845 : btype { unbangedType $1 }
846 | '!' atype { BangType MarkedUserStrict $2 }
848 fielddecls :: { [([RdrName],RdrNameBangType)] }
849 : fielddecl ',' fielddecls { $1 : $3 }
852 fielddecl :: { ([RdrName],RdrNameBangType) }
853 : sig_vars '::' stype { (reverse $1, $3) }
855 stype :: { RdrNameBangType }
856 : ctype { unbangedType $1 }
857 | '!' atype { BangType MarkedUserStrict $2 }
859 deriving :: { Maybe RdrNameContext }
860 : {- empty -} { Nothing }
861 | 'deriving' context { Just $2 }
862 -- Glasgow extension: allow partial
863 -- applications in derivings
865 -----------------------------------------------------------------------------
868 {- There's an awkward overlap with a type signature. Consider
869 f :: Int -> Int = ...rhs...
870 Then we can't tell whether it's a type signature or a value
871 definition with a result signature until we see the '='.
872 So we have to inline enough to postpone reductions until we know.
876 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
877 instead of qvar, we get another shift/reduce-conflict. Consider the
880 { (^^) :: Int->Int ; } Type signature; only var allowed
882 { (^^) :: Int->Int = ... ; } Value defn with result signature;
883 qvar allowed (because of instance decls)
885 We can't tell whether to reduce var to qvar until after we've read the signatures.
888 decl :: { RdrBinding }
890 | infixexp srcloc opt_sig rhs {% checkValDef $1 $3 $4 $2 }
892 rhs :: { RdrNameGRHSs }
893 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2) $4 placeHolderType }
894 | gdrhs wherebinds { GRHSs (reverse $1) $2 placeHolderType }
896 gdrhs :: { [RdrNameGRHS] }
897 : gdrhs gdrh { $2 : $1 }
900 gdrh :: { RdrNameGRHS }
901 : '|' srcloc quals '=' exp { GRHS (reverse (ResultStmt $5 $2 : $3)) $2 }
903 sigdecl :: { RdrBinding }
904 : infixexp srcloc '::' sigtype
905 {% checkValSig $1 $4 $2 }
906 -- See the above notes for why we need infixexp here
907 | var ',' sig_vars srcloc '::' sigtype
908 { mkSigDecls [ Sig n $6 $4 | n <- $1:$3 ] }
909 | srcloc infix prec ops { mkSigDecls [ FixSig (FixitySig n (Fixity $3 $2) $1)
911 | '{-# INLINE' srcloc activation qvar '#-}'
912 { RdrHsDecl (SigD (InlineSig True $4 $3 $2)) }
913 | '{-# NOINLINE' srcloc inverse_activation qvar '#-}'
914 { RdrHsDecl (SigD (InlineSig False $4 $3 $2)) }
915 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
916 { mkSigDecls [ SpecSig $3 t $2 | t <- $5] }
917 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
918 { RdrHsDecl (SigD (SpecInstSig $4 $2)) }
920 -----------------------------------------------------------------------------
923 exp :: { RdrNameHsExpr }
924 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
925 | infixexp 'with' dbinding { HsWith $1 $3 True{-not a let-} }
928 infixexp :: { RdrNameHsExpr }
930 | infixexp qop exp10 { (OpApp $1 (HsVar $2)
931 (panic "fixity") $3 )}
933 exp10 :: { RdrNameHsExpr }
934 : '\\' srcloc aexp aexps opt_asig '->' srcloc exp
935 {% checkPatterns $2 ($3 : reverse $4) `thenP` \ ps ->
936 returnP (HsLam (Match ps $5
937 (GRHSs (unguardedRHS $8 $7)
938 EmptyBinds placeHolderType))) }
939 | 'let' letbinds 'in' exp { $2 $4 }
940 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
941 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
942 | '-' fexp { mkHsNegApp $2 }
943 | srcloc 'do' stmtlist {% checkDo $3 `thenP` \ stmts ->
944 returnP (mkHsDo DoExpr stmts $1) }
945 | srcloc 'mdo' stmtlist {% checkMDo $3 `thenP` \ stmts ->
946 returnP (mkHsDo MDoExpr stmts $1) }
948 | '_ccall_' ccallid aexps0 { HsCCall $2 $3 PlayRisky False placeHolderType }
949 | '_ccall_GC_' ccallid aexps0 { HsCCall $2 $3 (PlaySafe False) False placeHolderType }
950 | '_casm_' CLITLIT aexps0 { HsCCall $2 $3 PlayRisky True placeHolderType }
951 | '_casm_GC_' CLITLIT aexps0 { HsCCall $2 $3 (PlaySafe False) True placeHolderType }
953 | scc_annot exp { if opt_SccProfilingOn
957 | reifyexp { HsReify $1 }
960 scc_annot :: { FastString }
961 : '_scc_' STRING { $2 }
962 | '{-# SCC' STRING '#-}' { $2 }
964 ccallid :: { FastString }
968 fexp :: { RdrNameHsExpr }
969 : fexp aexp { (HsApp $1 $2) }
972 reifyexp :: { HsReify RdrName }
973 : REIFY_DECL gtycon { Reify ReifyDecl $2 }
974 | REIFY_DECL qvar { Reify ReifyDecl $2 }
975 | REIFY_TYPE qcname { Reify ReifyType $2 }
976 | REIFY_FIXITY qcname { Reify ReifyFixity $2 }
978 aexps0 :: { [RdrNameHsExpr] }
979 : aexps { reverse $1 }
981 aexps :: { [RdrNameHsExpr] }
982 : aexps aexp { $2 : $1 }
985 aexp :: { RdrNameHsExpr }
986 : qvar '@' aexp { EAsPat $1 $3 }
987 | '~' aexp { ELazyPat $2 }
990 aexp1 :: { RdrNameHsExpr }
991 : aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1 (reverse $3)) }
994 -- Here was the syntax for type applications that I was planning
995 -- but there are difficulties (e.g. what order for type args)
996 -- so it's not enabled yet.
997 | qcname '{|' gentype '|}' { (HsApp (HsVar $1) (HsType $3)) }
999 aexp2 :: { RdrNameHsExpr }
1000 : ipvar { HsIPVar $1 }
1001 | qcname { HsVar $1 }
1002 | literal { HsLit $1 }
1003 | INTEGER { HsOverLit (mkHsIntegral $1) }
1004 | RATIONAL { HsOverLit (mkHsFractional $1) }
1005 | '(' exp ')' { HsPar $2 }
1006 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) Boxed}
1007 | '(#' texps '#)' { ExplicitTuple (reverse $2) Unboxed }
1008 | '[' list ']' { $2 }
1009 | '[:' parr ':]' { $2 }
1010 | '(' infixexp qop ')' { (SectionL $2 (HsVar $3)) }
1011 | '(' qopm infixexp ')' { (SectionR $2 $3) }
1014 -- MetaHaskell Extension
1015 | srcloc ID_SPLICE { mkHsSplice (HsVar (mkUnqual varName $2)) $1 } -- $x
1016 | srcloc '$(' exp ')' { mkHsSplice $3 $1 } -- $( exp )
1017 | srcloc '[|' exp '|]' { HsBracket (ExpBr $3) $1 }
1018 | srcloc '[t|' ctype '|]' { HsBracket (TypBr $3) $1 }
1019 | srcloc '[p|' infixexp '|]' {% checkPattern $1 $3 `thenP` \p ->
1020 returnP (HsBracket (PatBr p) $1) }
1021 | srcloc '[d|' cvtopdecls '|]' { HsBracket (DecBr (mkGroup $3)) $1 }
1024 texps :: { [RdrNameHsExpr] }
1025 : texps ',' exp { $3 : $1 }
1029 -----------------------------------------------------------------------------
1032 -- The rules below are little bit contorted to keep lexps left-recursive while
1033 -- avoiding another shift/reduce-conflict.
1035 list :: { RdrNameHsExpr }
1036 : exp { ExplicitList placeHolderType [$1] }
1037 | lexps { ExplicitList placeHolderType (reverse $1) }
1038 | exp '..' { ArithSeqIn (From $1) }
1039 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
1040 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
1041 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
1042 | exp srcloc pquals {% let { body [qs] = qs;
1043 body qss = [ParStmt (map reverse qss)] }
1045 returnP ( mkHsDo ListComp
1046 (reverse (ResultStmt $1 $2 : body $3))
1051 lexps :: { [RdrNameHsExpr] }
1052 : lexps ',' exp { $3 : $1 }
1053 | exp ',' exp { [$3,$1] }
1055 -----------------------------------------------------------------------------
1056 -- List Comprehensions
1058 pquals :: { [[RdrNameStmt]] }
1059 : pquals '|' quals { $3 : $1 }
1060 | '|' quals { [$2] }
1062 quals :: { [RdrNameStmt] }
1063 : quals ',' stmt { $3 : $1 }
1066 -----------------------------------------------------------------------------
1067 -- Parallel array expressions
1069 -- The rules below are little bit contorted; see the list case for details.
1070 -- Note that, in contrast to lists, we only have finite arithmetic sequences.
1071 -- Moreover, we allow explicit arrays with no element (represented by the nil
1072 -- constructor in the list case).
1074 parr :: { RdrNameHsExpr }
1075 : { ExplicitPArr placeHolderType [] }
1076 | exp { ExplicitPArr placeHolderType [$1] }
1077 | lexps { ExplicitPArr placeHolderType
1079 | exp '..' exp { PArrSeqIn (FromTo $1 $3) }
1080 | exp ',' exp '..' exp { PArrSeqIn (FromThenTo $1 $3 $5) }
1081 | exp srcloc pquals {% let {
1088 (reverse (ResultStmt $1 $2
1093 -- We are reusing `lexps' and `pquals' from the list case.
1095 -----------------------------------------------------------------------------
1096 -- Case alternatives
1098 altslist :: { [RdrNameMatch] }
1099 : '{' alts '}' { reverse $2 }
1100 | layout_on alts close { reverse $2 }
1102 alts :: { [RdrNameMatch] }
1106 alts1 :: { [RdrNameMatch] }
1107 : alts1 ';' alt { $3 : $1 }
1111 alt :: { RdrNameMatch }
1112 : srcloc infixexp opt_sig ralt wherebinds
1113 {% (checkPattern $1 $2 `thenP` \p ->
1114 returnP (Match [p] $3
1115 (GRHSs $4 $5 placeHolderType)) )}
1117 ralt :: { [RdrNameGRHS] }
1118 : '->' srcloc exp { [GRHS [ResultStmt $3 $2] $2] }
1119 | gdpats { reverse $1 }
1121 gdpats :: { [RdrNameGRHS] }
1122 : gdpats gdpat { $2 : $1 }
1125 gdpat :: { RdrNameGRHS }
1126 : srcloc '|' quals '->' exp { GRHS (reverse (ResultStmt $5 $1:$3)) $1}
1128 -----------------------------------------------------------------------------
1129 -- Statement sequences
1131 stmtlist :: { [RdrNameStmt] }
1132 : '{' stmts '}' { $2 }
1133 | layout_on_for_do stmts close { $2 }
1135 -- do { ;; s ; s ; ; s ;; }
1136 -- The last Stmt should be a ResultStmt, but that's hard to enforce
1137 -- here, because we need too much lookahead if we see do { e ; }
1138 -- So we use ExprStmts throughout, and switch the last one over
1139 -- in ParseUtils.checkDo instead
1140 stmts :: { [RdrNameStmt] }
1141 : stmt stmts_help { $1 : $2 }
1143 | {- empty -} { [] }
1145 stmts_help :: { [RdrNameStmt] }
1147 | {- empty -} { [] }
1149 -- For typing stmts at the GHCi prompt, where
1150 -- the input may consist of just comments.
1151 maybe_stmt :: { Maybe RdrNameStmt }
1153 | {- nothing -} { Nothing }
1155 stmt :: { RdrNameStmt }
1156 : srcloc infixexp '<-' exp {% checkPattern $1 $2 `thenP` \p ->
1157 returnP (BindStmt p $4 $1) }
1158 | srcloc exp { ExprStmt $2 placeHolderType $1 }
1159 | srcloc 'let' decllist { LetStmt (cvBinds $3) }
1161 -----------------------------------------------------------------------------
1162 -- Record Field Update/Construction
1164 fbinds :: { RdrNameHsRecordBinds }
1165 : fbinds ',' fbind { $3 : $1 }
1168 | {- empty -} { [] }
1170 fbind :: { (RdrName, RdrNameHsExpr) }
1171 : qvar '=' exp { ($1,$3) }
1173 -----------------------------------------------------------------------------
1174 -- Implicit Parameter Bindings
1176 dbinding :: { [(IPName RdrName, RdrNameHsExpr)] }
1177 : '{' dbinds '}' { $2 }
1178 | layout_on dbinds close { $2 }
1180 dbinds :: { [(IPName RdrName, RdrNameHsExpr)] }
1181 : dbinds ';' dbind { $3 : $1 }
1184 -- | {- empty -} { [] }
1186 dbind :: { (IPName RdrName, RdrNameHsExpr) }
1187 dbind : ipvar '=' exp { ($1, $3) }
1189 -----------------------------------------------------------------------------
1190 -- Variables, Constructors and Operators.
1192 identifier :: { RdrName }
1197 depreclist :: { [RdrName] }
1198 depreclist : deprec_var { [$1] }
1199 | deprec_var ',' depreclist { $1 : $3 }
1201 deprec_var :: { RdrName }
1202 deprec_var : var { $1 }
1205 gcon :: { RdrName } -- Data constructor namespace
1208 -- the case of '[:' ':]' is part of the production `parr'
1210 sysdcon :: { RdrName } -- Data constructor namespace
1211 : '(' ')' { getRdrName unitDataCon }
1212 | '(' commas ')' { getRdrName (tupleCon Boxed $2) }
1213 | '[' ']' { nameRdrName nilDataConName }
1217 | '(' varsym ')' { $2 }
1221 | '(' varsym ')' { $2 }
1222 | '(' qvarsym1 ')' { $2 }
1223 -- We've inlined qvarsym here so that the decision about
1224 -- whether it's a qvar or a var can be postponed until
1225 -- *after* we see the close paren.
1227 ipvar :: { IPName RdrName }
1228 : IPDUPVARID { Dupable (mkUnqual varName $1) }
1229 | IPSPLITVARID { Linear (mkUnqual varName $1) }
1233 | '(' qconsym ')' { $2 }
1235 varop :: { RdrName }
1237 | '`' varid '`' { $2 }
1239 qvarop :: { RdrName }
1241 | '`' qvarid '`' { $2 }
1243 qvaropm :: { RdrName }
1244 : qvarsym_no_minus { $1 }
1245 | '`' qvarid '`' { $2 }
1247 conop :: { RdrName }
1249 | '`' conid '`' { $2 }
1251 qconop :: { RdrName }
1253 | '`' qconid '`' { $2 }
1255 -----------------------------------------------------------------------------
1256 -- Type constructors
1258 gtycon :: { RdrName } -- A "general" qualified tycon
1260 | '(' ')' { getRdrName unitTyCon }
1261 | '(' commas ')' { getRdrName (tupleTyCon Boxed $2) }
1262 | '(' '->' ')' { nameRdrName funTyConName }
1263 | '[' ']' { nameRdrName listTyConName }
1264 | '[:' ':]' { nameRdrName parrTyConName }
1266 oqtycon :: { RdrName } -- An "ordinary" qualified tycon
1268 | '(' qtyconsym ')' { $2 }
1270 qtyconop :: { RdrName } -- Qualified or unqualified
1272 | '`' qtycon '`' { $2 }
1274 tyconop :: { RdrName } -- Unqualified
1276 | '`' tycon '`' { $2 }
1278 qtycon :: { RdrName } -- Qualified or unqualified
1279 : QCONID { mkQual tcClsName $1 }
1282 tycon :: { RdrName } -- Unqualified
1283 : CONID { mkUnqual tcClsName $1 }
1285 qtyconsym :: { RdrName }
1286 : QCONSYM { mkQual tcClsName $1 }
1289 tyconsym :: { RdrName }
1290 : CONSYM { mkUnqual tcClsName $1 }
1292 -----------------------------------------------------------------------------
1295 op :: { RdrName } -- used in infix decls
1299 qop :: { RdrName {-HsExpr-} } -- used in sections
1303 qopm :: { RdrNameHsExpr } -- used in sections
1304 : qvaropm { HsVar $1 }
1305 | qconop { HsVar $1 }
1307 -----------------------------------------------------------------------------
1310 qvarid :: { RdrName }
1312 | QVARID { mkQual varName $1 }
1314 varid :: { RdrName }
1315 : varid_no_unsafe { $1 }
1316 | 'unsafe' { mkUnqual varName FSLIT("unsafe") }
1317 | 'safe' { mkUnqual varName FSLIT("safe") }
1318 | 'threadsafe' { mkUnqual varName FSLIT("threadsafe") }
1320 varid_no_unsafe :: { RdrName }
1321 : VARID { mkUnqual varName $1 }
1322 | special_id { mkUnqual varName $1 }
1323 | 'forall' { mkUnqual varName FSLIT("forall") }
1325 tyvar :: { RdrName }
1326 : VARID { mkUnqual tvName $1 }
1327 | special_id { mkUnqual tvName $1 }
1328 | 'unsafe' { mkUnqual tvName FSLIT("unsafe") }
1329 | 'safe' { mkUnqual tvName FSLIT("safe") }
1330 | 'threadsafe' { mkUnqual tvName FSLIT("threadsafe") }
1332 -- These special_ids are treated as keywords in various places,
1333 -- but as ordinary ids elsewhere. 'special_id' collects all these
1334 -- except 'unsafe' and 'forall' whose treatment differs depending on context
1335 special_id :: { UserFS }
1337 : 'as' { FSLIT("as") }
1338 | 'qualified' { FSLIT("qualified") }
1339 | 'hiding' { FSLIT("hiding") }
1340 | 'export' { FSLIT("export") }
1341 | 'label' { FSLIT("label") }
1342 | 'dynamic' { FSLIT("dynamic") }
1343 | 'stdcall' { FSLIT("stdcall") }
1344 | 'ccall' { FSLIT("ccall") }
1346 -----------------------------------------------------------------------------
1349 qvarsym :: { RdrName }
1353 qvarsym_no_minus :: { RdrName }
1354 : varsym_no_minus { $1 }
1357 qvarsym1 :: { RdrName }
1358 qvarsym1 : QVARSYM { mkQual varName $1 }
1360 varsym :: { RdrName }
1361 : varsym_no_minus { $1 }
1362 | '-' { mkUnqual varName FSLIT("-") }
1364 varsym_no_minus :: { RdrName } -- varsym not including '-'
1365 : VARSYM { mkUnqual varName $1 }
1366 | special_sym { mkUnqual varName $1 }
1369 -- See comments with special_id
1370 special_sym :: { UserFS }
1371 special_sym : '!' { FSLIT("!") }
1372 | '.' { FSLIT(".") }
1373 | '*' { FSLIT("*") }
1375 -----------------------------------------------------------------------------
1376 -- Data constructors
1378 qconid :: { RdrName } -- Qualified or unqualifiedb
1380 | QCONID { mkQual dataName $1 }
1382 conid :: { RdrName }
1383 : CONID { mkUnqual dataName $1 }
1385 qconsym :: { RdrName } -- Qualified or unqualified
1387 | QCONSYM { mkQual dataName $1 }
1389 consym :: { RdrName }
1390 : CONSYM { mkUnqual dataName $1 }
1391 | ':' { nameRdrName consDataConName }
1392 -- ':' means only list cons
1395 -----------------------------------------------------------------------------
1398 literal :: { HsLit }
1399 : CHAR { HsChar $1 }
1400 | STRING { HsString $1 }
1401 | PRIMINTEGER { HsIntPrim $1 }
1402 | PRIMCHAR { HsCharPrim $1 }
1403 | PRIMSTRING { HsStringPrim $1 }
1404 | PRIMFLOAT { HsFloatPrim $1 }
1405 | PRIMDOUBLE { HsDoublePrim $1 }
1406 | CLITLIT { HsLitLit $1 placeHolderType }
1408 srcloc :: { SrcLoc } : {% getSrcLocP }
1410 -----------------------------------------------------------------------------
1414 : vccurly { () } -- context popped in lexer.
1415 | error {% popContext }
1417 layout_on :: { () } : {% layoutOn True{-strict-} }
1418 layout_on_for_do :: { () } : {% layoutOn False }
1420 -----------------------------------------------------------------------------
1421 -- Miscellaneous (mostly renamings)
1423 modid :: { ModuleName }
1424 : CONID { mkModuleNameFS $1 }
1425 | QCONID { mkModuleNameFS
1427 (unpackFS (fst $1) ++
1428 '.':unpackFS (snd $1)))
1432 : commas ',' { $1 + 1 }
1435 -----------------------------------------------------------------------------
1439 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)