2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.15 1999/11/01 17:10:23 simonpj Exp $
7 Author(s): Simon Marlow, Sven Panne 1997, 1998, 1999
8 -----------------------------------------------------------------------------
12 module Parser ( parse ) where
21 import PrelMods ( mAIN_Name )
22 import OccName ( varName, dataName, tcClsName, tvName )
23 import SrcLoc ( SrcLoc )
26 import CmdLineOpts ( opt_SccProfilingOn )
27 import BasicTypes ( Fixity(..), FixityDirection(..), NewOrData(..) )
32 #include "HsVersions.h"
36 -----------------------------------------------------------------------------
37 Conflicts: 14 shift/reduce
39 8 for abiguity in 'if x then y else z + 1'
40 (shift parses as 'if x then y else (z + 1)', as per longest-parse rule)
41 1 for ambiguity in 'if x then y else z :: T'
42 (shift parses as 'if x then y else (z :: T)', as per longest-parse rule)
43 3 for ambiguity in 'case x of y :: a -> b'
44 (don't know whether to reduce 'a' as a btype or shift the '->'.
45 conclusion: bogus expression anyway, doesn't matter)
47 1 for ambiguity in '{-# RULES "name" forall = ... #-}'
48 since 'forall' is a valid variable name, we don't know whether
49 to treat a forall on the input as the beginning of a quantifier
50 or the beginning of the rule itself. Resolving to shift means
51 it's always treated as a quantifier, hence the above is disallowed.
52 This saves explicitly defining a grammar for the rule lhs that
53 doesn't include 'forall'.
55 1 for ambiguity in 'x @ Rec{..}'.
56 Only sensible parse is 'x @ (Rec{..})', which is what resolving
59 -----------------------------------------------------------------------------
63 '_' { ITunderscore } -- Haskell keywords
68 'default' { ITdefault }
69 'deriving' { ITderiving }
79 'instance' { ITinstance }
82 'newtype' { ITnewtype }
84 'qualified' { ITqualified }
90 'forall' { ITforall } -- GHC extension keywords
91 'foreign' { ITforeign }
94 'dynamic' { ITdynamic }
96 'stdcall' { ITstdcallconv }
97 'ccall' { ITccallconv }
98 '_ccall_' { ITccall (False, False, False) }
99 '_ccall_GC_' { ITccall (False, False, True) }
100 '_casm_' { ITccall (False, True, False) }
101 '_casm_GC_' { ITccall (False, True, True) }
103 '{-# SPECIALISE' { ITspecialise_prag }
104 '{-# SOURCE' { ITsource_prag }
105 '{-# INLINE' { ITinline_prag }
106 '{-# NOINLINE' { ITnoinline_prag }
107 '{-# RULES' { ITrules_prag }
108 '#-}' { ITclose_prag }
111 '__interface' { ITinterface } -- interface keywords
112 '__export' { IT__export }
113 '__instimport' { ITinstimport }
114 '__forall' { IT__forall }
115 '__letrec' { ITletrec }
116 '__coerce' { ITcoerce }
117 '__depends' { ITdepends }
118 '__inline' { ITinline }
119 '__DEFAULT' { ITdefaultbranch }
121 '__integer' { ITinteger_lit }
122 '__float' { ITfloat_lit }
123 '__rational' { ITrational_lit }
124 '__addr' { ITaddr_lit }
125 '__litlit' { ITlit_lit }
126 '__string' { ITstring_lit }
127 '__ccall' { ITccall $$ }
129 '__sccC' { ITsccAllCafs }
132 '__P' { ITspecialise }
134 '__U' { ITunfold $$ }
135 '__S' { ITstrict $$ }
136 '__M' { ITcprinfo $$ }
139 '..' { ITdotdot } -- reserved symbols
153 '/\\' { ITbiglam } -- GHC-extension symbols
155 '{' { ITocurly } -- special symbols
157 vccurly { ITvccurly } -- virtual close curly (from layout)
168 VARID { ITvarid $$ } -- identifiers
170 VARSYM { ITvarsym $$ }
171 CONSYM { ITconsym $$ }
172 QVARID { ITqvarid $$ }
173 QCONID { ITqconid $$ }
174 QVARSYM { ITqvarsym $$ }
175 QCONSYM { ITqconsym $$ }
177 PRAGMA { ITpragma $$ }
180 STRING { ITstring $$ }
181 INTEGER { ITinteger $$ }
182 RATIONAL { ITrational $$ }
184 PRIMCHAR { ITprimchar $$ }
185 PRIMSTRING { ITprimstring $$ }
186 PRIMINTEGER { ITprimint $$ }
187 PRIMFLOAT { ITprimfloat $$ }
188 PRIMDOUBLE { ITprimdouble $$ }
189 CLITLIT { ITlitlit $$ }
191 UNKNOWN { ITunknown $$ }
193 %monad { P } { thenP } { returnP }
194 %lexer { lexer } { ITeof }
199 -----------------------------------------------------------------------------
202 module :: { RdrNameHsModule }
203 : srcloc 'module' modid maybeexports 'where' body
204 { HsModule $3 Nothing $4 (fst $6) (snd $6) $1 }
206 { HsModule mAIN_Name Nothing Nothing (fst $2) (snd $2) $1 }
208 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
210 | layout_on top close { $2 }
212 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
213 : importdecls ';' cvtopdecls { (reverse $1,$3) }
214 | importdecls { (reverse $1,[]) }
215 | cvtopdecls { ([],$1) }
217 cvtopdecls :: { [RdrNameHsDecl] }
218 : topdecls { cvTopDecls (groupBindings $1)}
220 -----------------------------------------------------------------------------
223 maybeexports :: { Maybe [RdrNameIE] }
224 : '(' exportlist ')' { Just $2 }
225 | {- empty -} { Nothing }
227 exportlist :: { [RdrNameIE] }
228 : exportlist ',' export { $3 : $1 }
229 | exportlist ',' { $1 }
233 -- GHC extension: we allow things like [] and (,,,) to be exported
234 export :: { RdrNameIE }
236 | gtycon { IEThingAbs $1 }
237 | gtycon '(' '..' ')' { IEThingAll $1 }
238 | gtycon '(' ')' { IEThingWith $1 [] }
239 | gtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
240 | 'module' modid { IEModuleContents $2 }
242 qcnames :: { [RdrName] }
243 : qcnames ',' qcname { $3 : $1 }
246 qcname :: { RdrName }
250 -----------------------------------------------------------------------------
251 -- Import Declarations
253 -- import decls can be *empty*, or even just a string of semicolons
254 -- whereas topdecls must contain at least one topdecl.
256 importdecls :: { [RdrNameImportDecl] }
257 : importdecls ';' importdecl { $3 : $1 }
258 | importdecls ';' { $1 }
259 | importdecl { [ $1 ] }
262 importdecl :: { RdrNameImportDecl }
263 : 'import' srcloc maybe_src optqualified CONID maybeas maybeimpspec
264 { ImportDecl (mkSrcModuleFS $5) $3 $4 $6 $7 $2 }
266 maybe_src :: { WhereFrom }
267 : '{-# SOURCE' '#-}' { ImportByUserSource }
268 | {- empty -} { ImportByUser }
270 optqualified :: { Bool }
271 : 'qualified' { True }
272 | {- empty -} { False }
274 maybeas :: { Maybe ModuleName }
275 : 'as' modid { Just $2 }
276 | {- empty -} { Nothing }
278 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
279 : impspec { Just $1 }
280 | {- empty -} { Nothing }
282 impspec :: { (Bool, [RdrNameIE]) }
283 : '(' exportlist ')' { (False, reverse $2) }
284 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
286 -----------------------------------------------------------------------------
287 -- Fixity Declarations
291 | INTEGER {% checkPrec $1 `thenP_`
292 returnP (fromInteger $1) }
294 infix :: { FixityDirection }
296 | 'infixl' { InfixL }
297 | 'infixr' { InfixR }
300 : ops ',' op { $3 : $1 }
303 -----------------------------------------------------------------------------
304 -- Top-Level Declarations
306 topdecls :: { [RdrBinding] }
307 : topdecls ';' topdecl { ($3 : $1) }
308 | topdecls ';' { $1 }
311 topdecl :: { RdrBinding }
312 : srcloc 'type' simpletype '=' type
313 { RdrHsDecl (TyClD (TySynonym (fst $3) (snd $3) $5 $1)) }
315 | srcloc 'data' ctype '=' constrs deriving
316 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
317 returnP (RdrHsDecl (TyClD
318 (TyData DataType cs c ts (reverse $5) $6
319 NoDataPragmas $1))) }
321 | srcloc 'newtype' ctype '=' newconstr deriving
322 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
323 returnP (RdrHsDecl (TyClD
324 (TyData NewType cs c ts [$5] $6
325 NoDataPragmas $1))) }
327 | srcloc 'class' ctype where
328 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
330 = cvMonoBindsAndSigs cvClassOpSig
333 returnP (RdrHsDecl (TyClD
334 (mkClassDecl cs c ts sigs binds
335 NoClassPragmas $1))) }
337 | srcloc 'instance' inst_type where
339 = cvMonoBindsAndSigs cvInstDeclSig
342 (InstDecl $3 binds sigs dummyRdrVarName $1)) }
344 | srcloc 'default' '(' types0 ')'
345 { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
347 | srcloc 'foreign' 'import' callconv ext_name
348 unsafe_flag varid_no_unsafe '::' sigtype
349 { RdrHsDecl (ForD (ForeignDecl $7 (FoImport $6) $9 (mkExtName $5 $7) $4 $1)) }
351 | srcloc 'foreign' 'export' callconv ext_name varid '::' sigtype
352 { RdrHsDecl (ForD (ForeignDecl $6 FoExport $8 (mkExtName $5 $6) $4 $1)) }
354 | srcloc 'foreign' 'label' ext_name varid '::' sigtype
355 { RdrHsDecl (ForD (ForeignDecl $5 FoLabel $7 (mkExtName $4 $5)
356 defaultCallConv $1)) }
360 decls :: { [RdrBinding] }
361 : decls ';' decl { $3 : $1 }
366 decl :: { RdrBinding }
369 | valdef { RdrValBinding $1 }
370 | '{-# INLINE' srcloc opt_phase qvar '#-}' { RdrSig (InlineSig $4 $3 $2) }
371 | '{-# NOINLINE' srcloc opt_phase qvar '#-}' { RdrSig (NoInlineSig $4 $3 $2) }
372 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
373 { foldr1 RdrAndBindings
374 (map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
375 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
376 { RdrSig (SpecInstSig $4 $2) }
377 | '{-# RULES' rules '#-}' { $2 }
379 opt_phase :: { Maybe Int }
380 : INTEGER { Just (fromInteger $1) }
381 | {- empty -} { Nothing }
383 sigtypes :: { [RdrNameHsType] }
385 | sigtypes ',' sigtype { $3 : $1 }
387 wherebinds :: { RdrNameHsBinds }
388 : where { cvBinds cvValSig (groupBindings $1) }
390 where :: { [RdrBinding] }
391 : 'where' decllist { $2 }
394 declbinds :: { RdrNameHsBinds }
395 : decllist { cvBinds cvValSig (groupBindings $1) }
397 decllist :: { [RdrBinding] }
398 : '{' decls '}' { $2 }
399 | layout_on decls close { $2 }
401 fixdecl :: { RdrBinding }
402 : srcloc infix prec ops { foldr1 RdrAndBindings
403 [ RdrSig (FixSig (FixitySig n
407 signdecl :: { RdrBinding }
408 : vars srcloc '::' sigtype { foldr1 RdrAndBindings
409 [ RdrSig (Sig n $4 $2) | n <- $1 ] }
411 sigtype :: { RdrNameHsType }
412 : ctype { mkHsForAllTy Nothing [] $1 }
415 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
416 instead of qvar, we get another shift/reduce-conflict. Consider the
419 { (+) :: ... } only var
420 { (+) x y = ... } could (incorrectly) be qvar
422 We re-use expressions for patterns, so a qvar would be allowed in patterns
423 instead of a var only (which would be correct). But deciding what the + is,
424 would require more lookahead. So let's check for ourselves...
427 vars :: { [RdrName] }
428 : vars ',' var { $3 : $1 }
431 -----------------------------------------------------------------------------
432 -- Transformation Rules
434 rules :: { RdrBinding }
435 : rules ';' rule { $1 `RdrAndBindings` $3 }
438 | {- empty -} { RdrNullBind }
440 rule :: { RdrBinding }
441 : STRING rule_forall fexp '=' srcloc exp
442 { RdrHsDecl (RuleD (RuleDecl $1 [] $2 $3 $6 $5)) }
444 rule_forall :: { [RdrNameRuleBndr] }
445 : 'forall' rule_var_list '.' { $2 }
448 rule_var_list :: { [RdrNameRuleBndr] }
450 | rule_var rule_var_list { $1 : $2 }
452 rule_var :: { RdrNameRuleBndr }
453 : varid { RuleBndr $1 }
454 | '(' varid '::' ctype ')' { RuleBndrSig $2 $4 }
456 -----------------------------------------------------------------------------
457 -- Foreign import/export
460 : 'stdcall' { stdCallConv }
461 | 'ccall' { cCallConv }
462 | {- empty -} { defaultCallConv }
464 unsafe_flag :: { Bool }
466 | {- empty -} { False }
468 ext_name :: { Maybe ExtName }
469 : 'dynamic' { Just Dynamic }
470 | STRING { Just (ExtName $1 Nothing) }
471 | STRING STRING { Just (ExtName $2 (Just $1)) }
472 | {- empty -} { Nothing }
474 -----------------------------------------------------------------------------
477 {- ToDo: forall stuff -}
479 type :: { RdrNameHsType }
480 : btype '->' type { MonoFunTy $1 $3 }
483 btype :: { RdrNameHsType }
484 : btype atype { MonoTyApp $1 $2 }
487 atype :: { RdrNameHsType }
488 : gtycon { MonoTyVar $1 }
489 | tyvar { MonoTyVar $1 }
490 | '(' type ',' types ')' { MonoTupleTy ($2 : reverse $4) True }
491 | '(#' types '#)' { MonoTupleTy (reverse $2) False }
492 | '[' type ']' { MonoListTy $2 }
493 | '(' ctype ')' { $2 }
495 gtycon :: { RdrName }
497 | '(' ')' { unitTyCon_RDR }
498 | '(' '->' ')' { funTyCon_RDR }
499 | '[' ']' { listTyCon_RDR }
500 | '(' commas ')' { tupleTyCon_RDR $2 }
502 -- An inst_type is what occurs in the head of an instance decl
503 -- e.g. (Foo a, Gaz b) => Wibble a b
504 -- It's kept as a single type, with a MonoDictTy at the right
505 -- hand corner, for convenience.
506 inst_type :: { RdrNameHsType }
507 : ctype {% checkInstType $1 }
509 ctype :: { RdrNameHsType }
510 : 'forall' tyvars '.' context type
511 { mkHsForAllTy (Just $2) $4 $5 }
512 | 'forall' tyvars '.' type { mkHsForAllTy (Just $2) [] $4 }
513 | context type { mkHsForAllTy Nothing $1 $2 }
514 -- A type of form (context => type) is an *implicit* HsForAllTy
517 types0 :: { [RdrNameHsType] }
521 types :: { [RdrNameHsType] }
523 | types ',' type { $3 : $1 }
525 simpletype :: { (RdrName, [RdrNameHsTyVar]) }
526 : tycon tyvars { ($1, reverse $2) }
528 tyvars :: { [RdrNameHsTyVar] }
529 : tyvars tyvar { UserTyVar $2 : $1 }
532 -----------------------------------------------------------------------------
533 -- Datatype declarations
535 constrs :: { [RdrNameConDecl] }
536 : constrs '|' constr { $3 : $1 }
539 constr :: { RdrNameConDecl }
540 : srcloc forall context constr_stuff
541 { ConDecl (fst $4) $2 $3 (snd $4) $1 }
542 | srcloc forall constr_stuff
543 { ConDecl (fst $3) $2 [] (snd $3) $1 }
545 forall :: { [RdrNameHsTyVar] }
546 : 'forall' tyvars '.' { $2 }
549 context :: { RdrNameContext }
550 : btype '=>' {% checkContext $1 }
552 constr_stuff :: { (RdrName, RdrNameConDetails) }
553 : scontype { (fst $1, VanillaCon (snd $1)) }
554 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
555 | con '{' fielddecls '}' { ($1, RecCon (reverse $3)) }
557 newconstr :: { RdrNameConDecl }
558 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
559 | srcloc conid '{' var '::' type '}'
560 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
562 scontype :: { (RdrName, [RdrNameBangType]) }
563 : btype {% splitForConApp $1 [] }
566 scontype1 :: { (RdrName, [RdrNameBangType]) }
567 : btype '!' atype {% splitForConApp $1 [Banged $3] }
568 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
570 satype :: { RdrNameBangType }
571 : atype { Unbanged $1 }
572 | '!' atype { Banged $2 }
574 sbtype :: { RdrNameBangType }
575 : btype { Unbanged $1 }
576 | '!' atype { Banged $2 }
578 fielddecls :: { [([RdrName],RdrNameBangType)] }
579 : fielddecls ',' fielddecl { $3 : $1 }
582 fielddecl :: { ([RdrName],RdrNameBangType) }
583 : vars '::' stype { (reverse $1, $3) }
585 stype :: { RdrNameBangType }
586 : type { Unbanged $1 }
587 | '!' atype { Banged $2 }
589 deriving :: { Maybe [RdrName] }
590 : {- empty -} { Nothing }
591 | 'deriving' qtycls { Just [$2] }
592 | 'deriving' '(' ')' { Just [] }
593 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
595 dclasses :: { [RdrName] }
596 : dclasses ',' qtycls { $3 : $1 }
599 -----------------------------------------------------------------------------
602 valdef :: { RdrNameMonoBinds }
603 : infixexp {-ToDo: opt_sig-} srcloc rhs
604 {% checkValDef $1 Nothing $3 $2 }
606 rhs :: { RdrNameGRHSs }
607 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
609 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
611 gdrhs :: { [RdrNameGRHS] }
612 : gdrhs gdrh { $2 : $1 }
615 gdrh :: { RdrNameGRHS }
616 : '|' srcloc quals '=' exp { GRHS (reverse
617 (ExprStmt $5 $2 : $3)) $2 }
619 -----------------------------------------------------------------------------
622 exp :: { RdrNameHsExpr }
623 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
626 infixexp :: { RdrNameHsExpr }
628 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
630 exp10 :: { RdrNameHsExpr }
631 : '\\' aexp aexps opt_asig '->' srcloc exp
632 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
633 returnP (HsLam (Match [] ps $4
634 (GRHSs (unguardedRHS $7 $6)
635 EmptyBinds Nothing))) }
636 | 'let' declbinds 'in' exp { HsLet $2 $4 }
637 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
638 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
639 | '-' fexp { NegApp $2 (error "NegApp") }
640 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
642 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
643 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
644 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
645 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
647 | '_scc_' STRING exp { if opt_SccProfilingOn
653 ccallid :: { FAST_STRING }
657 fexp :: { RdrNameHsExpr }
658 : fexp aexp { HsApp $1 $2 }
661 aexps0 :: { [RdrNameHsExpr] }
662 : aexps { reverse $1 }
664 aexps :: { [RdrNameHsExpr] }
665 : aexps aexp { $2 : $1 }
668 aexp :: { RdrNameHsExpr }
669 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
672 aexp1 :: { RdrNameHsExpr }
675 | literal { HsLit $1 }
676 | '(' exp ')' { HsPar $2 }
677 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
678 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
679 | '[' list ']' { $2 }
680 | '(' infixexp qop ')' { SectionL $2 $3 }
681 | '(' qopm infixexp ')' { SectionR $2 $3 }
682 | qvar '@' aexp { EAsPat $1 $3 }
684 | '~' aexp1 { ELazyPat $2 }
687 : commas ',' { $1 + 1 }
690 texps :: { [RdrNameHsExpr] }
691 : texps ',' exp { $3 : $1 }
694 -----------------------------------------------------------------------------
697 -- The rules below are little bit contorted to keep lexps left-recursive while
698 -- avoiding another shift/reduce-conflict.
700 list :: { RdrNameHsExpr }
701 : exp { ExplicitList [$1] }
702 | lexps { ExplicitList (reverse $1) }
703 | exp '..' { ArithSeqIn (From $1) }
704 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
705 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
706 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
707 | exp srcloc '|' quals { HsDo ListComp (reverse
708 (ReturnStmt $1 : $4)) $2 }
710 lexps :: { [RdrNameHsExpr] }
711 : lexps ',' exp { $3 : $1 }
712 | exp ',' exp { [$3,$1] }
714 -----------------------------------------------------------------------------
715 -- List Comprehensions
717 quals :: { [RdrNameStmt] }
718 : quals ',' qual { $3 : $1 }
721 qual :: { RdrNameStmt }
722 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
723 returnP (BindStmt p $4 $1) }
724 | srcloc exp { GuardStmt $2 $1 }
725 | srcloc 'let' declbinds { LetStmt $3 }
727 -----------------------------------------------------------------------------
730 altslist :: { [RdrNameMatch] }
731 : '{' alts '}' { reverse $2 }
732 | layout_on alts close { reverse $2 }
735 alts :: { [RdrNameMatch] }
736 : alts ';' alt { $3 : $1 }
741 alt :: { RdrNameMatch }
742 : infixexp opt_sig ralt wherebinds
743 {% checkPattern $1 `thenP` \p ->
744 returnP (Match [] [p] $2
745 (GRHSs $3 $4 Nothing)) }
747 opt_sig :: { Maybe RdrNameHsType }
748 : {- empty -} { Nothing }
749 | '::' type { Just $2 }
751 opt_asig :: { Maybe RdrNameHsType }
752 : {- empty -} { Nothing }
753 | '::' atype { Just $2 }
755 ralt :: { [RdrNameGRHS] }
756 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
757 | gdpats { (reverse $1) }
759 gdpats :: { [RdrNameGRHS] }
760 : gdpats gdpat { $2 : $1 }
763 gdpat :: { RdrNameGRHS }
764 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
766 -----------------------------------------------------------------------------
767 -- Statement sequences
769 stmtlist :: { [RdrNameStmt] }
770 : '{' stmts '}' { reverse $2 }
771 | layout_on_for_do stmts close { reverse $2 }
773 -- Stmt list should really end in an expression, but it's not
774 -- convenient to enforce this here, so we throw out erroneous
775 -- statement sequences in the renamer instead.
777 stmts :: { [RdrNameStmt] }
781 stmts1 :: { [RdrNameStmt] }
782 : stmts1 ';' stmt { $3 : $1 }
786 stmt :: { RdrNameStmt }
787 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
788 returnP (BindStmt p $4 $1) }
789 | srcloc exp { ExprStmt $2 $1 }
790 | srcloc 'let' declbinds { LetStmt $3 }
792 -----------------------------------------------------------------------------
793 -- Record Field Update/Construction
795 fbinds :: { RdrNameHsRecordBinds }
796 : fbinds ',' fbind { $3 : $1 }
801 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
802 : qvar '=' exp { ($1,$3,False) }
804 -----------------------------------------------------------------------------
805 -- Variables, Constructors and Operators.
808 : '(' ')' { unitCon_RDR }
809 | '[' ']' { nilCon_RDR }
810 | '(' commas ')' { tupleCon_RDR $2 }
815 | '(' varsym ')' { $2 }
819 | '(' qvarsym ')' { $2 }
823 | '(' consym ')' { $2 }
827 | '(' qconsym ')' { $2 }
831 | '`' varid '`' { $2 }
833 qvarop :: { RdrName }
835 | '`' qvarid '`' { $2 }
837 qvaropm :: { RdrName }
839 | '`' qvarid '`' { $2 }
843 | '`' conid '`' { $2 }
845 qconop :: { RdrName }
847 | '`' qconid '`' { $2 }
849 -----------------------------------------------------------------------------
852 op :: { RdrName } -- used in infix decls
856 qop :: { RdrNameHsExpr } -- used in sections
857 : qvarop { HsVar $1 }
858 | qconop { HsVar $1 }
860 qopm :: { RdrNameHsExpr } -- used in sections
861 : qvaropm { HsVar $1 }
862 | qconop { HsVar $1 }
864 -----------------------------------------------------------------------------
867 qvarid :: { RdrName }
869 | QVARID { case $1 of { (mod,n) ->
870 mkSrcQual varName mod n } }
873 : VARID { mkSrcUnqual varName $1 }
874 | 'as' { as_var_RDR }
875 | 'qualified' { qualified_var_RDR }
876 | 'hiding' { hiding_var_RDR }
877 | 'forall' { forall_var_RDR }
878 | 'export' { export_var_RDR }
879 | 'label' { label_var_RDR }
880 | 'dynamic' { dynamic_var_RDR }
881 | 'unsafe' { unsafe_var_RDR }
882 | 'stdcall' { stdcall_var_RDR }
883 | 'ccall' { ccall_var_RDR }
885 varid_no_unsafe :: { RdrName }
886 : VARID { mkSrcUnqual varName $1 }
887 | 'as' { as_var_RDR }
888 | 'qualified' { qualified_var_RDR }
889 | 'hiding' { hiding_var_RDR }
890 | 'forall' { forall_var_RDR }
891 | 'export' { export_var_RDR }
892 | 'label' { label_var_RDR }
893 | 'dynamic' { dynamic_var_RDR }
894 | 'stdcall' { stdcall_var_RDR }
895 | 'ccall' { ccall_var_RDR }
897 -----------------------------------------------------------------------------
900 qconid :: { RdrName }
902 | QCONID { case $1 of { (mod,n) ->
903 mkSrcQual dataName mod n } }
906 : CONID { mkSrcUnqual dataName $1 }
908 -----------------------------------------------------------------------------
911 qconsym :: { RdrName }
913 | QCONSYM { case $1 of { (mod,n) ->
914 mkSrcQual dataName mod n } }
916 consym :: { RdrName }
917 : CONSYM { mkSrcUnqual dataName $1 }
919 -----------------------------------------------------------------------------
922 qvarsym :: { RdrName }
926 qvarsymm :: { RdrName }
930 varsym :: { RdrName }
931 : VARSYM { mkSrcUnqual varName $1 }
936 varsymm :: { RdrName } -- varsym not including '-'
937 : VARSYM { mkSrcUnqual varName $1 }
941 qvarsym1 :: { RdrName }
942 : QVARSYM { case $1 of { (mod,n) ->
943 mkSrcQual varName mod n } }
946 : INTEGER { HsInt $1 }
948 | RATIONAL { HsFrac $1 }
949 | STRING { HsString $1 }
951 | PRIMINTEGER { HsIntPrim $1 }
952 | PRIMCHAR { HsCharPrim $1 }
953 | PRIMSTRING { HsStringPrim $1 }
954 | PRIMFLOAT { HsFloatPrim $1 }
955 | PRIMDOUBLE { HsDoublePrim $1 }
956 | CLITLIT { HsLitLit $1 }
958 srcloc :: { SrcLoc } : {% getSrcLocP }
960 -----------------------------------------------------------------------------
964 : vccurly { () } -- context popped in lexer.
965 | error {% popContext }
967 layout_on :: { () } : {% layoutOn True{-strict-} }
968 layout_on_for_do :: { () } : {% layoutOn False }
970 -----------------------------------------------------------------------------
971 -- Miscellaneous (mostly renamings)
973 modid :: { ModuleName }
974 : CONID { mkSrcModuleFS $1 }
977 : CONID { mkSrcUnqual tcClsName $1 }
979 qtycon :: { RdrName }
981 | QCONID { case $1 of { (mod,n) ->
982 mkSrcQual tcClsName mod n } }
984 qtycls :: { RdrName }
988 : VARID { mkSrcUnqual tvName $1 }
989 | 'as' { as_tyvar_RDR }
990 | 'qualified' { qualified_tyvar_RDR }
991 | 'hiding' { hiding_tyvar_RDR }
992 | 'export' { export_tyvar_RDR }
993 | 'label' { label_tyvar_RDR }
994 | 'dynamic' { dynamic_tyvar_RDR }
995 | 'unsafe' { unsafe_tyvar_RDR }
996 | 'stdcall' { stdcall_tyvar_RDR }
997 | 'ccall' { ccall_tyvar_RDR }
1000 -----------------------------------------------------------------------------
1004 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)