2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.16 1999/11/25 10:34:53 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 -- A ctype is a for-all type
478 ctype :: { RdrNameHsType }
479 : 'forall' tyvars '.' ctype { mkHsForAllTy (Just $2) [] $4 }
480 | context type { mkHsForAllTy Nothing $1 $2 }
481 -- A type of form (context => type) is an *implicit* HsForAllTy
484 type :: { RdrNameHsType }
485 : btype '->' type { MonoFunTy $1 $3 }
488 btype :: { RdrNameHsType }
489 : btype atype { MonoTyApp $1 $2 }
492 atype :: { RdrNameHsType }
493 : gtycon { MonoTyVar $1 }
494 | tyvar { MonoTyVar $1 }
495 | '(' type ',' types ')' { MonoTupleTy ($2 : reverse $4) True }
496 | '(#' types '#)' { MonoTupleTy (reverse $2) False }
497 | '[' type ']' { MonoListTy $2 }
498 | '(' ctype ')' { $2 }
500 gtycon :: { RdrName }
502 | '(' ')' { unitTyCon_RDR }
503 | '(' '->' ')' { funTyCon_RDR }
504 | '[' ']' { listTyCon_RDR }
505 | '(' commas ')' { tupleTyCon_RDR $2 }
507 -- An inst_type is what occurs in the head of an instance decl
508 -- e.g. (Foo a, Gaz b) => Wibble a b
509 -- It's kept as a single type, with a MonoDictTy at the right
510 -- hand corner, for convenience.
511 inst_type :: { RdrNameHsType }
512 : ctype {% checkInstType $1 }
514 types0 :: { [RdrNameHsType] }
518 types :: { [RdrNameHsType] }
520 | types ',' type { $3 : $1 }
522 simpletype :: { (RdrName, [RdrNameHsTyVar]) }
523 : tycon tyvars { ($1, reverse $2) }
525 tyvars :: { [RdrNameHsTyVar] }
526 : tyvars tyvar { UserTyVar $2 : $1 }
529 -----------------------------------------------------------------------------
530 -- Datatype declarations
532 constrs :: { [RdrNameConDecl] }
533 : constrs '|' constr { $3 : $1 }
536 constr :: { RdrNameConDecl }
537 : srcloc forall context constr_stuff
538 { ConDecl (fst $4) $2 $3 (snd $4) $1 }
539 | srcloc forall constr_stuff
540 { ConDecl (fst $3) $2 [] (snd $3) $1 }
542 forall :: { [RdrNameHsTyVar] }
543 : 'forall' tyvars '.' { $2 }
546 context :: { RdrNameContext }
547 : btype '=>' {% checkContext $1 }
549 constr_stuff :: { (RdrName, RdrNameConDetails) }
550 : scontype { (fst $1, VanillaCon (snd $1)) }
551 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
552 | con '{' fielddecls '}' { ($1, RecCon (reverse $3)) }
554 newconstr :: { RdrNameConDecl }
555 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
556 | srcloc conid '{' var '::' type '}'
557 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
559 scontype :: { (RdrName, [RdrNameBangType]) }
560 : btype {% splitForConApp $1 [] }
563 scontype1 :: { (RdrName, [RdrNameBangType]) }
564 : btype '!' atype {% splitForConApp $1 [Banged $3] }
565 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
567 satype :: { RdrNameBangType }
568 : atype { Unbanged $1 }
569 | '!' atype { Banged $2 }
571 sbtype :: { RdrNameBangType }
572 : btype { Unbanged $1 }
573 | '!' atype { Banged $2 }
575 fielddecls :: { [([RdrName],RdrNameBangType)] }
576 : fielddecls ',' fielddecl { $3 : $1 }
579 fielddecl :: { ([RdrName],RdrNameBangType) }
580 : vars '::' stype { (reverse $1, $3) }
582 stype :: { RdrNameBangType }
583 : ctype { Unbanged $1 }
584 | '!' atype { Banged $2 }
586 deriving :: { Maybe [RdrName] }
587 : {- empty -} { Nothing }
588 | 'deriving' qtycls { Just [$2] }
589 | 'deriving' '(' ')' { Just [] }
590 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
592 dclasses :: { [RdrName] }
593 : dclasses ',' qtycls { $3 : $1 }
596 -----------------------------------------------------------------------------
599 valdef :: { RdrNameMonoBinds }
600 : infixexp {-ToDo: opt_sig-} srcloc rhs
601 {% checkValDef $1 Nothing $3 $2 }
603 rhs :: { RdrNameGRHSs }
604 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
606 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
608 gdrhs :: { [RdrNameGRHS] }
609 : gdrhs gdrh { $2 : $1 }
612 gdrh :: { RdrNameGRHS }
613 : '|' srcloc quals '=' exp { GRHS (reverse
614 (ExprStmt $5 $2 : $3)) $2 }
616 -----------------------------------------------------------------------------
619 exp :: { RdrNameHsExpr }
620 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
623 infixexp :: { RdrNameHsExpr }
625 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
627 exp10 :: { RdrNameHsExpr }
628 : '\\' aexp aexps opt_asig '->' srcloc exp
629 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
630 returnP (HsLam (Match [] ps $4
631 (GRHSs (unguardedRHS $7 $6)
632 EmptyBinds Nothing))) }
633 | 'let' declbinds 'in' exp { HsLet $2 $4 }
634 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
635 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
636 | '-' fexp { NegApp $2 (error "NegApp") }
637 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
639 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
640 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
641 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
642 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
644 | '_scc_' STRING exp { if opt_SccProfilingOn
650 ccallid :: { FAST_STRING }
654 fexp :: { RdrNameHsExpr }
655 : fexp aexp { HsApp $1 $2 }
658 aexps0 :: { [RdrNameHsExpr] }
659 : aexps { reverse $1 }
661 aexps :: { [RdrNameHsExpr] }
662 : aexps aexp { $2 : $1 }
665 aexp :: { RdrNameHsExpr }
666 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
669 aexp1 :: { RdrNameHsExpr }
672 | literal { HsLit $1 }
673 | '(' exp ')' { HsPar $2 }
674 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
675 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
676 | '[' list ']' { $2 }
677 | '(' infixexp qop ')' { SectionL $2 $3 }
678 | '(' qopm infixexp ')' { SectionR $2 $3 }
679 | qvar '@' aexp { EAsPat $1 $3 }
681 | '~' aexp1 { ELazyPat $2 }
684 : commas ',' { $1 + 1 }
687 texps :: { [RdrNameHsExpr] }
688 : texps ',' exp { $3 : $1 }
691 -----------------------------------------------------------------------------
694 -- The rules below are little bit contorted to keep lexps left-recursive while
695 -- avoiding another shift/reduce-conflict.
697 list :: { RdrNameHsExpr }
698 : exp { ExplicitList [$1] }
699 | lexps { ExplicitList (reverse $1) }
700 | exp '..' { ArithSeqIn (From $1) }
701 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
702 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
703 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
704 | exp srcloc '|' quals { HsDo ListComp (reverse
705 (ReturnStmt $1 : $4)) $2 }
707 lexps :: { [RdrNameHsExpr] }
708 : lexps ',' exp { $3 : $1 }
709 | exp ',' exp { [$3,$1] }
711 -----------------------------------------------------------------------------
712 -- List Comprehensions
714 quals :: { [RdrNameStmt] }
715 : quals ',' qual { $3 : $1 }
718 qual :: { RdrNameStmt }
719 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
720 returnP (BindStmt p $4 $1) }
721 | srcloc exp { GuardStmt $2 $1 }
722 | srcloc 'let' declbinds { LetStmt $3 }
724 -----------------------------------------------------------------------------
727 altslist :: { [RdrNameMatch] }
728 : '{' alts '}' { reverse $2 }
729 | layout_on alts close { reverse $2 }
732 alts :: { [RdrNameMatch] }
733 : alts ';' alt { $3 : $1 }
738 alt :: { RdrNameMatch }
739 : infixexp opt_sig ralt wherebinds
740 {% checkPattern $1 `thenP` \p ->
741 returnP (Match [] [p] $2
742 (GRHSs $3 $4 Nothing)) }
744 opt_sig :: { Maybe RdrNameHsType }
745 : {- empty -} { Nothing }
746 | '::' type { Just $2 }
748 opt_asig :: { Maybe RdrNameHsType }
749 : {- empty -} { Nothing }
750 | '::' atype { Just $2 }
752 ralt :: { [RdrNameGRHS] }
753 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
754 | gdpats { (reverse $1) }
756 gdpats :: { [RdrNameGRHS] }
757 : gdpats gdpat { $2 : $1 }
760 gdpat :: { RdrNameGRHS }
761 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
763 -----------------------------------------------------------------------------
764 -- Statement sequences
766 stmtlist :: { [RdrNameStmt] }
767 : '{' stmts '}' { reverse $2 }
768 | layout_on_for_do stmts close { reverse $2 }
770 -- Stmt list should really end in an expression, but it's not
771 -- convenient to enforce this here, so we throw out erroneous
772 -- statement sequences in the renamer instead.
774 stmts :: { [RdrNameStmt] }
778 stmts1 :: { [RdrNameStmt] }
779 : stmts1 ';' stmt { $3 : $1 }
783 stmt :: { RdrNameStmt }
784 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
785 returnP (BindStmt p $4 $1) }
786 | srcloc exp { ExprStmt $2 $1 }
787 | srcloc 'let' declbinds { LetStmt $3 }
789 -----------------------------------------------------------------------------
790 -- Record Field Update/Construction
792 fbinds :: { RdrNameHsRecordBinds }
793 : fbinds ',' fbind { $3 : $1 }
798 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
799 : qvar '=' exp { ($1,$3,False) }
801 -----------------------------------------------------------------------------
802 -- Variables, Constructors and Operators.
805 : '(' ')' { unitCon_RDR }
806 | '[' ']' { nilCon_RDR }
807 | '(' commas ')' { tupleCon_RDR $2 }
812 | '(' varsym ')' { $2 }
816 | '(' qvarsym ')' { $2 }
820 | '(' consym ')' { $2 }
824 | '(' qconsym ')' { $2 }
828 | '`' varid '`' { $2 }
830 qvarop :: { RdrName }
832 | '`' qvarid '`' { $2 }
834 qvaropm :: { RdrName }
836 | '`' qvarid '`' { $2 }
840 | '`' conid '`' { $2 }
842 qconop :: { RdrName }
844 | '`' qconid '`' { $2 }
846 -----------------------------------------------------------------------------
849 op :: { RdrName } -- used in infix decls
853 qop :: { RdrNameHsExpr } -- used in sections
854 : qvarop { HsVar $1 }
855 | qconop { HsVar $1 }
857 qopm :: { RdrNameHsExpr } -- used in sections
858 : qvaropm { HsVar $1 }
859 | qconop { HsVar $1 }
861 -----------------------------------------------------------------------------
864 qvarid :: { RdrName }
866 | QVARID { case $1 of { (mod,n) ->
867 mkSrcQual varName mod n } }
870 : VARID { mkSrcUnqual varName $1 }
871 | 'as' { as_var_RDR }
872 | 'qualified' { qualified_var_RDR }
873 | 'hiding' { hiding_var_RDR }
874 | 'forall' { forall_var_RDR }
875 | 'export' { export_var_RDR }
876 | 'label' { label_var_RDR }
877 | 'dynamic' { dynamic_var_RDR }
878 | 'unsafe' { unsafe_var_RDR }
879 | 'stdcall' { stdcall_var_RDR }
880 | 'ccall' { ccall_var_RDR }
882 varid_no_unsafe :: { RdrName }
883 : VARID { mkSrcUnqual varName $1 }
884 | 'as' { as_var_RDR }
885 | 'qualified' { qualified_var_RDR }
886 | 'hiding' { hiding_var_RDR }
887 | 'forall' { forall_var_RDR }
888 | 'export' { export_var_RDR }
889 | 'label' { label_var_RDR }
890 | 'dynamic' { dynamic_var_RDR }
891 | 'stdcall' { stdcall_var_RDR }
892 | 'ccall' { ccall_var_RDR }
894 -----------------------------------------------------------------------------
897 qconid :: { RdrName }
899 | QCONID { case $1 of { (mod,n) ->
900 mkSrcQual dataName mod n } }
903 : CONID { mkSrcUnqual dataName $1 }
905 -----------------------------------------------------------------------------
908 qconsym :: { RdrName }
910 | QCONSYM { case $1 of { (mod,n) ->
911 mkSrcQual dataName mod n } }
913 consym :: { RdrName }
914 : CONSYM { mkSrcUnqual dataName $1 }
916 -----------------------------------------------------------------------------
919 qvarsym :: { RdrName }
923 qvarsymm :: { RdrName }
927 varsym :: { RdrName }
928 : VARSYM { mkSrcUnqual varName $1 }
933 varsymm :: { RdrName } -- varsym not including '-'
934 : VARSYM { mkSrcUnqual varName $1 }
938 qvarsym1 :: { RdrName }
939 : QVARSYM { case $1 of { (mod,n) ->
940 mkSrcQual varName mod n } }
943 : INTEGER { HsInt $1 }
945 | RATIONAL { HsFrac $1 }
946 | STRING { HsString $1 }
948 | PRIMINTEGER { HsIntPrim $1 }
949 | PRIMCHAR { HsCharPrim $1 }
950 | PRIMSTRING { HsStringPrim $1 }
951 | PRIMFLOAT { HsFloatPrim $1 }
952 | PRIMDOUBLE { HsDoublePrim $1 }
953 | CLITLIT { HsLitLit $1 }
955 srcloc :: { SrcLoc } : {% getSrcLocP }
957 -----------------------------------------------------------------------------
961 : vccurly { () } -- context popped in lexer.
962 | error {% popContext }
964 layout_on :: { () } : {% layoutOn True{-strict-} }
965 layout_on_for_do :: { () } : {% layoutOn False }
967 -----------------------------------------------------------------------------
968 -- Miscellaneous (mostly renamings)
970 modid :: { ModuleName }
971 : CONID { mkSrcModuleFS $1 }
974 : CONID { mkSrcUnqual tcClsName $1 }
976 qtycon :: { RdrName }
978 | QCONID { case $1 of { (mod,n) ->
979 mkSrcQual tcClsName mod n } }
981 qtycls :: { RdrName }
985 : VARID { mkSrcUnqual tvName $1 }
986 | 'as' { as_tyvar_RDR }
987 | 'qualified' { qualified_tyvar_RDR }
988 | 'hiding' { hiding_tyvar_RDR }
989 | 'export' { export_tyvar_RDR }
990 | 'label' { label_tyvar_RDR }
991 | 'dynamic' { dynamic_tyvar_RDR }
992 | 'unsafe' { unsafe_tyvar_RDR }
993 | 'stdcall' { stdcall_tyvar_RDR }
994 | 'ccall' { ccall_tyvar_RDR }
997 -----------------------------------------------------------------------------
1001 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)