2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.102 2002/09/13 15:02:37 simonpj Exp $
7 Author(s): Simon Marlow, Sven Panne 1997, 1998, 1999
8 -----------------------------------------------------------------------------
12 module Parser ( parseModule, parseStmt, parseIdentifier, parseIface ) where
14 #include "HsVersions.h"
17 import HsTypes ( mkHsTupCon )
20 import HscTypes ( ParsedIface(..), IsBootInterface )
24 import PrelNames ( mAIN_Name, funTyConName, listTyConName,
25 parrTyConName, consDataConName, nilDataConName )
26 import TysWiredIn ( unitTyCon, unitDataCon, tupleTyCon, tupleCon )
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(..),
42 import CStrings ( CLabelString )
44 import Maybes ( orElse )
50 -----------------------------------------------------------------------------
51 Conflicts: 21 shift/reduce, -=chak[4Feb2]
53 11 for abiguity in 'if x then y else z + 1' [State 128]
54 (shift parses as 'if x then y else (z + 1)', as per longest-parse rule)
55 8 because op might be: - ! * . `x` VARSYM CONSYM QVARSYM QCONSYM
57 1 for ambiguity in '{-# RULES "name" [ ... #-} [State 210]
58 we don't know whether the '[' starts the activation or not: it
59 might be the start of the declaration with the activation being
62 1 for ambiguity in '{-# RULES "name" forall = ... #-}' [State 412]
63 since 'forall' is a valid variable name, we don't know whether
64 to treat a forall on the input as the beginning of a quantifier
65 or the beginning of the rule itself. Resolving to shift means
66 it's always treated as a quantifier, hence the above is disallowed.
67 This saves explicitly defining a grammar for the rule lhs that
68 doesn't include 'forall'.
70 1 for ambiguity in 'let ?x ...' [State 278]
71 the parser can't tell whether the ?x is the lhs of a normal binding or
72 an implicit binding. Fortunately resolving as shift gives it the only
73 sensible meaning, namely the lhs of an implicit binding.
76 8 for ambiguity in 'e :: a `b` c'. Does this mean [States 238,267]
80 6 for conflicts between `fdecl' and `fdeclDEPRECATED', [States 402,403]
81 which are resolved correctly, and moreover,
82 should go away when `fdeclDEPRECATED' is removed.
84 1 for ambiguity in 'if x then y else z :: T'
85 (shift parses as 'if x then y else (z :: T)', as per longest-parse rule)
86 1 for ambiguity in 'if x then y else z with ?x=3'
87 (shift parses as 'if x then y else (z with ?x=3)'
88 3 for ambiguity in 'case x of y :: a -> b'
89 (don't know whether to reduce 'a' as a btype or shift the '->'.
90 conclusion: bogus expression anyway, doesn't matter)
93 -----------------------------------------------------------------------------
97 '_' { ITunderscore } -- Haskell keywords
102 'default' { ITdefault }
103 'deriving' { ITderiving }
106 'hiding' { IThiding }
108 'import' { ITimport }
111 'infixl' { ITinfixl }
112 'infixr' { ITinfixr }
113 'instance' { ITinstance }
115 'module' { ITmodule }
116 'newtype' { ITnewtype }
118 'qualified' { ITqualified }
122 '_scc_' { ITscc } -- ToDo: remove
124 'forall' { ITforall } -- GHC extension keywords
125 'foreign' { ITforeign }
126 'export' { ITexport }
128 'dynamic' { ITdynamic }
130 'threadsafe' { ITthreadsafe }
131 'unsafe' { ITunsafe }
133 'stdcall' { ITstdcallconv }
134 'ccall' { ITccallconv }
135 'dotnet' { ITdotnet }
136 '_ccall_' { ITccall (False, False, PlayRisky) }
137 '_ccall_GC_' { ITccall (False, False, PlaySafe False) }
138 '_casm_' { ITccall (False, True, PlayRisky) }
139 '_casm_GC_' { ITccall (False, True, PlaySafe False) }
141 '{-# SPECIALISE' { ITspecialise_prag }
142 '{-# SOURCE' { ITsource_prag }
143 '{-# INLINE' { ITinline_prag }
144 '{-# NOINLINE' { ITnoinline_prag }
145 '{-# RULES' { ITrules_prag }
146 '{-# SCC' { ITscc_prag }
147 '{-# DEPRECATED' { ITdeprecated_prag }
148 '#-}' { ITclose_prag }
151 '__interface' { ITinterface } -- interface keywords
152 '__export' { IT__export }
153 '__instimport' { ITinstimport }
154 '__forall' { IT__forall }
155 '__letrec' { ITletrec }
156 '__coerce' { ITcoerce }
157 '__depends' { ITdepends }
158 '__inline' { ITinline }
159 '__DEFAULT' { ITdefaultbranch }
161 '__integer' { ITinteger_lit }
162 '__float' { ITfloat_lit }
163 '__rational' { ITrational_lit }
164 '__addr' { ITaddr_lit }
165 '__label' { ITlabel_lit }
166 '__litlit' { ITlit_lit }
167 '__string' { ITstring_lit }
168 '__ccall' { ITccall $$ }
170 '__sccC' { ITsccAllCafs }
173 '__P' { ITspecialise }
176 '__S' { ITstrict $$ }
177 '__M' { ITcprinfo $$ }
180 '..' { ITdotdot } -- reserved symbols
196 '{' { ITocurly } -- special symbols
200 vccurly { ITvccurly } -- virtual close curly (from layout)
213 VARID { ITvarid $$ } -- identifiers
215 VARSYM { ITvarsym $$ }
216 CONSYM { ITconsym $$ }
217 QVARID { ITqvarid $$ }
218 QCONID { ITqconid $$ }
219 QVARSYM { ITqvarsym $$ }
220 QCONSYM { ITqconsym $$ }
222 IPDUPVARID { ITdupipvarid $$ } -- GHC extension
223 IPSPLITVARID { ITsplitipvarid $$ } -- GHC extension
226 STRING { ITstring $$ }
227 INTEGER { ITinteger $$ }
228 RATIONAL { ITrational $$ }
230 PRIMCHAR { ITprimchar $$ }
231 PRIMSTRING { ITprimstring $$ }
232 PRIMINTEGER { ITprimint $$ }
233 PRIMFLOAT { ITprimfloat $$ }
234 PRIMDOUBLE { ITprimdouble $$ }
235 CLITLIT { ITlitlit $$ }
238 '[|' { ITopenExpQuote }
239 '[p|' { ITopenPatQuote }
240 '[t|' { ITopenTypQuote }
241 '[d|' { ITopenDecQuote }
242 '|]' { ITcloseQuote }
243 ID_SPLICE { ITidEscape $$ } -- $x
244 '$(' { ITparenEscape } -- $( exp )
246 %monad { P } { thenP } { returnP }
247 %lexer { lexer } { ITeof }
248 %name parseModule module
249 %name parseStmt maybe_stmt
250 %name parseIdentifier identifier
251 %name parseIface iface
255 -----------------------------------------------------------------------------
258 -- The place for module deprecation is really too restrictive, but if it
259 -- was allowed at its natural place just before 'module', we get an ugly
260 -- s/r conflict with the second alternative. Another solution would be the
261 -- introduction of a new pragma DEPRECATED_MODULE, but this is not very nice,
262 -- either, and DEPRECATED is only expected to be used by people who really
263 -- know what they are doing. :-)
265 module :: { RdrNameHsModule }
266 : srcloc 'module' modid maybemoddeprec maybeexports 'where' body
267 { HsModule (mkHomeModule $3) Nothing $5 (fst $7) (snd $7) $4 $1 }
269 { HsModule (mkHomeModule mAIN_Name) Nothing Nothing
270 (fst $2) (snd $2) Nothing $1 }
272 maybemoddeprec :: { Maybe DeprecTxt }
273 : '{-# DEPRECATED' STRING '#-}' { Just $2 }
274 | {- empty -} { Nothing }
276 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
278 | layout_on top close { $2 }
280 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
281 : importdecls { (reverse $1,[]) }
282 | importdecls ';' cvtopdecls { (reverse $1,$3) }
283 | cvtopdecls { ([],$1) }
285 cvtopdecls :: { [RdrNameHsDecl] }
286 : topdecls { cvTopDecls (groupBindings $1)}
288 -----------------------------------------------------------------------------
289 -- Interfaces (.hi-boot files)
291 iface :: { ParsedIface }
292 : 'module' modid 'where' ifacebody
295 pi_pkg = opt_InPackage,
296 pi_vers = 1, -- Module version
298 pi_exports = (1,[($2,mkIfaceExports $4)]),
302 pi_decls = map (\x -> (1,x)) $4,
308 ifacebody :: { [RdrNameTyClDecl] }
309 : '{' ifacedecls '}' { $2 }
310 | layout_on ifacedecls close { $2 }
312 ifacedecls :: { [RdrNameTyClDecl] }
313 : ifacedecl ';' ifacedecls { $1 : $3 }
314 | ';' ifacedecls { $2 }
318 ifacedecl :: { RdrNameTyClDecl }
319 : srcloc 'data' tycl_hdr constrs
320 { mkTyData DataType $3 (DataCons (reverse $4)) Nothing $1 }
322 | srcloc 'newtype' tycl_hdr '=' newconstr
323 { mkTyData NewType $3 (DataCons [$5]) Nothing $1 }
325 | srcloc 'class' tycl_hdr fds where
327 (binds,sigs) = cvMonoBindsAndSigs cvClassOpSig
330 mkClassDecl $3 $4 sigs (Just binds) $1 }
332 | srcloc 'type' tycon tv_bndrs '=' ctype
333 { TySynonym $3 $4 $6 $1 }
335 | srcloc var '::' sigtype
336 { IfaceSig $2 $4 [] $1 }
338 -----------------------------------------------------------------------------
341 maybeexports :: { Maybe [RdrNameIE] }
342 : '(' exportlist ')' { Just $2 }
343 | {- empty -} { Nothing }
345 exportlist :: { [RdrNameIE] }
346 : exportlist ',' export { $3 : $1 }
347 | exportlist ',' { $1 }
351 -- No longer allow things like [] and (,,,) to be exported
352 -- They are built in syntax, always available
353 export :: { RdrNameIE }
355 | oqtycon { IEThingAbs $1 }
356 | oqtycon '(' '..' ')' { IEThingAll $1 }
357 | oqtycon '(' ')' { IEThingWith $1 [] }
358 | oqtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
359 | 'module' modid { IEModuleContents $2 }
361 qcnames :: { [RdrName] }
362 : qcnames ',' qcname { $3 : $1 }
365 qcname :: { RdrName } -- Variable or data constructor
369 -----------------------------------------------------------------------------
370 -- Import Declarations
372 -- import decls can be *empty*, or even just a string of semicolons
373 -- whereas topdecls must contain at least one topdecl.
375 importdecls :: { [RdrNameImportDecl] }
376 : importdecls ';' importdecl { $3 : $1 }
377 | importdecls ';' { $1 }
378 | importdecl { [ $1 ] }
381 importdecl :: { RdrNameImportDecl }
382 : 'import' srcloc maybe_src optqualified modid maybeas maybeimpspec
383 { ImportDecl $5 $3 $4 $6 $7 $2 }
385 maybe_src :: { IsBootInterface }
386 : '{-# SOURCE' '#-}' { True }
387 | {- empty -} { False }
389 optqualified :: { Bool }
390 : 'qualified' { True }
391 | {- empty -} { False }
393 maybeas :: { Maybe ModuleName }
394 : 'as' modid { Just $2 }
395 | {- empty -} { Nothing }
397 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
398 : impspec { Just $1 }
399 | {- empty -} { Nothing }
401 impspec :: { (Bool, [RdrNameIE]) }
402 : '(' exportlist ')' { (False, reverse $2) }
403 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
405 -----------------------------------------------------------------------------
406 -- Fixity Declarations
410 | INTEGER {% checkPrec $1 `thenP_`
411 returnP (fromInteger $1) }
413 infix :: { FixityDirection }
415 | 'infixl' { InfixL }
416 | 'infixr' { InfixR }
419 : ops ',' op { $3 : $1 }
422 -----------------------------------------------------------------------------
423 -- Top-Level Declarations
425 topdecls :: { [RdrBinding] }
426 : topdecls ';' topdecl { ($3 : $1) }
427 | topdecls ';' { $1 }
430 topdecl :: { RdrBinding }
431 : srcloc 'type' syn_hdr '=' ctype
432 -- Note ctype, not sigtype.
433 -- We allow an explicit for-all but we don't insert one
434 -- in type Foo a = (b,b)
435 -- Instead we just say b is out of scope
437 in RdrHsDecl (TyClD (TySynonym tc tvs $5 $1)) }
440 | srcloc 'data' tycl_hdr constrs deriving
441 {% returnP (RdrHsDecl (TyClD
442 (mkTyData DataType $3 (DataCons (reverse $4)) $5 $1))) }
444 | srcloc 'newtype' tycl_hdr '=' newconstr deriving
445 {% returnP (RdrHsDecl (TyClD
446 (mkTyData NewType $3 (DataCons [$5]) $6 $1))) }
448 | srcloc 'class' tycl_hdr fds where
450 (binds,sigs) = cvMonoBindsAndSigs cvClassOpSig (groupBindings $5)
452 returnP (RdrHsDecl (TyClD
453 (mkClassDecl $3 $4 sigs (Just binds) $1))) }
455 | srcloc 'instance' inst_type where
457 = cvMonoBindsAndSigs cvInstDeclSig
459 in RdrHsDecl (InstD (InstDecl $3 binds sigs Nothing $1)) }
461 | srcloc 'default' '(' comma_types0 ')' { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
462 | 'foreign' fdecl { RdrHsDecl $2 }
463 | '{-# DEPRECATED' deprecations '#-}' { $2 }
464 | '{-# RULES' rules '#-}' { $2 }
465 | '$(' exp ')' { RdrHsDecl (SpliceD $2) }
468 syn_hdr :: { (RdrName, [RdrNameHsTyVar]) } -- We don't retain the syntax of an infix
469 -- type synonym declaration. Oh well.
470 : tycon tv_bndrs { ($1, $2) }
471 | tv_bndr tyconop tv_bndr { ($2, [$1,$3]) }
473 -- tycl_hdr parses the header of a type or class decl,
474 -- which takes the form
477 -- (Eq a, Ord b) => T a b
478 -- Rather a lot of inlining here, else we get reduce/reduce errors
479 tycl_hdr :: { (RdrNameContext, RdrName, [RdrNameHsTyVar]) }
480 : context '=>' type {% checkTyClHdr $3 `thenP` \ (tc,tvs) ->
481 returnP ($1, tc, tvs) }
482 | type {% checkTyClHdr $1 `thenP` \ (tc,tvs) ->
483 returnP ([], tc, tvs) }
486 : '(' comma_types1 ')' '=>' gtycon tv_bndrs
487 {% mapP checkPred $2 `thenP` \ cxt ->
488 returnP (cxt, $5, $6) }
490 | '(' ')' '=>' gtycon tv_bndrs
493 -- qtycon for the class below name would lead to many s/r conflicts
494 -- FIXME: does the renamer pick up all wrong forms and raise an
496 | gtycon atypes1 '=>' gtycon atypes0
497 {% checkTyVars $5 `thenP` \ tvs ->
498 returnP ([HsClassP $1 $2], $4, tvs) }
501 {% checkTyVars $2 `thenP` \ tvs ->
502 returnP ([], $1, tvs) }
503 -- We have to have qtycon in this production to avoid s/r
504 -- conflicts with the previous one. The renamer will complain
505 -- if we use a qualified tycon.
507 -- Using a `gtycon' throughout. This enables special syntax,
508 -- such as "[]" for tycons as well as tycon ops in
509 -- parentheses. This is beyond H98, but used repeatedly in
510 -- the Prelude modules. (So, it would be a good idea to raise
511 -- an error in the renamer if some non-H98 form is used and
512 -- -fglasgow-exts is not given.) -=chak
514 atypes0 :: { [RdrNameHsType] }
518 atypes1 :: { [RdrNameHsType] }
520 | atype atypes1 { $1 : $2 }
523 decls :: { [RdrBinding] }
524 : decls ';' decl { $3 : $1 }
529 decl :: { RdrBinding }
532 | '{-# INLINE' srcloc activation qvar '#-}' { RdrSig (InlineSig True $4 $3 $2) }
533 | '{-# NOINLINE' srcloc inverse_activation qvar '#-}' { RdrSig (InlineSig False $4 $3 $2) }
534 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
535 { foldr1 RdrAndBindings
536 (map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
537 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
538 { RdrSig (SpecInstSig $4 $2) }
540 wherebinds :: { RdrNameHsBinds }
541 : where { cvBinds cvValSig (groupBindings $1) }
543 where :: { [RdrBinding] }
544 : 'where' decllist { $2 }
547 declbinds :: { RdrNameHsBinds }
548 : decllist { cvBinds cvValSig (groupBindings $1) }
550 decllist :: { [RdrBinding] }
551 : '{' decls '}' { $2 }
552 | layout_on decls close { $2 }
554 letbinds :: { RdrNameHsExpr -> RdrNameHsExpr }
555 : decllist { HsLet (cvBinds cvValSig (groupBindings $1)) }
556 | '{' dbinds '}' { \e -> HsWith e $2 False{-not with-} }
557 | layout_on dbinds close { \e -> HsWith e $2 False{-not with-} }
559 fixdecl :: { RdrBinding }
560 : srcloc infix prec ops { foldr1 RdrAndBindings
561 [ RdrSig (FixSig (FixitySig n
565 -----------------------------------------------------------------------------
566 -- Transformation Rules
568 rules :: { RdrBinding }
569 : rules ';' rule { $1 `RdrAndBindings` $3 }
572 | {- empty -} { RdrNullBind }
574 rule :: { RdrBinding }
575 : STRING activation rule_forall infixexp '=' srcloc exp
576 { RdrHsDecl (RuleD (HsRule $1 $2 $3 $4 $7 $6)) }
578 activation :: { Activation } -- Omitted means AlwaysActive
579 : {- empty -} { AlwaysActive }
580 | explicit_activation { $1 }
582 inverse_activation :: { Activation } -- Omitted means NeverActive
583 : {- empty -} { NeverActive }
584 | explicit_activation { $1 }
586 explicit_activation :: { Activation } -- In brackets
587 : '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
588 | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
590 rule_forall :: { [RdrNameRuleBndr] }
591 : 'forall' rule_var_list '.' { $2 }
594 rule_var_list :: { [RdrNameRuleBndr] }
596 | rule_var rule_var_list { $1 : $2 }
598 rule_var :: { RdrNameRuleBndr }
599 : varid { RuleBndr $1 }
600 | '(' varid '::' ctype ')' { RuleBndrSig $2 $4 }
602 -----------------------------------------------------------------------------
605 deprecations :: { RdrBinding }
606 : deprecations ';' deprecation { $1 `RdrAndBindings` $3 }
607 | deprecations ';' { $1 }
609 | {- empty -} { RdrNullBind }
611 -- SUP: TEMPORARY HACK, not checking for `module Foo'
612 deprecation :: { RdrBinding }
613 : srcloc depreclist STRING
614 { foldr RdrAndBindings RdrNullBind
615 [ RdrHsDecl (DeprecD (Deprecation n $3 $1)) | n <- $2 ] }
618 -----------------------------------------------------------------------------
619 -- Foreign import and export declarations
621 -- for the time being, the following accepts foreign declarations conforming
622 -- to the FFI Addendum, Version 1.0 as well as pre-standard declarations
624 -- * a flag indicates whether pre-standard declarations have been used and
625 -- triggers a deprecation warning further down the road
627 -- NB: The first two rules could be combined into one by replacing `safety1'
628 -- with `safety'. However, the combined rule conflicts with the
631 fdecl :: { RdrNameHsDecl }
632 fdecl : srcloc 'import' callconv safety1 fspec {% mkImport $3 $4 $5 $1 }
633 | srcloc 'import' callconv fspec {% mkImport $3 (PlaySafe False) $4 $1 }
634 | srcloc 'export' callconv fspec {% mkExport $3 $4 $1 }
635 -- the following syntax is DEPRECATED
636 | srcloc fdecl1DEPRECATED { ForD ($2 True $1) }
637 | srcloc fdecl2DEPRECATED { $2 $1 }
639 fdecl1DEPRECATED :: { Bool -> SrcLoc -> ForeignDecl RdrName }
641 ----------- DEPRECATED label decls ------------
642 : 'label' ext_name varid '::' sigtype
643 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
644 (CLabel ($2 `orElse` mkExtName $3))) }
646 ----------- DEPRECATED ccall/stdcall decls ------------
648 -- NB: This business with the case expression below may seem overly
649 -- complicated, but it is necessary to avoid some conflicts.
651 -- DEPRECATED variant #1: lack of a calling convention specification
653 | 'import' {-no callconv-} ext_name safety varid_no_unsafe '::' sigtype
655 target = StaticTarget ($2 `orElse` mkExtName $4)
657 ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
658 (CFunction target)) }
660 -- DEPRECATED variant #2: external name consists of two separate strings
661 -- (module name and function name) (import)
662 | 'import' callconv STRING STRING safety varid_no_unsafe '::' sigtype
664 DNCall -> parseError "Illegal format of .NET foreign import"
665 CCall cconv -> returnP $
667 imp = CFunction (StaticTarget $4)
669 ForeignImport $6 $8 (CImport cconv $5 nilFS nilFS imp) }
671 -- DEPRECATED variant #3: `unsafe' after entity
672 | 'import' callconv STRING 'unsafe' varid_no_unsafe '::' sigtype
674 DNCall -> parseError "Illegal format of .NET foreign import"
675 CCall cconv -> returnP $
677 imp = CFunction (StaticTarget $3)
679 ForeignImport $5 $7 (CImport cconv PlayRisky nilFS nilFS imp) }
681 -- DEPRECATED variant #4: use of the special identifier `dynamic' without
682 -- an explicit calling convention (import)
683 | 'import' {-no callconv-} 'dynamic' safety varid_no_unsafe '::' sigtype
684 { ForeignImport $4 $6 (CImport defaultCCallConv $3 nilFS nilFS
685 (CFunction DynamicTarget)) }
687 -- DEPRECATED variant #5: use of the special identifier `dynamic' (import)
688 | 'import' callconv 'dynamic' safety varid_no_unsafe '::' sigtype
690 DNCall -> parseError "Illegal format of .NET foreign import"
691 CCall cconv -> returnP $
692 ForeignImport $5 $7 (CImport cconv $4 nilFS nilFS
693 (CFunction DynamicTarget)) }
695 -- DEPRECATED variant #6: lack of a calling convention specification
697 | 'export' {-no callconv-} ext_name varid '::' sigtype
698 { ForeignExport $3 $5 (CExport (CExportStatic ($2 `orElse` mkExtName $3)
701 -- DEPRECATED variant #7: external name consists of two separate strings
702 -- (module name and function name) (export)
703 | 'export' callconv STRING STRING varid '::' sigtype
705 DNCall -> parseError "Illegal format of .NET foreign import"
706 CCall cconv -> returnP $
708 (CExport (CExportStatic $4 cconv)) }
710 -- DEPRECATED variant #8: use of the special identifier `dynamic' without
711 -- an explicit calling convention (export)
712 | 'export' {-no callconv-} 'dynamic' varid '::' sigtype
713 { ForeignImport $3 $5 (CImport defaultCCallConv (PlaySafe False) nilFS nilFS
716 -- DEPRECATED variant #9: use of the special identifier `dynamic' (export)
717 | 'export' callconv 'dynamic' varid '::' sigtype
719 DNCall -> parseError "Illegal format of .NET foreign import"
720 CCall cconv -> returnP $
721 ForeignImport $4 $6 (CImport cconv (PlaySafe False) nilFS nilFS CWrapper) }
723 ----------- DEPRECATED .NET decls ------------
724 -- NB: removed the .NET call declaration, as it is entirely subsumed
725 -- by the new standard FFI declarations
727 fdecl2DEPRECATED :: { SrcLoc -> RdrNameHsDecl }
729 : 'import' 'dotnet' 'type' ext_name tycon
730 { \loc -> TyClD (ForeignType $5 $4 DNType loc) }
731 -- left this one unchanged for the moment as type imports are not
732 -- covered currently by the FFI standard -=chak
735 callconv :: { CallConv }
736 : 'stdcall' { CCall StdCallConv }
737 | 'ccall' { CCall CCallConv }
738 | 'dotnet' { DNCall }
741 : 'unsafe' { PlayRisky }
742 | 'safe' { PlaySafe False }
743 | 'threadsafe' { PlaySafe True }
744 | {- empty -} { PlaySafe False }
746 safety1 :: { Safety }
747 : 'unsafe' { PlayRisky }
748 | 'safe' { PlaySafe False }
749 | 'threadsafe' { PlaySafe True }
750 -- only needed to avoid conflicts with the DEPRECATED rules
752 fspec :: { (FastString, RdrName, RdrNameHsType) }
753 : STRING varid '::' sigtype { ($1 , $2, $4) }
754 | varid '::' sigtype { (nilFS, $1, $3) }
755 -- if the entity string is missing, it defaults to the empty string;
756 -- the meaning of an empty entity string depends on the calling
760 ext_name :: { Maybe CLabelString }
762 | STRING STRING { Just $2 } -- Ignore "module name" for now
763 | {- empty -} { Nothing }
766 -----------------------------------------------------------------------------
769 opt_sig :: { Maybe RdrNameHsType }
770 : {- empty -} { Nothing }
771 | '::' sigtype { Just $2 }
773 opt_asig :: { Maybe RdrNameHsType }
774 : {- empty -} { Nothing }
775 | '::' atype { Just $2 }
777 sigtypes :: { [RdrNameHsType] }
779 | sigtypes ',' sigtype { $3 : $1 }
781 sigtype :: { RdrNameHsType }
782 : ctype { mkHsForAllTy Nothing [] $1 }
784 sig_vars :: { [RdrName] }
785 : sig_vars ',' var { $3 : $1 }
788 -----------------------------------------------------------------------------
791 -- A ctype is a for-all type
792 ctype :: { RdrNameHsType }
793 : 'forall' tv_bndrs '.' ctype { mkHsForAllTy (Just $2) [] $4 }
794 | context '=>' type { mkHsForAllTy Nothing $1 $3 }
795 -- A type of form (context => type) is an *implicit* HsForAllTy
798 -- We parse a context as a btype so that we don't get reduce/reduce
799 -- errors in ctype. The basic problem is that
801 -- looks so much like a tuple type. We can't tell until we find the =>
802 context :: { RdrNameContext }
803 : btype {% checkContext $1 }
805 type :: { RdrNameHsType }
806 : ipvar '::' gentype { mkHsIParamTy $1 $3 }
809 gentype :: { RdrNameHsType }
811 | btype qtyconop gentype { HsOpTy $1 (HsTyOp $2) $3 }
812 | btype '`' tyvar '`' gentype { HsOpTy $1 (HsTyOp $3) $5 }
813 | btype '->' gentype { HsOpTy $1 HsArrow $3 }
815 btype :: { RdrNameHsType }
816 : btype atype { HsAppTy $1 $2 }
819 atype :: { RdrNameHsType }
820 : gtycon { HsTyVar $1 }
821 | tyvar { HsTyVar $1 }
822 | '(' type ',' comma_types1 ')' { HsTupleTy (mkHsTupCon tcName Boxed ($2:$4)) ($2:$4) }
823 | '(#' comma_types1 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
824 | '[' type ']' { HsListTy $2 }
825 | '[:' type ':]' { HsPArrTy $2 }
826 | '(' ctype ')' { HsParTy $2 }
827 | '(' ctype '::' kind ')' { HsKindSig $2 $4 }
829 | INTEGER { HsNumTy $1 }
831 -- An inst_type is what occurs in the head of an instance decl
832 -- e.g. (Foo a, Gaz b) => Wibble a b
833 -- It's kept as a single type, with a MonoDictTy at the right
834 -- hand corner, for convenience.
835 inst_type :: { RdrNameHsType }
836 : ctype {% checkInstType $1 }
838 comma_types0 :: { [RdrNameHsType] }
839 : comma_types1 { $1 }
842 comma_types1 :: { [RdrNameHsType] }
844 | type ',' comma_types1 { $1 : $3 }
846 tv_bndrs :: { [RdrNameHsTyVar] }
847 : tv_bndr tv_bndrs { $1 : $2 }
850 tv_bndr :: { RdrNameHsTyVar }
851 : tyvar { UserTyVar $1 }
852 | '(' tyvar '::' kind ')' { IfaceTyVar $2 $4 }
854 fds :: { [([RdrName], [RdrName])] }
856 | '|' fds1 { reverse $2 }
858 fds1 :: { [([RdrName], [RdrName])] }
859 : fds1 ',' fd { $3 : $1 }
862 fd :: { ([RdrName], [RdrName]) }
863 : varids0 '->' varids0 { (reverse $1, reverse $3) }
865 varids0 :: { [RdrName] }
867 | varids0 tyvar { $2 : $1 }
869 -----------------------------------------------------------------------------
874 | akind '->' kind { mkArrowKind $1 $3 }
877 : '*' { liftedTypeKind }
878 | '(' kind ')' { $2 }
881 -----------------------------------------------------------------------------
882 -- Datatype declarations
884 newconstr :: { RdrNameConDecl }
885 : srcloc conid atype { ConDecl $2 [] [] (PrefixCon [unbangedType $3]) $1 }
886 | srcloc conid '{' var '::' ctype '}'
887 { ConDecl $2 [] [] (RecCon [($4, unbangedType $6)]) $1 }
889 constrs :: { [RdrNameConDecl] }
890 : {- empty; a GHC extension -} { [] }
891 | '=' constrs1 { $2 }
893 constrs1 :: { [RdrNameConDecl] }
894 : constrs1 '|' constr { $3 : $1 }
897 constr :: { RdrNameConDecl }
898 : srcloc forall context '=>' constr_stuff
899 { ConDecl (fst $5) $2 $3 (snd $5) $1 }
900 | srcloc forall constr_stuff
901 { ConDecl (fst $3) $2 [] (snd $3) $1 }
903 forall :: { [RdrNameHsTyVar] }
904 : 'forall' tv_bndrs '.' { $2 }
907 constr_stuff :: { (RdrName, RdrNameConDetails) }
908 : btype {% mkPrefixCon $1 [] }
909 | btype '!' atype satypes {% mkPrefixCon $1 (BangType MarkedUserStrict $3 : $4) }
910 | conid '{' '}' { ($1, RecCon []) }
911 | conid '{' fielddecls '}' { ($1, mkRecCon $3) }
912 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
914 satypes :: { [RdrNameBangType] }
915 : atype satypes { unbangedType $1 : $2 }
916 | '!' atype satypes { BangType MarkedUserStrict $2 : $3 }
919 sbtype :: { RdrNameBangType }
920 : btype { unbangedType $1 }
921 | '!' atype { BangType MarkedUserStrict $2 }
923 fielddecls :: { [([RdrName],RdrNameBangType)] }
924 : fielddecl ',' fielddecls { $1 : $3 }
927 fielddecl :: { ([RdrName],RdrNameBangType) }
928 : sig_vars '::' stype { (reverse $1, $3) }
930 stype :: { RdrNameBangType }
931 : ctype { unbangedType $1 }
932 | '!' atype { BangType MarkedUserStrict $2 }
934 deriving :: { Maybe RdrNameContext }
935 : {- empty -} { Nothing }
936 | 'deriving' context { Just $2 }
937 -- Glasgow extension: allow partial
938 -- applications in derivings
940 -----------------------------------------------------------------------------
943 {- There's an awkward overlap with a type signature. Consider
944 f :: Int -> Int = ...rhs...
945 Then we can't tell whether it's a type signature or a value
946 definition with a result signature until we see the '='.
947 So we have to inline enough to postpone reductions until we know.
951 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
952 instead of qvar, we get another shift/reduce-conflict. Consider the
955 { (^^) :: Int->Int ; } Type signature; only var allowed
957 { (^^) :: Int->Int = ... ; } Value defn with result signature;
958 qvar allowed (because of instance decls)
960 We can't tell whether to reduce var to qvar until after we've read the signatures.
963 valdef :: { RdrBinding }
964 : infixexp srcloc opt_sig rhs {% (checkValDef $1 $3 $4 $2) }
965 | infixexp srcloc '::' sigtype {% (checkValSig $1 $4 $2) }
966 | var ',' sig_vars srcloc '::' sigtype { foldr1 RdrAndBindings
967 [ RdrSig (Sig n $6 $4) | n <- $1:$3 ]
970 rhs :: { RdrNameGRHSs }
971 : '=' srcloc exp wherebinds { (GRHSs (unguardedRHS $3 $2) $4 placeHolderType)}
972 | gdrhs wherebinds { GRHSs (reverse $1) $2 placeHolderType }
974 gdrhs :: { [RdrNameGRHS] }
975 : gdrhs gdrh { $2 : $1 }
978 gdrh :: { RdrNameGRHS }
979 : '|' srcloc quals '=' exp { GRHS (reverse (ResultStmt $5 $2 : $3)) $2 }
981 -----------------------------------------------------------------------------
984 exp :: { RdrNameHsExpr }
985 : infixexp '::' sigtype { (ExprWithTySig $1 $3) }
986 | infixexp 'with' dbinding { HsWith $1 $3 True{-not a let-} }
989 infixexp :: { RdrNameHsExpr }
991 | infixexp qop exp10 { (OpApp $1 (HsVar $2)
992 (panic "fixity") $3 )}
994 exp10 :: { RdrNameHsExpr }
995 : '\\' srcloc aexp aexps opt_asig '->' srcloc exp
996 {% checkPatterns $2 ($3 : reverse $4) `thenP` \ ps ->
997 returnP (HsLam (Match ps $5
998 (GRHSs (unguardedRHS $8 $7)
999 EmptyBinds placeHolderType))) }
1000 | 'let' letbinds 'in' exp { $2 $4 }
1001 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
1002 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
1003 | '-' fexp { mkHsNegApp $2 }
1004 | srcloc 'do' stmtlist {% checkDo $3 `thenP` \ stmts ->
1005 returnP (mkHsDo DoExpr stmts $1) }
1007 | '_ccall_' ccallid aexps0 { HsCCall $2 $3 PlayRisky False placeHolderType }
1008 | '_ccall_GC_' ccallid aexps0 { HsCCall $2 $3 (PlaySafe False) False placeHolderType }
1009 | '_casm_' CLITLIT aexps0 { HsCCall $2 $3 PlayRisky True placeHolderType }
1010 | '_casm_GC_' CLITLIT aexps0 { HsCCall $2 $3 (PlaySafe False) True placeHolderType }
1012 | scc_annot exp { if opt_SccProfilingOn
1018 scc_annot :: { FastString }
1019 : '_scc_' STRING { $2 }
1020 | '{-# SCC' STRING '#-}' { $2 }
1022 ccallid :: { FastString }
1026 fexp :: { RdrNameHsExpr }
1027 : fexp aexp { (HsApp $1 $2) }
1030 aexps0 :: { [RdrNameHsExpr] }
1031 : aexps { reverse $1 }
1033 aexps :: { [RdrNameHsExpr] }
1034 : aexps aexp { $2 : $1 }
1035 | {- empty -} { [] }
1037 aexp :: { RdrNameHsExpr }
1038 : qvar '@' aexp { EAsPat $1 $3 }
1039 | '~' aexp { ELazyPat $2 }
1042 aexp1 :: { RdrNameHsExpr }
1043 : aexp1 '{' fbinds '}' {% (mkRecConstrOrUpdate $1 (reverse $3)) }
1046 -- Here was the syntax for type applications that I was planning
1047 -- but there are difficulties (e.g. what order for type args)
1048 -- so it's not enabled yet.
1049 | qcname '{|' gentype '|}' { (HsApp (HsVar $1) (HsType $3)) }
1051 aexp2 :: { RdrNameHsExpr }
1052 : ipvar { HsIPVar $1 }
1053 | qcname { HsVar $1 }
1054 | literal { HsLit $1 }
1055 | INTEGER { HsOverLit (mkHsIntegral $1) }
1056 | RATIONAL { HsOverLit (mkHsFractional $1) }
1057 | '(' exp ')' { HsPar $2 }
1058 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) Boxed}
1059 | '(#' texps '#)' { ExplicitTuple (reverse $2) Unboxed }
1060 | '[' list ']' { $2 }
1061 | '[:' parr ':]' { $2 }
1062 | '(' infixexp qop ')' { (SectionL $2 (HsVar $3)) }
1063 | '(' qopm infixexp ')' { (SectionR $2 $3) }
1066 -- MetaHaskell Extension
1067 | ID_SPLICE { mkHsSplice (HsVar (mkUnqual varName $1))} -- $x
1068 | '$(' exp ')' { mkHsSplice $2 } -- $( exp )
1069 | '[|' exp '|]' { HsBracket (ExpBr $2) }
1070 | '[t|' ctype '|]' { HsBracket (TypBr $2) }
1071 | '[p|' srcloc infixexp '|]' {% checkPattern $2 $3 `thenP` \p ->
1072 returnP (HsBracket (PatBr p)) }
1073 | '[d|' cvtopdecls '|]' { HsBracket (DecBr $2) }
1076 texps :: { [RdrNameHsExpr] }
1077 : texps ',' exp { $3 : $1 }
1081 -----------------------------------------------------------------------------
1084 -- The rules below are little bit contorted to keep lexps left-recursive while
1085 -- avoiding another shift/reduce-conflict.
1087 list :: { RdrNameHsExpr }
1088 : exp { ExplicitList placeHolderType [$1] }
1089 | lexps { ExplicitList placeHolderType (reverse $1) }
1090 | exp '..' { ArithSeqIn (From $1) }
1091 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
1092 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
1093 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
1094 | exp srcloc pquals {% let { body [qs] = qs;
1095 body qss = [ParStmt (map reverse qss)] }
1097 returnP ( mkHsDo ListComp
1098 (reverse (ResultStmt $1 $2 : body $3))
1103 lexps :: { [RdrNameHsExpr] }
1104 : lexps ',' exp { $3 : $1 }
1105 | exp ',' exp { [$3,$1] }
1107 -----------------------------------------------------------------------------
1108 -- List Comprehensions
1110 pquals :: { [[RdrNameStmt]] }
1111 : pquals '|' quals { $3 : $1 }
1112 | '|' quals { [$2] }
1114 quals :: { [RdrNameStmt] }
1115 : quals ',' stmt { $3 : $1 }
1118 -----------------------------------------------------------------------------
1119 -- Parallel array expressions
1121 -- The rules below are little bit contorted; see the list case for details.
1122 -- Note that, in contrast to lists, we only have finite arithmetic sequences.
1123 -- Moreover, we allow explicit arrays with no element (represented by the nil
1124 -- constructor in the list case).
1126 parr :: { RdrNameHsExpr }
1127 : { ExplicitPArr placeHolderType [] }
1128 | exp { ExplicitPArr placeHolderType [$1] }
1129 | lexps { ExplicitPArr placeHolderType
1131 | exp '..' exp { PArrSeqIn (FromTo $1 $3) }
1132 | exp ',' exp '..' exp { PArrSeqIn (FromThenTo $1 $3 $5) }
1133 | exp srcloc pquals {% let {
1140 (reverse (ResultStmt $1 $2
1145 -- We are reusing `lexps' and `pquals' from the list case.
1147 -----------------------------------------------------------------------------
1148 -- Case alternatives
1150 altslist :: { [RdrNameMatch] }
1151 : '{' alts '}' { reverse $2 }
1152 | layout_on alts close { reverse $2 }
1154 alts :: { [RdrNameMatch] }
1158 alts1 :: { [RdrNameMatch] }
1159 : alts1 ';' alt { $3 : $1 }
1163 alt :: { RdrNameMatch }
1164 : srcloc infixexp opt_sig ralt wherebinds
1165 {% (checkPattern $1 $2 `thenP` \p ->
1166 returnP (Match [p] $3
1167 (GRHSs $4 $5 placeHolderType)) )}
1169 ralt :: { [RdrNameGRHS] }
1170 : '->' srcloc exp { [GRHS [ResultStmt $3 $2] $2] }
1171 | gdpats { reverse $1 }
1173 gdpats :: { [RdrNameGRHS] }
1174 : gdpats gdpat { $2 : $1 }
1177 gdpat :: { RdrNameGRHS }
1178 : srcloc '|' quals '->' exp { GRHS (reverse (ResultStmt $5 $1:$3)) $1}
1180 -----------------------------------------------------------------------------
1181 -- Statement sequences
1183 stmtlist :: { [RdrNameStmt] }
1184 : '{' stmts '}' { $2 }
1185 | layout_on_for_do stmts close { $2 }
1187 -- do { ;; s ; s ; ; s ;; }
1188 -- The last Stmt should be a ResultStmt, but that's hard to enforce
1189 -- here, because we need too much lookahead if we see do { e ; }
1190 -- So we use ExprStmts throughout, and switch the last one over
1191 -- in ParseUtils.checkDo instead
1192 stmts :: { [RdrNameStmt] }
1193 : stmt stmts_help { $1 : $2 }
1195 | {- empty -} { [] }
1197 stmts_help :: { [RdrNameStmt] }
1199 | {- empty -} { [] }
1201 -- For typing stmts at the GHCi prompt, where
1202 -- the input may consist of just comments.
1203 maybe_stmt :: { Maybe RdrNameStmt }
1205 | {- nothing -} { Nothing }
1207 stmt :: { RdrNameStmt }
1208 : srcloc infixexp '<-' exp {% checkPattern $1 $2 `thenP` \p ->
1209 returnP (BindStmt p $4 $1) }
1210 | srcloc exp { ExprStmt $2 placeHolderType $1 }
1211 | srcloc 'let' declbinds { LetStmt $3 }
1213 -----------------------------------------------------------------------------
1214 -- Record Field Update/Construction
1216 fbinds :: { RdrNameHsRecordBinds }
1217 : fbinds ',' fbind { $3 : $1 }
1220 | {- empty -} { [] }
1222 fbind :: { (RdrName, RdrNameHsExpr) }
1223 : qvar '=' exp { ($1,$3) }
1225 -----------------------------------------------------------------------------
1226 -- Implicit Parameter Bindings
1228 dbinding :: { [(IPName RdrName, RdrNameHsExpr)] }
1229 : '{' dbinds '}' { $2 }
1230 | layout_on dbinds close { $2 }
1232 dbinds :: { [(IPName RdrName, RdrNameHsExpr)] }
1233 : dbinds ';' dbind { $3 : $1 }
1236 -- | {- empty -} { [] }
1238 dbind :: { (IPName RdrName, RdrNameHsExpr) }
1239 dbind : ipvar '=' exp { ($1, $3) }
1241 -----------------------------------------------------------------------------
1242 -- Variables, Constructors and Operators.
1244 identifier :: { RdrName }
1249 depreclist :: { [RdrName] }
1250 depreclist : deprec_var { [$1] }
1251 | deprec_var ',' depreclist { $1 : $3 }
1253 deprec_var :: { RdrName }
1254 deprec_var : var { $1 }
1257 gcon :: { RdrName } -- Data constructor namespace
1260 -- the case of '[:' ':]' is part of the production `parr'
1262 sysdcon :: { RdrName } -- Data constructor namespace
1263 : '(' ')' { getRdrName unitDataCon }
1264 | '(' commas ')' { getRdrName (tupleCon Boxed $2) }
1265 | '[' ']' { nameRdrName nilDataConName }
1269 | '(' varsym ')' { $2 }
1273 | '(' varsym ')' { $2 }
1274 | '(' qvarsym1 ')' { $2 }
1275 -- We've inlined qvarsym here so that the decision about
1276 -- whether it's a qvar or a var can be postponed until
1277 -- *after* we see the close paren.
1279 ipvar :: { IPName RdrName }
1280 : IPDUPVARID { Dupable (mkUnqual varName $1) }
1281 | IPSPLITVARID { Linear (mkUnqual varName $1) }
1285 | '(' qconsym ')' { $2 }
1287 varop :: { RdrName }
1289 | '`' varid '`' { $2 }
1291 qvarop :: { RdrName }
1293 | '`' qvarid '`' { $2 }
1295 qvaropm :: { RdrName }
1296 : qvarsym_no_minus { $1 }
1297 | '`' qvarid '`' { $2 }
1299 conop :: { RdrName }
1301 | '`' conid '`' { $2 }
1303 qconop :: { RdrName }
1305 | '`' qconid '`' { $2 }
1307 -----------------------------------------------------------------------------
1308 -- Type constructors
1310 gtycon :: { RdrName } -- A "general" qualified tycon
1312 | '(' ')' { getRdrName unitTyCon }
1313 | '(' commas ')' { getRdrName (tupleTyCon Boxed $2) }
1314 | '(' '->' ')' { nameRdrName funTyConName }
1315 | '[' ']' { nameRdrName listTyConName }
1316 | '[:' ':]' { nameRdrName parrTyConName }
1318 oqtycon :: { RdrName } -- An "ordinary" qualified tycon
1320 | '(' qtyconop ')' { $2 }
1322 qtycon :: { RdrName } -- Qualified or unqualified
1323 : QCONID { mkQual tcClsName $1 }
1326 qtyconop :: { RdrName } -- Qualified or unqualified
1327 : QCONSYM { mkQual tcClsName $1 }
1328 | '`' QCONID '`' { mkQual tcClsName $2 }
1331 tycon :: { RdrName } -- Unqualified
1332 : CONID { mkUnqual tcClsName $1 }
1334 tyconop :: { RdrName } -- Unqualified
1335 : CONSYM { mkUnqual tcClsName $1 }
1336 | '`' tycon '`' { $2 }
1339 -----------------------------------------------------------------------------
1342 op :: { RdrName } -- used in infix decls
1346 qop :: { RdrName {-HsExpr-} } -- used in sections
1350 qopm :: { RdrNameHsExpr } -- used in sections
1351 : qvaropm { HsVar $1 }
1352 | qconop { HsVar $1 }
1354 -----------------------------------------------------------------------------
1357 qvarid :: { RdrName }
1359 | QVARID { mkQual varName $1 }
1361 varid :: { RdrName }
1362 : varid_no_unsafe { $1 }
1363 | 'unsafe' { mkUnqual varName FSLIT("unsafe") }
1364 | 'safe' { mkUnqual varName FSLIT("safe") }
1365 | 'threadsafe' { mkUnqual varName FSLIT("threadsafe") }
1367 varid_no_unsafe :: { RdrName }
1368 : VARID { mkUnqual varName $1 }
1369 | special_id { mkUnqual varName $1 }
1370 | 'forall' { mkUnqual varName FSLIT("forall") }
1372 tyvar :: { RdrName }
1373 : VARID { mkUnqual tvName $1 }
1374 | special_id { mkUnqual tvName $1 }
1375 | 'unsafe' { mkUnqual tvName FSLIT("unsafe") }
1376 | 'safe' { mkUnqual tvName FSLIT("safe") }
1377 | 'threadsafe' { mkUnqual tvName FSLIT("threadsafe") }
1379 -- These special_ids are treated as keywords in various places,
1380 -- but as ordinary ids elsewhere. 'special_id' collects all these
1381 -- except 'unsafe' and 'forall' whose treatment differs depending on context
1382 special_id :: { UserFS }
1384 : 'as' { FSLIT("as") }
1385 | 'qualified' { FSLIT("qualified") }
1386 | 'hiding' { FSLIT("hiding") }
1387 | 'export' { FSLIT("export") }
1388 | 'label' { FSLIT("label") }
1389 | 'dynamic' { FSLIT("dynamic") }
1390 | 'stdcall' { FSLIT("stdcall") }
1391 | 'ccall' { FSLIT("ccall") }
1393 -----------------------------------------------------------------------------
1396 qvarsym :: { RdrName }
1400 qvarsym_no_minus :: { RdrName }
1401 : varsym_no_minus { $1 }
1404 qvarsym1 :: { RdrName }
1405 qvarsym1 : QVARSYM { mkQual varName $1 }
1407 varsym :: { RdrName }
1408 : varsym_no_minus { $1 }
1409 | '-' { mkUnqual varName FSLIT("-") }
1411 varsym_no_minus :: { RdrName } -- varsym not including '-'
1412 : VARSYM { mkUnqual varName $1 }
1413 | special_sym { mkUnqual varName $1 }
1416 -- See comments with special_id
1417 special_sym :: { UserFS }
1418 special_sym : '!' { FSLIT("!") }
1419 | '.' { FSLIT(".") }
1420 | '*' { FSLIT("*") }
1422 -----------------------------------------------------------------------------
1423 -- Data constructors
1425 qconid :: { RdrName } -- Qualified or unqualifiedb
1427 | QCONID { mkQual dataName $1 }
1429 conid :: { RdrName }
1430 : CONID { mkUnqual dataName $1 }
1432 qconsym :: { RdrName } -- Qualified or unqualified
1434 | QCONSYM { mkQual dataName $1 }
1436 consym :: { RdrName }
1437 : CONSYM { mkUnqual dataName $1 }
1438 | ':' { nameRdrName consDataConName }
1439 -- ':' means only list cons
1442 -----------------------------------------------------------------------------
1445 literal :: { HsLit }
1446 : CHAR { HsChar $1 }
1447 | STRING { HsString $1 }
1448 | PRIMINTEGER { HsIntPrim $1 }
1449 | PRIMCHAR { HsCharPrim $1 }
1450 | PRIMSTRING { HsStringPrim $1 }
1451 | PRIMFLOAT { HsFloatPrim $1 }
1452 | PRIMDOUBLE { HsDoublePrim $1 }
1453 | CLITLIT { HsLitLit $1 placeHolderType }
1455 srcloc :: { SrcLoc } : {% getSrcLocP }
1457 -----------------------------------------------------------------------------
1461 : vccurly { () } -- context popped in lexer.
1462 | error {% popContext }
1464 layout_on :: { () } : {% layoutOn True{-strict-} }
1465 layout_on_for_do :: { () } : {% layoutOn False }
1467 -----------------------------------------------------------------------------
1468 -- Miscellaneous (mostly renamings)
1470 modid :: { ModuleName }
1471 : CONID { mkModuleNameFS $1 }
1472 | QCONID { mkModuleNameFS
1474 (unpackFS (fst $1) ++
1475 '.':unpackFS (snd $1)))
1479 : commas ',' { $1 + 1 }
1482 -----------------------------------------------------------------------------
1486 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)