2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.101 2002/09/06 14:35:44 simonmar 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 RnMonad ( ParsedIface(..) )
24 import PrelNames ( mAIN_Name, unitTyCon_RDR, funTyCon_RDR,
25 listTyCon_RDR, parrTyCon_RDR, tupleTyCon_RDR,
26 unitCon_RDR, nilCon_RDR, tupleCon_RDR )
27 import ForeignCall ( Safety(..), CExportSpec(..),
28 CCallConv(..), CCallTarget(..), defaultCCallConv,
30 import OccName ( UserFS, varName, tcName, dataName, tcClsName, tvName )
31 import TyCon ( DataConDetails(..) )
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(..) )
41 import CStrings ( CLabelString )
43 import Maybes ( orElse )
49 -----------------------------------------------------------------------------
50 Conflicts: 21 shift/reduce, -=chak[4Feb2]
52 11 for abiguity in 'if x then y else z + 1' [State 128]
53 (shift parses as 'if x then y else (z + 1)', as per longest-parse rule)
54 8 because op might be: - ! * . `x` VARSYM CONSYM QVARSYM QCONSYM
56 1 for ambiguity in '{-# RULES "name" [ ... #-} [State 210]
57 we don't know whether the '[' starts the activation or not: it
58 might be the start of the declaration with the activation being
61 1 for ambiguity in '{-# RULES "name" forall = ... #-}' [State 412]
62 since 'forall' is a valid variable name, we don't know whether
63 to treat a forall on the input as the beginning of a quantifier
64 or the beginning of the rule itself. Resolving to shift means
65 it's always treated as a quantifier, hence the above is disallowed.
66 This saves explicitly defining a grammar for the rule lhs that
67 doesn't include 'forall'.
69 1 for ambiguity in 'let ?x ...' [State 278]
70 the parser can't tell whether the ?x is the lhs of a normal binding or
71 an implicit binding. Fortunately resolving as shift gives it the only
72 sensible meaning, namely the lhs of an implicit binding.
75 8 for ambiguity in 'e :: a `b` c'. Does this mean [States 238,267]
79 6 for conflicts between `fdecl' and `fdeclDEPRECATED', [States 402,403]
80 which are resolved correctly, and moreover,
81 should go away when `fdeclDEPRECATED' is removed.
83 1 for ambiguity in 'if x then y else z :: T'
84 (shift parses as 'if x then y else (z :: T)', as per longest-parse rule)
85 1 for ambiguity in 'if x then y else z with ?x=3'
86 (shift parses as 'if x then y else (z with ?x=3)'
87 3 for ambiguity in 'case x of y :: a -> b'
88 (don't know whether to reduce 'a' as a btype or shift the '->'.
89 conclusion: bogus expression anyway, doesn't matter)
92 -----------------------------------------------------------------------------
96 '_' { ITunderscore } -- Haskell keywords
101 'default' { ITdefault }
102 'deriving' { ITderiving }
105 'hiding' { IThiding }
107 'import' { ITimport }
110 'infixl' { ITinfixl }
111 'infixr' { ITinfixr }
112 'instance' { ITinstance }
114 'module' { ITmodule }
115 'newtype' { ITnewtype }
117 'qualified' { ITqualified }
121 '_scc_' { ITscc } -- ToDo: remove
123 'forall' { ITforall } -- GHC extension keywords
124 'foreign' { ITforeign }
125 'export' { ITexport }
127 'dynamic' { ITdynamic }
129 'threadsafe' { ITthreadsafe }
130 'unsafe' { ITunsafe }
132 'stdcall' { ITstdcallconv }
133 'ccall' { ITccallconv }
134 'dotnet' { ITdotnet }
135 '_ccall_' { ITccall (False, False, PlayRisky) }
136 '_ccall_GC_' { ITccall (False, False, PlaySafe False) }
137 '_casm_' { ITccall (False, True, PlayRisky) }
138 '_casm_GC_' { ITccall (False, True, PlaySafe False) }
140 '{-# SPECIALISE' { ITspecialise_prag }
141 '{-# SOURCE' { ITsource_prag }
142 '{-# INLINE' { ITinline_prag }
143 '{-# NOINLINE' { ITnoinline_prag }
144 '{-# RULES' { ITrules_prag }
145 '{-# SCC' { ITscc_prag }
146 '{-# DEPRECATED' { ITdeprecated_prag }
147 '#-}' { ITclose_prag }
150 '__interface' { ITinterface } -- interface keywords
151 '__export' { IT__export }
152 '__instimport' { ITinstimport }
153 '__forall' { IT__forall }
154 '__letrec' { ITletrec }
155 '__coerce' { ITcoerce }
156 '__depends' { ITdepends }
157 '__inline' { ITinline }
158 '__DEFAULT' { ITdefaultbranch }
160 '__integer' { ITinteger_lit }
161 '__float' { ITfloat_lit }
162 '__rational' { ITrational_lit }
163 '__addr' { ITaddr_lit }
164 '__label' { ITlabel_lit }
165 '__litlit' { ITlit_lit }
166 '__string' { ITstring_lit }
167 '__ccall' { ITccall $$ }
169 '__sccC' { ITsccAllCafs }
172 '__P' { ITspecialise }
175 '__S' { ITstrict $$ }
176 '__M' { ITcprinfo $$ }
179 '..' { 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 $$ }
235 %monad { P } { thenP } { returnP }
236 %lexer { lexer } { ITeof }
237 %name parseModule module
238 %name parseStmt maybe_stmt
239 %name parseIdentifier identifier
240 %name parseIface iface
244 -----------------------------------------------------------------------------
247 -- The place for module deprecation is really too restrictive, but if it
248 -- was allowed at its natural place just before 'module', we get an ugly
249 -- s/r conflict with the second alternative. Another solution would be the
250 -- introduction of a new pragma DEPRECATED_MODULE, but this is not very nice,
251 -- either, and DEPRECATED is only expected to be used by people who really
252 -- know what they are doing. :-)
254 module :: { RdrNameHsModule }
255 : srcloc 'module' modid maybemoddeprec maybeexports 'where' body
256 { HsModule $3 Nothing $5 (fst $7) (snd $7) $4 $1 }
258 { HsModule mAIN_Name Nothing Nothing (fst $2) (snd $2) Nothing $1 }
260 maybemoddeprec :: { Maybe DeprecTxt }
261 : '{-# DEPRECATED' STRING '#-}' { Just $2 }
262 | {- empty -} { Nothing }
264 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
266 | layout_on top close { $2 }
268 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
269 : importdecls { (reverse $1,[]) }
270 | importdecls ';' cvtopdecls { (reverse $1,$3) }
271 | cvtopdecls { ([],$1) }
273 cvtopdecls :: { [RdrNameHsDecl] }
274 : topdecls { cvTopDecls (groupBindings $1)}
276 -----------------------------------------------------------------------------
277 -- Interfaces (.hi-boot files)
279 iface :: { ParsedIface }
280 : 'module' modid 'where' ifacebody
283 pi_pkg = opt_InPackage,
284 pi_vers = 1, -- Module version
286 pi_exports = (1,[($2,mkIfaceExports $4)]),
290 pi_decls = map (\x -> (1,x)) $4,
296 ifacebody :: { [RdrNameTyClDecl] }
297 : '{' ifacedecls '}' { $2 }
298 | layout_on ifacedecls close { $2 }
300 ifacedecls :: { [RdrNameTyClDecl] }
301 : ifacedecl ';' ifacedecls { $1 : $3 }
302 | ';' ifacedecls { $2 }
306 ifacedecl :: { RdrNameTyClDecl }
307 : srcloc 'data' tycl_hdr constrs
308 { mkTyData DataType $3 (DataCons (reverse $4)) Nothing $1 }
310 | srcloc 'newtype' tycl_hdr '=' newconstr
311 { mkTyData NewType $3 (DataCons [$5]) Nothing $1 }
313 | srcloc 'class' tycl_hdr fds where
315 (binds,sigs) = cvMonoBindsAndSigs cvClassOpSig
318 mkClassDecl $3 $4 sigs (Just binds) $1 }
320 | srcloc 'type' tycon tv_bndrs '=' ctype
321 { TySynonym $3 $4 $6 $1 }
323 | srcloc var '::' sigtype
324 { IfaceSig $2 $4 [] $1 }
326 -----------------------------------------------------------------------------
329 maybeexports :: { Maybe [RdrNameIE] }
330 : '(' exportlist ')' { Just $2 }
331 | {- empty -} { Nothing }
333 exportlist :: { [RdrNameIE] }
334 : exportlist ',' export { $3 : $1 }
335 | exportlist ',' { $1 }
339 -- GHC extension: we allow things like [] and (,,,) to be exported
340 export :: { RdrNameIE }
342 | gtycon { IEThingAbs $1 }
343 | gtycon '(' '..' ')' { IEThingAll $1 }
344 | gtycon '(' ')' { IEThingWith $1 [] }
345 | gtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
346 | 'module' modid { IEModuleContents $2 }
348 qcnames :: { [RdrName] }
349 : qcnames ',' qcname { $3 : $1 }
352 qcname :: { RdrName }
356 -----------------------------------------------------------------------------
357 -- Import Declarations
359 -- import decls can be *empty*, or even just a string of semicolons
360 -- whereas topdecls must contain at least one topdecl.
362 importdecls :: { [RdrNameImportDecl] }
363 : importdecls ';' importdecl { $3 : $1 }
364 | importdecls ';' { $1 }
365 | importdecl { [ $1 ] }
368 importdecl :: { RdrNameImportDecl }
369 : 'import' srcloc maybe_src optqualified modid maybeas maybeimpspec
370 { ImportDecl $5 $3 $4 $6 $7 $2 }
372 maybe_src :: { WhereFrom }
373 : '{-# SOURCE' '#-}' { ImportByUserSource }
374 | {- empty -} { ImportByUser }
376 optqualified :: { Bool }
377 : 'qualified' { True }
378 | {- empty -} { False }
380 maybeas :: { Maybe ModuleName }
381 : 'as' modid { Just $2 }
382 | {- empty -} { Nothing }
384 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
385 : impspec { Just $1 }
386 | {- empty -} { Nothing }
388 impspec :: { (Bool, [RdrNameIE]) }
389 : '(' exportlist ')' { (False, reverse $2) }
390 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
392 -----------------------------------------------------------------------------
393 -- Fixity Declarations
397 | INTEGER {% checkPrec $1 `thenP_`
398 returnP (fromInteger $1) }
400 infix :: { FixityDirection }
402 | 'infixl' { InfixL }
403 | 'infixr' { InfixR }
406 : ops ',' op { $3 : $1 }
409 -----------------------------------------------------------------------------
410 -- Top-Level Declarations
412 topdecls :: { [RdrBinding] }
413 : topdecls ';' topdecl { ($3 : $1) }
414 | topdecls ';' { $1 }
417 topdecl :: { RdrBinding }
418 : srcloc 'type' syn_hdr '=' ctype
419 -- Note ctype, not sigtype.
420 -- We allow an explicit for-all but we don't insert one
421 -- in type Foo a = (b,b)
422 -- Instead we just say b is out of scope
424 in RdrHsDecl (TyClD (TySynonym tc tvs $5 $1)) }
427 | srcloc 'data' tycl_hdr constrs deriving
428 {% returnP (RdrHsDecl (TyClD
429 (mkTyData DataType $3 (DataCons (reverse $4)) $5 $1))) }
431 | srcloc 'newtype' tycl_hdr '=' newconstr deriving
432 {% returnP (RdrHsDecl (TyClD
433 (mkTyData NewType $3 (DataCons [$5]) $6 $1))) }
435 | srcloc 'class' tycl_hdr fds where
437 (binds,sigs) = cvMonoBindsAndSigs cvClassOpSig (groupBindings $5)
439 returnP (RdrHsDecl (TyClD
440 (mkClassDecl $3 $4 sigs (Just binds) $1))) }
442 | srcloc 'instance' inst_type where
444 = cvMonoBindsAndSigs cvInstDeclSig
446 in RdrHsDecl (InstD (InstDecl $3 binds sigs Nothing $1)) }
448 | srcloc 'default' '(' comma_types0 ')' { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
449 | 'foreign' fdecl { RdrHsDecl $2 }
450 | '{-# DEPRECATED' deprecations '#-}' { $2 }
451 | '{-# RULES' rules '#-}' { $2 }
454 syn_hdr :: { (RdrName, [RdrNameHsTyVar]) } -- We don't retain the syntax of an infix
455 -- type synonym declaration. Oh well.
456 : tycon tv_bndrs { ($1, $2) }
457 | tv_bndr tyconop tv_bndr { ($2, [$1,$3]) }
459 -- tycl_hdr parses the header of a type or class decl,
460 -- which takes the form
463 -- (Eq a, Ord b) => T a b
464 -- Rather a lot of inlining here, else we get reduce/reduce errors
465 tycl_hdr :: { (RdrNameContext, RdrName, [RdrNameHsTyVar]) }
466 : context '=>' type {% checkTyClHdr $3 `thenP` \ (tc,tvs) ->
467 returnP ($1, tc, tvs) }
468 | type {% checkTyClHdr $1 `thenP` \ (tc,tvs) ->
469 returnP ([], tc, tvs) }
472 : '(' comma_types1 ')' '=>' gtycon tv_bndrs
473 {% mapP checkPred $2 `thenP` \ cxt ->
474 returnP (cxt, $5, $6) }
476 | '(' ')' '=>' gtycon tv_bndrs
479 -- qtycon for the class below name would lead to many s/r conflicts
480 -- FIXME: does the renamer pick up all wrong forms and raise an
482 | gtycon atypes1 '=>' gtycon atypes0
483 {% checkTyVars $5 `thenP` \ tvs ->
484 returnP ([HsClassP $1 $2], $4, tvs) }
487 {% checkTyVars $2 `thenP` \ tvs ->
488 returnP ([], $1, tvs) }
489 -- We have to have qtycon in this production to avoid s/r
490 -- conflicts with the previous one. The renamer will complain
491 -- if we use a qualified tycon.
493 -- Using a `gtycon' throughout. This enables special syntax,
494 -- such as "[]" for tycons as well as tycon ops in
495 -- parentheses. This is beyond H98, but used repeatedly in
496 -- the Prelude modules. (So, it would be a good idea to raise
497 -- an error in the renamer if some non-H98 form is used and
498 -- -fglasgow-exts is not given.) -=chak
500 atypes0 :: { [RdrNameHsType] }
504 atypes1 :: { [RdrNameHsType] }
506 | atype atypes1 { $1 : $2 }
509 decls :: { [RdrBinding] }
510 : decls ';' decl { $3 : $1 }
515 decl :: { RdrBinding }
518 | '{-# INLINE' srcloc activation qvar '#-}' { RdrSig (InlineSig True $4 $3 $2) }
519 | '{-# NOINLINE' srcloc inverse_activation qvar '#-}' { RdrSig (InlineSig False $4 $3 $2) }
520 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
521 { foldr1 RdrAndBindings
522 (map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
523 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
524 { RdrSig (SpecInstSig $4 $2) }
526 wherebinds :: { RdrNameHsBinds }
527 : where { cvBinds cvValSig (groupBindings $1) }
529 where :: { [RdrBinding] }
530 : 'where' decllist { $2 }
533 declbinds :: { RdrNameHsBinds }
534 : decllist { cvBinds cvValSig (groupBindings $1) }
536 decllist :: { [RdrBinding] }
537 : '{' decls '}' { $2 }
538 | layout_on decls close { $2 }
540 letbinds :: { RdrNameHsExpr -> RdrNameHsExpr }
541 : decllist { HsLet (cvBinds cvValSig (groupBindings $1)) }
542 | '{' dbinds '}' { \e -> HsWith e $2 False{-not with-} }
543 | layout_on dbinds close { \e -> HsWith e $2 False{-not with-} }
545 fixdecl :: { RdrBinding }
546 : srcloc infix prec ops { foldr1 RdrAndBindings
547 [ RdrSig (FixSig (FixitySig n
551 -----------------------------------------------------------------------------
552 -- Transformation Rules
554 rules :: { RdrBinding }
555 : rules ';' rule { $1 `RdrAndBindings` $3 }
558 | {- empty -} { RdrNullBind }
560 rule :: { RdrBinding }
561 : STRING activation rule_forall infixexp '=' srcloc exp
562 { RdrHsDecl (RuleD (HsRule $1 $2 $3 $4 $7 $6)) }
564 activation :: { Activation } -- Omitted means AlwaysActive
565 : {- empty -} { AlwaysActive }
566 | explicit_activation { $1 }
568 inverse_activation :: { Activation } -- Omitted means NeverActive
569 : {- empty -} { NeverActive }
570 | explicit_activation { $1 }
572 explicit_activation :: { Activation } -- In brackets
573 : '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
574 | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
576 rule_forall :: { [RdrNameRuleBndr] }
577 : 'forall' rule_var_list '.' { $2 }
580 rule_var_list :: { [RdrNameRuleBndr] }
582 | rule_var rule_var_list { $1 : $2 }
584 rule_var :: { RdrNameRuleBndr }
585 : varid { RuleBndr $1 }
586 | '(' varid '::' ctype ')' { RuleBndrSig $2 $4 }
588 -----------------------------------------------------------------------------
591 deprecations :: { RdrBinding }
592 : deprecations ';' deprecation { $1 `RdrAndBindings` $3 }
593 | deprecations ';' { $1 }
595 | {- empty -} { RdrNullBind }
597 -- SUP: TEMPORARY HACK, not checking for `module Foo'
598 deprecation :: { RdrBinding }
599 : srcloc depreclist STRING
600 { foldr RdrAndBindings RdrNullBind
601 [ RdrHsDecl (DeprecD (Deprecation n $3 $1)) | n <- $2 ] }
604 -----------------------------------------------------------------------------
605 -- Foreign import and export declarations
607 -- for the time being, the following accepts foreign declarations conforming
608 -- to the FFI Addendum, Version 1.0 as well as pre-standard declarations
610 -- * a flag indicates whether pre-standard declarations have been used and
611 -- triggers a deprecation warning further down the road
613 -- NB: The first two rules could be combined into one by replacing `safety1'
614 -- with `safety'. However, the combined rule conflicts with the
617 fdecl :: { RdrNameHsDecl }
618 fdecl : srcloc 'import' callconv safety1 fspec {% mkImport $3 $4 $5 $1 }
619 | srcloc 'import' callconv fspec {% mkImport $3 (PlaySafe False) $4 $1 }
620 | srcloc 'export' callconv fspec {% mkExport $3 $4 $1 }
621 -- the following syntax is DEPRECATED
622 | srcloc fdecl1DEPRECATED { ForD ($2 True $1) }
623 | srcloc fdecl2DEPRECATED { $2 $1 }
625 fdecl1DEPRECATED :: { Bool -> SrcLoc -> ForeignDecl RdrName }
627 ----------- DEPRECATED label decls ------------
628 : 'label' ext_name varid '::' sigtype
629 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
630 (CLabel ($2 `orElse` mkExtName $3))) }
632 ----------- DEPRECATED ccall/stdcall decls ------------
634 -- NB: This business with the case expression below may seem overly
635 -- complicated, but it is necessary to avoid some conflicts.
637 -- DEPRECATED variant #1: lack of a calling convention specification
639 | 'import' {-no callconv-} ext_name safety varid_no_unsafe '::' sigtype
641 target = StaticTarget ($2 `orElse` mkExtName $4)
643 ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
644 (CFunction target)) }
646 -- DEPRECATED variant #2: external name consists of two separate strings
647 -- (module name and function name) (import)
648 | 'import' callconv STRING STRING safety varid_no_unsafe '::' sigtype
650 DNCall -> parseError "Illegal format of .NET foreign import"
651 CCall cconv -> returnP $
653 imp = CFunction (StaticTarget $4)
655 ForeignImport $6 $8 (CImport cconv $5 nilFS nilFS imp) }
657 -- DEPRECATED variant #3: `unsafe' after entity
658 | 'import' callconv STRING 'unsafe' varid_no_unsafe '::' sigtype
660 DNCall -> parseError "Illegal format of .NET foreign import"
661 CCall cconv -> returnP $
663 imp = CFunction (StaticTarget $3)
665 ForeignImport $5 $7 (CImport cconv PlayRisky nilFS nilFS imp) }
667 -- DEPRECATED variant #4: use of the special identifier `dynamic' without
668 -- an explicit calling convention (import)
669 | 'import' {-no callconv-} 'dynamic' safety varid_no_unsafe '::' sigtype
670 { ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
671 (CFunction DynamicTarget)) }
673 -- DEPRECATED variant #5: use of the special identifier `dynamic' (import)
674 | 'import' callconv 'dynamic' safety varid_no_unsafe '::' sigtype
676 DNCall -> parseError "Illegal format of .NET foreign import"
677 CCall cconv -> returnP $
678 ForeignImport $5 $7 (CImport cconv $4 nilFS nilFS
679 (CFunction DynamicTarget)) }
681 -- DEPRECATED variant #6: lack of a calling convention specification
683 | 'export' {-no callconv-} ext_name varid '::' sigtype
684 { ForeignExport $3 $5 (CExport (CExportStatic ($2 `orElse` mkExtName $3)
687 -- DEPRECATED variant #7: external name consists of two separate strings
688 -- (module name and function name) (export)
689 | 'export' callconv STRING STRING varid '::' sigtype
691 DNCall -> parseError "Illegal format of .NET foreign import"
692 CCall cconv -> returnP $
694 (CExport (CExportStatic $4 cconv)) }
696 -- DEPRECATED variant #8: use of the special identifier `dynamic' without
697 -- an explicit calling convention (export)
698 | 'export' {-no callconv-} 'dynamic' varid '::' sigtype
699 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
702 -- DEPRECATED variant #9: use of the special identifier `dynamic' (export)
703 | 'export' callconv 'dynamic' varid '::' sigtype
705 DNCall -> parseError "Illegal format of .NET foreign import"
706 CCall cconv -> returnP $
707 ForeignImport $4 $6 (CImport cconv (PlaySafe False) nilFS nilFS CWrapper) }
709 ----------- DEPRECATED .NET decls ------------
710 -- NB: removed the .NET call declaration, as it is entirely subsumed
711 -- by the new standard FFI declarations
713 fdecl2DEPRECATED :: { SrcLoc -> RdrNameHsDecl }
715 : 'import' 'dotnet' 'type' ext_name tycon
716 { \loc -> TyClD (ForeignType $5 $4 DNType loc) }
717 -- left this one unchanged for the moment as type imports are not
718 -- covered currently by the FFI standard -=chak
721 callconv :: { CallConv }
722 : 'stdcall' { CCall StdCallConv }
723 | 'ccall' { CCall CCallConv }
724 | 'dotnet' { DNCall }
727 : 'unsafe' { PlayRisky }
728 | 'safe' { PlaySafe False }
729 | 'threadsafe' { PlaySafe True }
730 | {- empty -} { PlaySafe False }
732 safety1 :: { Safety }
733 : 'unsafe' { PlayRisky }
734 | 'safe' { PlaySafe False }
735 | 'threadsafe' { PlaySafe True }
736 -- only needed to avoid conflicts with the DEPRECATED rules
738 fspec :: { (FastString, RdrName, RdrNameHsType) }
739 : STRING varid '::' sigtype { ($1 , $2, $4) }
740 | varid '::' sigtype { (nilFS, $1, $3) }
741 -- if the entity string is missing, it defaults to the empty string;
742 -- the meaning of an empty entity string depends on the calling
746 ext_name :: { Maybe CLabelString }
748 | STRING STRING { Just $2 } -- Ignore "module name" for now
749 | {- empty -} { Nothing }
752 -----------------------------------------------------------------------------
755 opt_sig :: { Maybe RdrNameHsType }
756 : {- empty -} { Nothing }
757 | '::' sigtype { Just $2 }
759 opt_asig :: { Maybe RdrNameHsType }
760 : {- empty -} { Nothing }
761 | '::' atype { Just $2 }
763 sigtypes :: { [RdrNameHsType] }
765 | sigtypes ',' sigtype { $3 : $1 }
767 sigtype :: { RdrNameHsType }
768 : ctype { mkHsForAllTy Nothing [] $1 }
770 sig_vars :: { [RdrName] }
771 : sig_vars ',' var { $3 : $1 }
774 -----------------------------------------------------------------------------
777 -- A ctype is a for-all type
778 ctype :: { RdrNameHsType }
779 : 'forall' tv_bndrs '.' ctype { mkHsForAllTy (Just $2) [] $4 }
780 | context '=>' type { mkHsForAllTy Nothing $1 $3 }
781 -- A type of form (context => type) is an *implicit* HsForAllTy
784 -- We parse a context as a btype so that we don't get reduce/reduce
785 -- errors in ctype. The basic problem is that
787 -- looks so much like a tuple type. We can't tell until we find the =>
788 context :: { RdrNameContext }
789 : btype {% checkContext $1 }
791 type :: { RdrNameHsType }
792 : ipvar '::' gentype { mkHsIParamTy $1 $3 }
795 gentype :: { RdrNameHsType }
797 | btype qtyconop gentype { HsOpTy $1 (HsTyOp $2) $3 }
798 | btype '->' gentype { HsOpTy $1 HsArrow $3 }
800 btype :: { RdrNameHsType }
801 : btype atype { HsAppTy $1 $2 }
804 atype :: { RdrNameHsType }
805 : gtycon { HsTyVar $1 }
806 | tyvar { HsTyVar $1 }
807 | '(' type ',' comma_types1 ')' { HsTupleTy (mkHsTupCon tcName Boxed ($2:$4)) ($2:$4) }
808 | '(#' comma_types1 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
809 | '[' type ']' { HsListTy $2 }
810 | '[:' type ':]' { HsPArrTy $2 }
811 | '(' ctype ')' { HsParTy $2 }
812 | '(' ctype '::' kind ')' { HsKindSig $2 $4 }
814 | INTEGER { HsNumTy $1 }
816 -- An inst_type is what occurs in the head of an instance decl
817 -- e.g. (Foo a, Gaz b) => Wibble a b
818 -- It's kept as a single type, with a MonoDictTy at the right
819 -- hand corner, for convenience.
820 inst_type :: { RdrNameHsType }
821 : ctype {% checkInstType $1 }
823 comma_types0 :: { [RdrNameHsType] }
824 : comma_types1 { $1 }
827 comma_types1 :: { [RdrNameHsType] }
829 | type ',' comma_types1 { $1 : $3 }
831 tv_bndrs :: { [RdrNameHsTyVar] }
832 : tv_bndr tv_bndrs { $1 : $2 }
835 tv_bndr :: { RdrNameHsTyVar }
836 : tyvar { UserTyVar $1 }
837 | '(' tyvar '::' kind ')' { IfaceTyVar $2 $4 }
839 fds :: { [([RdrName], [RdrName])] }
841 | '|' fds1 { reverse $2 }
843 fds1 :: { [([RdrName], [RdrName])] }
844 : fds1 ',' fd { $3 : $1 }
847 fd :: { ([RdrName], [RdrName]) }
848 : varids0 '->' varids0 { (reverse $1, reverse $3) }
850 varids0 :: { [RdrName] }
852 | varids0 tyvar { $2 : $1 }
854 -----------------------------------------------------------------------------
859 | akind '->' kind { mkArrowKind $1 $3 }
862 : '*' { liftedTypeKind }
863 | '(' kind ')' { $2 }
866 -----------------------------------------------------------------------------
867 -- Datatype declarations
869 newconstr :: { RdrNameConDecl }
870 : srcloc conid atype { mkConDecl $2 [] [] (VanillaCon [unbangedType $3]) $1 }
871 | srcloc conid '{' var '::' ctype '}'
872 { mkConDecl $2 [] [] (RecCon [([$4], unbangedType $6)]) $1 }
874 constrs :: { [RdrNameConDecl] }
875 : {- empty; a GHC extension -} { [] }
876 | '=' constrs1 { $2 }
878 constrs1 :: { [RdrNameConDecl] }
879 : constrs1 '|' constr { $3 : $1 }
882 constr :: { RdrNameConDecl }
883 : srcloc forall context '=>' constr_stuff
884 { mkConDecl (fst $5) $2 $3 (snd $5) $1 }
885 | srcloc forall constr_stuff
886 { mkConDecl (fst $3) $2 [] (snd $3) $1 }
888 forall :: { [RdrNameHsTyVar] }
889 : 'forall' tv_bndrs '.' { $2 }
892 constr_stuff :: { (RdrName, RdrNameConDetails) }
893 : btype {% mkVanillaCon $1 [] }
894 | btype '!' atype satypes {% mkVanillaCon $1 (BangType MarkedUserStrict $3 : $4) }
895 | gtycon '{' '}' {% mkRecCon $1 [] }
896 | gtycon '{' fielddecls '}' {% mkRecCon $1 $3 }
897 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
899 satypes :: { [RdrNameBangType] }
900 : atype satypes { unbangedType $1 : $2 }
901 | '!' atype satypes { BangType MarkedUserStrict $2 : $3 }
904 sbtype :: { RdrNameBangType }
905 : btype { unbangedType $1 }
906 | '!' atype { BangType MarkedUserStrict $2 }
908 fielddecls :: { [([RdrName],RdrNameBangType)] }
909 : fielddecl ',' fielddecls { $1 : $3 }
912 fielddecl :: { ([RdrName],RdrNameBangType) }
913 : sig_vars '::' stype { (reverse $1, $3) }
915 stype :: { RdrNameBangType }
916 : ctype { unbangedType $1 }
917 | '!' atype { BangType MarkedUserStrict $2 }
919 deriving :: { Maybe RdrNameContext }
920 : {- empty -} { Nothing }
921 | 'deriving' context { Just $2 }
922 -- Glasgow extension: allow partial
923 -- applications in derivings
925 -----------------------------------------------------------------------------
928 {- There's an awkward overlap with a type signature. Consider
929 f :: Int -> Int = ...rhs...
930 Then we can't tell whether it's a type signature or a value
931 definition with a result signature until we see the '='.
932 So we have to inline enough to postpone reductions until we know.
936 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
937 instead of qvar, we get another shift/reduce-conflict. Consider the
940 { (^^) :: Int->Int ; } Type signature; only var allowed
942 { (^^) :: Int->Int = ... ; } Value defn with result signature;
943 qvar allowed (because of instance decls)
945 We can't tell whether to reduce var to qvar until after we've read the signatures.
948 valdef :: { RdrBinding }
949 : infixexp srcloc opt_sig rhs {% (checkValDef $1 $3 $4 $2) }
950 | infixexp srcloc '::' sigtype {% (checkValSig $1 $4 $2) }
951 | var ',' sig_vars srcloc '::' sigtype { foldr1 RdrAndBindings
952 [ RdrSig (Sig n $6 $4) | n <- $1:$3 ]
956 rhs :: { RdrNameGRHSs }
957 : '=' srcloc exp wherebinds { (GRHSs (unguardedRHS $3 $2) $4 placeHolderType)}
958 | gdrhs wherebinds { GRHSs (reverse $1) $2 placeHolderType }
960 gdrhs :: { [RdrNameGRHS] }
961 : gdrhs gdrh { $2 : $1 }
964 gdrh :: { RdrNameGRHS }
965 : '|' srcloc quals '=' exp { GRHS (reverse (ResultStmt $5 $2 : $3)) $2 }
967 -----------------------------------------------------------------------------
970 exp :: { RdrNameHsExpr }
971 : infixexp '::' sigtype { (ExprWithTySig $1 $3) }
972 | infixexp 'with' dbinding { HsWith $1 $3 True{-not a let-} }
975 infixexp :: { RdrNameHsExpr }
977 | infixexp qop exp10 { (OpApp $1 (HsVar $2)
978 (panic "fixity") $3 )}
980 exp10 :: { RdrNameHsExpr }
981 : '\\' srcloc aexp aexps opt_asig '->' srcloc exp
982 {% checkPatterns $2 ($3 : reverse $4) `thenP` \ ps ->
983 returnP (HsLam (Match ps $5
984 (GRHSs (unguardedRHS $8 $7)
985 EmptyBinds placeHolderType))) }
986 | 'let' letbinds 'in' exp { $2 $4 }
987 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
988 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
989 | '-' fexp { mkHsNegApp $2 }
990 | srcloc 'do' stmtlist {% checkDo $3 `thenP` \ stmts ->
991 returnP (mkHsDo DoExpr stmts $1) }
993 | '_ccall_' ccallid aexps0 { HsCCall $2 $3 PlayRisky False placeHolderType }
994 | '_ccall_GC_' ccallid aexps0 { HsCCall $2 $3 (PlaySafe False) False placeHolderType }
995 | '_casm_' CLITLIT aexps0 { HsCCall $2 $3 PlayRisky True placeHolderType }
996 | '_casm_GC_' CLITLIT aexps0 { HsCCall $2 $3 (PlaySafe False) True placeHolderType }
998 | scc_annot exp { if opt_SccProfilingOn
1004 scc_annot :: { FastString }
1005 : '_scc_' STRING { $2 }
1006 | '{-# SCC' STRING '#-}' { $2 }
1008 ccallid :: { FastString }
1012 fexp :: { RdrNameHsExpr }
1013 : fexp aexp { (HsApp $1 $2) }
1016 aexps0 :: { [RdrNameHsExpr] }
1017 : aexps { reverse $1 }
1019 aexps :: { [RdrNameHsExpr] }
1020 : aexps aexp { $2 : $1 }
1021 | {- empty -} { [] }
1023 aexp :: { RdrNameHsExpr }
1024 : qvar '@' aexp { EAsPat $1 $3 }
1025 | '~' aexp { ELazyPat $2 }
1028 aexp1 :: { RdrNameHsExpr }
1029 : aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1
1032 | var_or_con '{|' gentype '|}' { HsApp $1 (HsType $3) }
1035 var_or_con :: { RdrNameHsExpr }
1039 aexp2 :: { RdrNameHsExpr }
1040 : ipvar { HsIPVar $1 }
1042 | literal { HsLit $1 }
1043 | INTEGER { HsOverLit (mkHsIntegral $1) }
1044 | RATIONAL { HsOverLit (mkHsFractional $1) }
1045 | '(' exp ')' { HsPar $2 }
1046 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) Boxed}
1047 | '(#' texps '#)' { ExplicitTuple (reverse $2) Unboxed }
1048 | '[' list ']' { $2 }
1049 | '[:' parr ':]' { $2 }
1050 | '(' infixexp qop ')' { (SectionL $2 (HsVar $3)) }
1051 | '(' qopm infixexp ')' { (SectionR $2 $3) }
1054 texps :: { [RdrNameHsExpr] }
1055 : texps ',' exp { $3 : $1 }
1059 -----------------------------------------------------------------------------
1062 -- The rules below are little bit contorted to keep lexps left-recursive while
1063 -- avoiding another shift/reduce-conflict.
1065 list :: { RdrNameHsExpr }
1066 : exp { ExplicitList placeHolderType [$1] }
1067 | lexps { ExplicitList placeHolderType (reverse $1) }
1068 | exp '..' { ArithSeqIn (From $1) }
1069 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
1070 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
1071 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
1072 | exp srcloc pquals {% let { body [qs] = qs;
1073 body qss = [ParStmt (map reverse qss)] }
1075 returnP ( mkHsDo ListComp
1076 (reverse (ResultStmt $1 $2 : body $3))
1081 lexps :: { [RdrNameHsExpr] }
1082 : lexps ',' exp { $3 : $1 }
1083 | exp ',' exp { [$3,$1] }
1085 -----------------------------------------------------------------------------
1086 -- List Comprehensions
1088 pquals :: { [[RdrNameStmt]] }
1089 : pquals '|' quals { $3 : $1 }
1090 | '|' quals { [$2] }
1092 quals :: { [RdrNameStmt] }
1093 : quals ',' stmt { $3 : $1 }
1096 -----------------------------------------------------------------------------
1097 -- Parallel array expressions
1099 -- The rules below are little bit contorted; see the list case for details.
1100 -- Note that, in contrast to lists, we only have finite arithmetic sequences.
1101 -- Moreover, we allow explicit arrays with no element (represented by the nil
1102 -- constructor in the list case).
1104 parr :: { RdrNameHsExpr }
1105 : { ExplicitPArr placeHolderType [] }
1106 | exp { ExplicitPArr placeHolderType [$1] }
1107 | lexps { ExplicitPArr placeHolderType
1109 | exp '..' exp { PArrSeqIn (FromTo $1 $3) }
1110 | exp ',' exp '..' exp { PArrSeqIn (FromThenTo $1 $3 $5) }
1111 | exp srcloc pquals {% let {
1118 (reverse (ResultStmt $1 $2
1123 -- We are reusing `lexps' and `pquals' from the list case.
1125 -----------------------------------------------------------------------------
1126 -- Case alternatives
1128 altslist :: { [RdrNameMatch] }
1129 : '{' alts '}' { reverse $2 }
1130 | layout_on alts close { reverse $2 }
1132 alts :: { [RdrNameMatch] }
1136 alts1 :: { [RdrNameMatch] }
1137 : alts1 ';' alt { $3 : $1 }
1141 alt :: { RdrNameMatch }
1142 : srcloc infixexp opt_sig ralt wherebinds
1143 {% (checkPattern $1 $2 `thenP` \p ->
1144 returnP (Match [p] $3
1145 (GRHSs $4 $5 placeHolderType)) )}
1147 ralt :: { [RdrNameGRHS] }
1148 : '->' srcloc exp { [GRHS [ResultStmt $3 $2] $2] }
1149 | gdpats { reverse $1 }
1151 gdpats :: { [RdrNameGRHS] }
1152 : gdpats gdpat { $2 : $1 }
1155 gdpat :: { RdrNameGRHS }
1156 : srcloc '|' quals '->' exp { GRHS (reverse (ResultStmt $5 $1:$3)) $1}
1158 -----------------------------------------------------------------------------
1159 -- Statement sequences
1161 stmtlist :: { [RdrNameStmt] }
1162 : '{' stmts '}' { $2 }
1163 | layout_on_for_do stmts close { $2 }
1165 -- do { ;; s ; s ; ; s ;; }
1166 -- The last Stmt should be a ResultStmt, but that's hard to enforce
1167 -- here, because we need too much lookahead if we see do { e ; }
1168 -- So we use ExprStmts throughout, and switch the last one over
1169 -- in ParseUtils.checkDo instead
1170 stmts :: { [RdrNameStmt] }
1171 : stmt stmts_help { $1 : $2 }
1173 | {- empty -} { [] }
1175 stmts_help :: { [RdrNameStmt] }
1177 | {- empty -} { [] }
1179 -- For typing stmts at the GHCi prompt, where
1180 -- the input may consist of just comments.
1181 maybe_stmt :: { Maybe RdrNameStmt }
1183 | {- nothing -} { Nothing }
1185 stmt :: { RdrNameStmt }
1186 : srcloc infixexp '<-' exp {% checkPattern $1 $2 `thenP` \p ->
1187 returnP (BindStmt p $4 $1) }
1188 | srcloc exp { ExprStmt $2 placeHolderType $1 }
1189 | srcloc 'let' declbinds { LetStmt $3 }
1191 -----------------------------------------------------------------------------
1192 -- Record Field Update/Construction
1194 fbinds :: { RdrNameHsRecordBinds }
1195 : fbinds ',' fbind { $3 : $1 }
1198 | {- empty -} { [] }
1200 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
1201 : qvar '=' exp { ($1,$3,False) }
1203 -----------------------------------------------------------------------------
1204 -- Implicit Parameter Bindings
1206 dbinding :: { [(IPName RdrName, RdrNameHsExpr)] }
1207 : '{' dbinds '}' { $2 }
1208 | layout_on dbinds close { $2 }
1210 dbinds :: { [(IPName RdrName, RdrNameHsExpr)] }
1211 : dbinds ';' dbind { $3 : $1 }
1214 -- | {- empty -} { [] }
1216 dbind :: { (IPName RdrName, RdrNameHsExpr) }
1217 dbind : ipvar '=' exp { ($1, $3) }
1219 -----------------------------------------------------------------------------
1220 -- Variables, Constructors and Operators.
1222 identifier :: { RdrName }
1227 depreclist :: { [RdrName] }
1228 depreclist : deprec_var { [$1] }
1229 | deprec_var ',' depreclist { $1 : $3 }
1231 deprec_var :: { RdrName }
1232 deprec_var : var { $1 }
1235 gtycon :: { RdrName }
1237 | '(' qtyconop ')' { $2 }
1238 | '(' ')' { unitTyCon_RDR }
1239 | '(' '->' ')' { funTyCon_RDR }
1240 | '[' ']' { listTyCon_RDR }
1241 | '[:' ':]' { parrTyCon_RDR }
1242 | '(' commas ')' { tupleTyCon_RDR $2 }
1244 gcon :: { RdrName } -- Data constructor namespace
1245 : '(' ')' { unitCon_RDR }
1246 | '[' ']' { nilCon_RDR }
1247 | '(' commas ')' { tupleCon_RDR $2 }
1249 -- the case of '[:' ':]' is part of the production `parr'
1253 | '(' varsym ')' { $2 }
1257 | '(' varsym ')' { $2 }
1258 | '(' qvarsym1 ')' { $2 }
1259 -- We've inlined qvarsym here so that the decision about
1260 -- whether it's a qvar or a var can be postponed until
1261 -- *after* we see the close paren.
1263 ipvar :: { IPName RdrName }
1264 : IPDUPVARID { Dupable (mkUnqual varName $1) }
1265 | IPSPLITVARID { Linear (mkUnqual varName $1) }
1269 | '(' qconsym ')' { $2 }
1271 varop :: { RdrName }
1273 | '`' varid '`' { $2 }
1275 qvarop :: { RdrName }
1277 | '`' qvarid '`' { $2 }
1279 qvaropm :: { RdrName }
1280 : qvarsym_no_minus { $1 }
1281 | '`' qvarid '`' { $2 }
1283 conop :: { RdrName }
1285 | '`' conid '`' { $2 }
1287 qconop :: { RdrName }
1289 | '`' qconid '`' { $2 }
1291 -----------------------------------------------------------------------------
1292 -- Type constructors
1294 tycon :: { RdrName } -- Unqualified
1295 : CONID { mkUnqual tcClsName $1 }
1297 tyconop :: { RdrName } -- Unqualified
1298 : CONSYM { mkUnqual tcClsName $1 }
1299 | '`' tyvar '`' { $2 }
1300 | '`' tycon '`' { $2 }
1302 qtycon :: { RdrName } -- Qualified or unqualified
1303 : QCONID { mkQual tcClsName $1 }
1306 qtyconop :: { RdrName } -- Qualified or unqualified
1307 : QCONSYM { mkQual tcClsName $1 }
1308 | '`' QCONID '`' { mkQual tcClsName $2 }
1311 -----------------------------------------------------------------------------
1314 op :: { RdrName } -- used in infix decls
1318 qop :: { RdrName {-HsExpr-} } -- used in sections
1322 qopm :: { RdrNameHsExpr } -- used in sections
1323 : qvaropm { HsVar $1 }
1324 | qconop { HsVar $1 }
1326 -----------------------------------------------------------------------------
1329 qvarid :: { RdrName }
1331 | QVARID { mkQual varName $1 }
1333 varid :: { RdrName }
1334 : varid_no_unsafe { $1 }
1335 | 'unsafe' { mkUnqual varName FSLIT("unsafe") }
1336 | 'safe' { mkUnqual varName FSLIT("safe") }
1337 | 'threadsafe' { mkUnqual varName FSLIT("threadsafe") }
1339 varid_no_unsafe :: { RdrName }
1340 : VARID { mkUnqual varName $1 }
1341 | special_id { mkUnqual varName $1 }
1342 | 'forall' { mkUnqual varName FSLIT("forall") }
1344 tyvar :: { RdrName }
1345 : VARID { mkUnqual tvName $1 }
1346 | special_id { mkUnqual tvName $1 }
1347 | 'unsafe' { mkUnqual tvName FSLIT("unsafe") }
1348 | 'safe' { mkUnqual tvName FSLIT("safe") }
1349 | 'threadsafe' { mkUnqual tvName FSLIT("threadsafe") }
1351 -- These special_ids are treated as keywords in various places,
1352 -- but as ordinary ids elsewhere. 'special_id' collects all these
1353 -- except 'unsafe' and 'forall' whose treatment differs depending on context
1354 special_id :: { UserFS }
1356 : 'as' { FSLIT("as") }
1357 | 'qualified' { FSLIT("qualified") }
1358 | 'hiding' { FSLIT("hiding") }
1359 | 'export' { FSLIT("export") }
1360 | 'label' { FSLIT("label") }
1361 | 'dynamic' { FSLIT("dynamic") }
1362 | 'stdcall' { FSLIT("stdcall") }
1363 | 'ccall' { FSLIT("ccall") }
1365 -----------------------------------------------------------------------------
1368 qvarsym :: { RdrName }
1372 qvarsym_no_minus :: { RdrName }
1373 : varsym_no_minus { $1 }
1376 qvarsym1 :: { RdrName }
1377 qvarsym1 : QVARSYM { mkQual varName $1 }
1379 varsym :: { RdrName }
1380 : varsym_no_minus { $1 }
1381 | '-' { mkUnqual varName FSLIT("-") }
1383 varsym_no_minus :: { RdrName } -- varsym not including '-'
1384 : VARSYM { mkUnqual varName $1 }
1385 | special_sym { mkUnqual varName $1 }
1388 -- See comments with special_id
1389 special_sym :: { UserFS }
1390 special_sym : '!' { FSLIT("!") }
1391 | '.' { FSLIT(".") }
1392 | '*' { FSLIT("*") }
1394 -----------------------------------------------------------------------------
1395 -- Data constructors
1397 qconid :: { RdrName } -- Qualified or unqualifiedb
1399 | QCONID { mkQual dataName $1 }
1401 conid :: { RdrName }
1402 : CONID { mkUnqual dataName $1 }
1404 qconsym :: { RdrName } -- Qualified or unqualified
1406 | QCONSYM { mkQual dataName $1 }
1408 consym :: { RdrName }
1409 : CONSYM { mkUnqual dataName $1 }
1412 -----------------------------------------------------------------------------
1415 literal :: { HsLit }
1416 : CHAR { HsChar $1 }
1417 | STRING { HsString $1 }
1418 | PRIMINTEGER { HsIntPrim $1 }
1419 | PRIMCHAR { HsCharPrim $1 }
1420 | PRIMSTRING { HsStringPrim $1 }
1421 | PRIMFLOAT { HsFloatPrim $1 }
1422 | PRIMDOUBLE { HsDoublePrim $1 }
1423 | CLITLIT { HsLitLit $1 placeHolderType }
1425 srcloc :: { SrcLoc } : {% getSrcLocP }
1427 -----------------------------------------------------------------------------
1431 : vccurly { () } -- context popped in lexer.
1432 | error {% popContext }
1434 layout_on :: { () } : {% layoutOn True{-strict-} }
1435 layout_on_for_do :: { () } : {% layoutOn False }
1437 -----------------------------------------------------------------------------
1438 -- Miscellaneous (mostly renamings)
1440 modid :: { ModuleName }
1441 : CONID { mkModuleNameFS $1 }
1442 | QCONID { mkModuleNameFS
1444 (unpackFS (fst $1) ++
1445 '.':unpackFS (snd $1)))
1449 : commas ',' { $1 + 1 }
1452 -----------------------------------------------------------------------------
1456 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)