2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.8 1999/06/28 15:42:33 simonmar 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
67 'default' { ITdefault }
68 'deriving' { ITderiving }
77 'instance' { ITinstance }
80 'newtype' { ITnewtype }
87 'forall' { ITforall } -- GHC extension keywords
88 'foreign' { ITforeign }
91 'dynamic' { ITdynamic }
93 '_ccall_' { ITccall (False, False, False) }
94 '_ccall_GC_' { ITccall (False, False, True) }
95 '_casm_' { ITccall (False, True, False) }
96 '_casm_GC_' { ITccall (False, True, True) }
98 '{-# SPECIALISE' { ITspecialise_prag }
99 '{-# SOURCE' { ITsource_prag }
100 '{-# INLINE' { ITinline_prag }
101 '{-# NOINLINE' { ITnoinline_prag }
102 '{-# RULES' { ITrules_prag }
103 '#-}' { ITclose_prag }
106 '__interface' { ITinterface } -- interface keywords
107 '__export' { IT__export }
108 '__instimport' { ITinstimport }
109 '__forall' { IT__forall }
110 '__letrec' { ITletrec }
111 '__coerce' { ITcoerce }
112 '__depends' { ITdepends }
113 '__inline' { ITinline }
114 '__DEFAULT' { ITdefaultbranch }
116 '__integer' { ITinteger_lit }
117 '__float' { ITfloat_lit }
118 '__rational' { ITrational_lit }
119 '__addr' { ITaddr_lit }
120 '__litlit' { ITlit_lit }
121 '__string' { ITstring_lit }
122 '__ccall' { ITccall $$ }
124 '__sccC' { ITsccAllCafs }
127 '__P' { ITspecialise }
129 '__U' { ITunfold $$ }
130 '__S' { ITstrict $$ }
131 '__M' { ITcprinfo $$ }
134 '..' { ITdotdot } -- reserved symbols
148 '/\\' { ITbiglam } -- GHC-extension symbols
150 '{' { ITocurly } -- special symbols
152 vccurly { ITvccurly } -- virtual close curly (from layout)
163 VARID { ITvarid $$ } -- identifiers
165 VARSYM { ITvarsym $$ }
166 CONSYM { ITconsym $$ }
167 QVARID { ITqvarid $$ }
168 QCONID { ITqconid $$ }
169 QVARSYM { ITqvarsym $$ }
170 QCONSYM { ITqconsym $$ }
172 PRAGMA { ITpragma $$ }
175 STRING { ITstring $$ }
176 INTEGER { ITinteger $$ }
177 RATIONAL { ITrational $$ }
179 PRIMCHAR { ITprimchar $$ }
180 PRIMSTRING { ITprimstring $$ }
181 PRIMINTEGER { ITprimint $$ }
182 PRIMFLOAT { ITprimfloat $$ }
183 PRIMDOUBLE { ITprimdouble $$ }
184 CLITLIT { ITlitlit $$ }
186 UNKNOWN { ITunknown $$ }
188 %monad { P } { thenP } { returnP }
189 %lexer { lexer } { ITeof }
194 -----------------------------------------------------------------------------
197 module :: { RdrNameHsModule }
198 : srcloc 'module' modid maybeexports 'where' body
199 { HsModule $3 Nothing $4 (fst $6) (snd $6) $1 }
201 { HsModule mAIN_Name Nothing Nothing (fst $2) (snd $2) $1 }
203 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
205 | layout_on top close { $2 }
207 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
208 : importdecls ';' cvtopdecls { (reverse $1,$3) }
209 | importdecls { (reverse $1,[]) }
210 | cvtopdecls { ([],$1) }
212 cvtopdecls :: { [RdrNameHsDecl] }
213 : topdecls { cvTopDecls (groupBindings $1)}
215 -----------------------------------------------------------------------------
218 maybeexports :: { Maybe [RdrNameIE] }
219 : '(' exportlist ')' { Just $2 }
220 | {- empty -} { Nothing }
222 exportlist :: { [RdrNameIE] }
223 : exportlist ',' export { $3 : $1 }
224 | exportlist ',' { $1 }
228 -- GHC extension: we allow things like [] and (,,,) to be exported
229 export :: { RdrNameIE }
231 | gtycon { IEThingAbs $1 }
232 | gtycon '(' '..' ')' { IEThingAll $1 }
233 | gtycon '(' ')' { IEThingWith $1 [] }
234 | gtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
235 | 'module' modid { IEModuleContents $2 }
237 qcnames :: { [RdrName] }
238 : qcnames ',' qcname { $3 : $1 }
241 qcname :: { RdrName }
245 -----------------------------------------------------------------------------
246 -- Import Declarations
248 -- import decls can be *empty*, or even just a string of semicolons
249 -- whereas topdecls must contain at least one topdecl.
251 importdecls :: { [RdrNameImportDecl] }
252 : importdecls ';' importdecl { $3 : $1 }
253 | importdecls ';' { $1 }
254 | importdecl { [ $1 ] }
257 importdecl :: { RdrNameImportDecl }
258 : 'import' srcloc maybe_src optqualified CONID maybeas maybeimpspec
259 { ImportDecl (mkSrcModuleFS $5) $3 $4 $6 $7 $2 }
261 maybe_src :: { WhereFrom }
262 : '{-# SOURCE' '#-}' { ImportByUserSource }
263 | {- empty -} { ImportByUser }
265 optqualified :: { Bool }
266 : 'qualified' { True }
267 | {- empty -} { False }
269 maybeas :: { Maybe ModuleName }
270 : 'as' modid { Just $2 }
271 | {- empty -} { Nothing }
273 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
274 : impspec { Just $1 }
275 | {- empty -} { Nothing }
277 impspec :: { (Bool, [RdrNameIE]) }
278 : '(' exportlist ')' { (False, reverse $2) }
279 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
281 -----------------------------------------------------------------------------
282 -- Fixity Declarations
286 | INTEGER {% checkPrec $1 `thenP_`
287 returnP (fromInteger $1) }
289 infix :: { FixityDirection }
291 | 'infixl' { InfixL }
292 | 'infixr' { InfixR }
295 : ops ',' op { $3 : $1 }
298 -----------------------------------------------------------------------------
299 -- Top-Level Declarations
301 topdecls :: { [RdrBinding] }
302 : topdecls ';' topdecl { ($3 : $1) }
303 | topdecls ';' { $1 }
306 topdecl :: { RdrBinding }
307 : srcloc 'type' simpletype '=' type
308 { RdrHsDecl (TyClD (TySynonym (fst $3) (snd $3) $5 $1)) }
310 | srcloc 'data' ctype '=' constrs deriving
311 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
312 returnP (RdrHsDecl (TyClD
313 (TyData DataType cs c ts (reverse $5) $6
314 NoDataPragmas $1))) }
316 | srcloc 'newtype' ctype '=' newconstr deriving
317 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
318 returnP (RdrHsDecl (TyClD
319 (TyData NewType cs c ts [$5] $6
320 NoDataPragmas $1))) }
322 | srcloc 'class' ctype where
323 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
325 = cvMonoBindsAndSigs cvClassOpSig
328 returnP (RdrHsDecl (TyClD
329 (mkClassDecl cs c ts sigs binds
330 NoClassPragmas $1))) }
332 | srcloc 'instance' inst_type where
334 = cvMonoBindsAndSigs cvInstDeclSig
337 (InstDecl $3 binds sigs dummyRdrVarName $1)) }
339 | srcloc 'default' '(' types0 ')'
340 { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
342 | srcloc 'foreign' 'import' callconv ext_name
343 unsafe_flag varid_no_unsafe '::' sigtype
344 { RdrHsDecl (ForD (ForeignDecl $7 (FoImport $6) $9 $5 $4 $1)) }
346 | srcloc 'foreign' 'export' callconv ext_name varid '::' sigtype
347 { RdrHsDecl (ForD (ForeignDecl $6 FoExport $8 $5 $4 $1)) }
349 | srcloc 'foreign' 'label' ext_name varid '::' sigtype
350 { RdrHsDecl (ForD (ForeignDecl $5 FoLabel $7 $4
351 defaultCallConv $1)) }
355 decls :: { [RdrBinding] }
356 : decls ';' decl { $3 : $1 }
361 decl :: { RdrBinding }
364 | valdef { RdrValBinding $1 }
365 | '{-# INLINE' srcloc qvar '#-}' { RdrSig (InlineSig $3 $2) }
366 | '{-# NOINLINE' srcloc qvar '#-}' { RdrSig (NoInlineSig $3 $2) }
367 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
368 { foldr1 RdrAndBindings
369 (map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
370 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
371 { RdrSig (SpecInstSig $4 $2) }
372 | '{-# RULES' rules '#-}' { $2 }
374 sigtypes :: { [RdrNameHsType] }
376 | sigtypes ',' sigtype { $3 : $1 }
378 wherebinds :: { RdrNameHsBinds }
379 : where { cvBinds cvValSig (groupBindings $1) }
381 where :: { [RdrBinding] }
382 : 'where' decllist { $2 }
385 declbinds :: { RdrNameHsBinds }
386 : decllist { cvBinds cvValSig (groupBindings $1) }
388 decllist :: { [RdrBinding] }
389 : '{' decls '}' { $2 }
390 | layout_on decls close { $2 }
392 fixdecl :: { RdrBinding }
393 : srcloc infix prec ops { foldr1 RdrAndBindings
394 [ RdrSig (FixSig (FixitySig n
398 signdecl :: { RdrBinding }
399 : vars srcloc '::' sigtype { foldr1 RdrAndBindings
400 [ RdrSig (Sig n $4 $2) | n <- $1 ] }
402 sigtype :: { RdrNameHsType }
404 HsForAllTy _ _ _ -> $1
405 other -> HsForAllTy Nothing [] $1 }
408 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
409 instead of qvar, we get another shift/reduce-conflict. Consider the
412 { (+) :: ... } only var
413 { (+) x y = ... } could (incorrectly) be qvar
415 We re-use expressions for patterns, so a qvar would be allowed in patterns
416 instead of a var only (which would be correct). But deciding what the + is,
417 would require more lookahead. So let's check for ourselves...
420 vars :: { [RdrName] }
421 : vars ',' var { $3 : $1 }
424 -----------------------------------------------------------------------------
425 -- Transformation Rules
427 rules :: { RdrBinding }
428 : rules ';' rule { $1 `RdrAndBindings` $3 }
431 | {- empty -} { RdrNullBind }
433 rule :: { RdrBinding }
434 : STRING rule_forall fexp '=' srcloc exp
435 { RdrHsDecl (RuleD (RuleDecl $1 [] $2 $3 $6 $5)) }
437 rule_forall :: { [RdrNameRuleBndr] }
438 : 'forall' rule_var_list '.' { $2 }
441 rule_var_list :: { [RdrNameRuleBndr] }
443 | rule_var ',' rule_var_list { $1 : $3 }
445 rule_var :: { RdrNameRuleBndr }
446 : varid { RuleBndr $1 }
447 | varid '::' ctype { RuleBndrSig $1 $3 }
449 -----------------------------------------------------------------------------
450 -- Foreign import/export
453 : VARID {% checkCallConv $1 }
454 | {- empty -} { defaultCallConv }
456 unsafe_flag :: { Bool }
458 | {- empty -} { False }
460 ext_name :: { ExtName }
461 : 'dynamic' { Dynamic }
462 | STRING { ExtName $1 Nothing }
463 | STRING STRING { ExtName $2 (Just $1) }
465 -----------------------------------------------------------------------------
468 {- ToDo: forall stuff -}
470 type :: { RdrNameHsType }
471 : btype '->' type { MonoFunTy $1 $3 }
474 btype :: { RdrNameHsType }
475 : btype atype { MonoTyApp $1 $2 }
478 atype :: { RdrNameHsType }
479 : gtycon { MonoTyVar $1 }
480 | tyvar { MonoTyVar $1 }
481 | '(' type ',' types ')' { MonoTupleTy ($2 : reverse $4) True }
482 | '(#' types '#)' { MonoTupleTy (reverse $2) False }
483 | '[' type ']' { MonoListTy $2 }
484 | '(' ctype ')' { $2 }
486 gtycon :: { RdrName }
488 | '(' ')' { unitTyCon_RDR }
489 | '(' '->' ')' { funTyCon_RDR }
490 | '[' ']' { listTyCon_RDR }
491 | '(' commas ')' { tupleTyCon_RDR $2 }
493 -- An inst_type is what occurs in the head of an instance decl
494 -- e.g. (Foo a, Gaz b) => Wibble a b
495 -- It's kept as a single type, with a MonoDictTy at the right
496 -- hand corner, for convenience.
497 inst_type :: { RdrNameHsType }
498 : ctype {% checkInstType $1 }
500 ctype :: { RdrNameHsType }
501 : 'forall' tyvars '.' context type
502 { HsForAllTy (Just $2) $4 $5 }
503 | 'forall' tyvars '.' type { HsForAllTy (Just $2) [] $4 }
504 | context type { HsForAllTy Nothing $1 $2 }
507 types0 :: { [RdrNameHsType] }
511 types :: { [RdrNameHsType] }
513 | types ',' type { $3 : $1 }
515 simpletype :: { (RdrName, [RdrNameHsTyVar]) }
516 : tycon tyvars { ($1, reverse $2) }
518 tyvars :: { [RdrNameHsTyVar] }
519 : tyvars tyvar { UserTyVar $2 : $1 }
522 -----------------------------------------------------------------------------
523 -- Datatype declarations
525 constrs :: { [RdrNameConDecl] }
526 : constrs '|' constr { $3 : $1 }
529 constr :: { RdrNameConDecl }
530 : srcloc forall context constr_stuff
531 { ConDecl (fst $4) $2 $3 (snd $4) $1 }
532 | srcloc forall constr_stuff
533 { ConDecl (fst $3) $2 [] (snd $3) $1 }
535 forall :: { [RdrNameHsTyVar] }
536 : 'forall' tyvars '.' { $2 }
539 context :: { RdrNameContext }
540 : btype '=>' {% checkContext $1 }
542 constr_stuff :: { (RdrName, RdrNameConDetails) }
543 : scontype { (fst $1, VanillaCon (snd $1)) }
544 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
545 | con '{' fielddecls '}' { ($1, RecCon (reverse $3)) }
547 newconstr :: { RdrNameConDecl }
548 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
549 | srcloc conid '{' var '::' type '}'
550 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
552 scontype :: { (RdrName, [RdrNameBangType]) }
553 : btype {% splitForConApp $1 [] }
556 scontype1 :: { (RdrName, [RdrNameBangType]) }
557 : btype '!' atype {% splitForConApp $1 [Banged $3] }
558 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
560 satype :: { RdrNameBangType }
561 : atype { Unbanged $1 }
562 | '!' atype { Banged $2 }
564 sbtype :: { RdrNameBangType }
565 : btype { Unbanged $1 }
566 | '!' atype { Banged $2 }
568 fielddecls :: { [([RdrName],RdrNameBangType)] }
569 : fielddecls ',' fielddecl { $3 : $1 }
572 fielddecl :: { ([RdrName],RdrNameBangType) }
573 : vars '::' stype { (reverse $1, $3) }
575 stype :: { RdrNameBangType }
576 : type { Unbanged $1 }
577 | '!' atype { Banged $2 }
579 deriving :: { Maybe [RdrName] }
580 : {- empty -} { Nothing }
581 | 'deriving' qtycls { Just [$2] }
582 | 'deriving' '(' ')' { Just [] }
583 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
585 dclasses :: { [RdrName] }
586 : dclasses ',' qtycls { $3 : $1 }
589 -----------------------------------------------------------------------------
592 valdef :: { RdrNameMonoBinds }
593 : infixexp {-ToDo: opt_sig-} srcloc rhs
594 {% checkValDef $1 Nothing $3 $2 }
596 rhs :: { RdrNameGRHSs }
597 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
599 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
601 gdrhs :: { [RdrNameGRHS] }
602 : gdrhs gdrh { $2 : $1 }
605 gdrh :: { RdrNameGRHS }
606 : '|' srcloc quals '=' exp { GRHS (reverse
607 (ExprStmt $5 $2 : $3)) $2 }
609 -----------------------------------------------------------------------------
612 exp :: { RdrNameHsExpr }
613 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
616 infixexp :: { RdrNameHsExpr }
618 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
620 exp10 :: { RdrNameHsExpr }
621 : '\\' aexp aexps opt_asig '->' srcloc exp
622 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
623 returnP (HsLam (Match [] ps $4
624 (GRHSs (unguardedRHS $7 $6)
625 EmptyBinds Nothing))) }
626 | 'let' declbinds 'in' exp { HsLet $2 $4 }
627 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
628 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
629 | '-' fexp { NegApp $2 (error "NegApp") }
630 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
632 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
633 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
634 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
635 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
637 | '_scc_' STRING exp { if opt_SccProfilingOn
643 ccallid :: { FAST_STRING }
647 fexp :: { RdrNameHsExpr }
648 : fexp aexp { HsApp $1 $2 }
651 aexps0 :: { [RdrNameHsExpr] }
652 : aexps { reverse $1 }
654 aexps :: { [RdrNameHsExpr] }
655 : aexps aexp { $2 : $1 }
658 aexp :: { RdrNameHsExpr }
659 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
662 aexp1 :: { RdrNameHsExpr }
665 | literal { HsLit $1 }
666 | '(' exp ')' { HsPar $2 }
667 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
668 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
669 | '[' list ']' { $2 }
670 | '(' infixexp qop ')' { SectionL $2 $3 }
671 | '(' qopm infixexp ')' { SectionR $2 $3 }
672 | qvar '@' aexp { EAsPat $1 $3 }
674 | '~' aexp1 { ELazyPat $2 }
677 : commas ',' { $1 + 1 }
680 texps :: { [RdrNameHsExpr] }
681 : texps ',' exp { $3 : $1 }
684 -----------------------------------------------------------------------------
687 -- The rules below are little bit contorted to keep lexps left-recursive while
688 -- avoiding another shift/reduce-conflict.
690 list :: { RdrNameHsExpr }
691 : exp { ExplicitList [$1] }
692 | lexps { ExplicitList (reverse $1) }
693 | exp '..' { ArithSeqIn (From $1) }
694 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
695 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
696 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
697 | exp srcloc '|' quals { HsDo ListComp (reverse
698 (ReturnStmt $1 : $4)) $2 }
700 lexps :: { [RdrNameHsExpr] }
701 : lexps ',' exp { $3 : $1 }
702 | exp ',' exp { [$3,$1] }
704 -----------------------------------------------------------------------------
705 -- List Comprehensions
707 quals :: { [RdrNameStmt] }
708 : quals ',' qual { $3 : $1 }
711 qual :: { RdrNameStmt }
712 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
713 returnP (BindStmt p $4 $1) }
714 | srcloc exp { GuardStmt $2 $1 }
715 | srcloc 'let' declbinds { LetStmt $3 }
717 -----------------------------------------------------------------------------
720 altslist :: { [RdrNameMatch] }
721 : '{' alts '}' { reverse $2 }
722 | layout_on alts close { reverse $2 }
725 alts :: { [RdrNameMatch] }
726 : alts ';' alt { $3 : $1 }
731 alt :: { RdrNameMatch }
732 : infixexp opt_sig ralt wherebinds
733 {% checkPattern $1 `thenP` \p ->
734 returnP (Match [] [p] $2
735 (GRHSs $3 $4 Nothing)) }
737 opt_sig :: { Maybe RdrNameHsType }
738 : {- empty -} { Nothing }
739 | '::' type { Just $2 }
741 opt_asig :: { Maybe RdrNameHsType }
742 : {- empty -} { Nothing }
743 | '::' atype { Just $2 }
745 ralt :: { [RdrNameGRHS] }
746 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
747 | gdpats { (reverse $1) }
749 gdpats :: { [RdrNameGRHS] }
750 : gdpats gdpat { $2 : $1 }
753 gdpat :: { RdrNameGRHS }
754 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
756 -----------------------------------------------------------------------------
757 -- Statement sequences
759 stmtlist :: { [RdrNameStmt] }
760 : '{' stmts '}' { reverse $2 }
761 | layout_on stmts close { reverse $2 }
763 stmts :: { [RdrNameStmt] }
767 stmts1 :: { [RdrNameStmt] }
768 : stmts1 ';' stmt { $3 : $1 }
772 stmt :: { RdrNameStmt }
773 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
774 returnP (BindStmt p $4 $1) }
775 | srcloc exp { ExprStmt $2 $1 }
776 | srcloc 'let' declbinds { LetStmt $3 }
778 -----------------------------------------------------------------------------
779 -- Record Field Update/Construction
781 fbinds :: { RdrNameHsRecordBinds }
782 : fbinds ',' fbind { $3 : $1 }
787 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
788 : qvar '=' exp { ($1,$3,False) }
790 -----------------------------------------------------------------------------
791 -- Variables, Constructors and Operators.
794 : '(' ')' { unitCon_RDR }
795 | '[' ']' { nilCon_RDR }
796 | '(' commas ')' { tupleCon_RDR $2 }
801 | '(' varsym ')' { $2 }
805 | '(' qvarsym ')' { $2 }
809 | '(' consym ')' { $2 }
813 | '(' qconsym ')' { $2 }
817 | '`' varid '`' { $2 }
819 qvarop :: { RdrName }
821 | '`' qvarid '`' { $2 }
823 qvaropm :: { RdrName }
825 | '`' qvarid '`' { $2 }
829 | '`' conid '`' { $2 }
831 qconop :: { RdrName }
833 | '`' qconid '`' { $2 }
835 -----------------------------------------------------------------------------
838 op :: { RdrName } -- used in infix decls
842 qop :: { RdrNameHsExpr } -- used in sections
843 : qvarop { HsVar $1 }
844 | qconop { HsVar $1 }
846 qopm :: { RdrNameHsExpr } -- used in sections
847 : qvaropm { HsVar $1 }
848 | qconop { HsVar $1 }
850 -----------------------------------------------------------------------------
853 qvarid :: { RdrName }
855 | QVARID { case $1 of { (mod,n) ->
856 mkSrcQual varName mod n } }
859 : VARID { mkSrcUnqual varName $1 }
860 | 'forall' { forall_var_RDR }
861 | 'export' { export_var_RDR }
862 | 'label' { label_var_RDR }
863 | 'dynamic' { dynamic_var_RDR }
864 | 'unsafe' { unsafe_var_RDR }
866 varid_no_unsafe :: { RdrName }
867 : VARID { mkSrcUnqual varName $1 }
868 | 'forall' { forall_var_RDR }
869 | 'export' { export_var_RDR }
870 | 'label' { label_var_RDR }
871 | 'dynamic' { dynamic_var_RDR }
874 'as' :: { () } : VARID {% checkAs $1 }
875 'qualified' :: { () } : VARID {% checkQualified $1 }
876 'hiding' :: { () } : VARID {% checkHiding $1 }
878 -----------------------------------------------------------------------------
881 qconid :: { RdrName }
883 | QCONID { case $1 of { (mod,n) ->
884 mkSrcQual dataName mod n } }
887 : CONID { mkSrcUnqual dataName $1 }
889 -----------------------------------------------------------------------------
892 qconsym :: { RdrName }
894 | QCONSYM { case $1 of { (mod,n) ->
895 mkSrcQual dataName mod n } }
897 consym :: { RdrName }
898 : CONSYM { mkSrcUnqual dataName $1 }
900 -----------------------------------------------------------------------------
903 qvarsym :: { RdrName }
907 qvarsymm :: { RdrName }
911 varsym :: { RdrName }
912 : VARSYM { mkSrcUnqual varName $1 }
917 varsymm :: { RdrName } -- varsym not including '-'
918 : VARSYM { mkSrcUnqual varName $1 }
922 qvarsym1 :: { RdrName }
923 : QVARSYM { case $1 of { (mod,n) ->
924 mkSrcQual varName mod n } }
927 : INTEGER { HsInt $1 }
929 | RATIONAL { HsFrac $1 }
930 | STRING { HsString $1 }
932 | PRIMINTEGER { HsIntPrim $1 }
933 | PRIMCHAR { HsCharPrim $1 }
934 | PRIMSTRING { HsStringPrim $1 }
935 | PRIMFLOAT { HsFloatPrim $1 }
936 | PRIMDOUBLE { HsDoublePrim $1 }
937 | CLITLIT { HsLitLit $1 }
939 srcloc :: { SrcLoc } : {% getSrcLocP }
941 -----------------------------------------------------------------------------
945 : vccurly { () } -- context popped in lexer.
946 | error {% popContext }
948 layout_on :: { () } : {% layoutOn }
950 -----------------------------------------------------------------------------
951 -- Miscellaneous (mostly renamings)
953 modid :: { ModuleName }
954 : CONID { mkSrcModuleFS $1 }
957 : CONID { mkSrcUnqual tcClsName $1 }
959 qtycon :: { RdrName }
961 | QCONID { case $1 of { (mod,n) ->
962 mkSrcQual tcClsName mod n } }
964 qtycls :: { RdrName }
968 : VARID { mkSrcUnqual tvName $1 }
969 | 'export' { export_var_RDR }
970 | 'label' { label_var_RDR }
971 | 'dynamic' { dynamic_var_RDR }
972 | 'unsafe' { unsafe_var_RDR }
975 -----------------------------------------------------------------------------
979 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)