2 -----------------------------------------------------------------------------
4 $Id: Parser.y,v 1.13 1999/07/27 09:25:49 simonmar Exp $
6 $Id: Parser.y,v 1.13 1999/07/27 09:25:49 simonmar Exp $
11 Author(s): Simon Marlow, Sven Panne 1997, 1998, 1999
12 -----------------------------------------------------------------------------
16 module Parser ( parse ) where
25 import PrelMods ( mAIN_Name )
26 import OccName ( varName, dataName, tcClsName, tvName )
27 import SrcLoc ( SrcLoc )
30 import CmdLineOpts ( opt_SccProfilingOn )
31 import BasicTypes ( Fixity(..), FixityDirection(..), NewOrData(..) )
36 #include "HsVersions.h"
40 -----------------------------------------------------------------------------
41 Conflicts: 14 shift/reduce
43 8 for abiguity in 'if x then y else z + 1'
44 (shift parses as 'if x then y else (z + 1)', as per longest-parse rule)
45 1 for ambiguity in 'if x then y else z :: T'
46 (shift parses as 'if x then y else (z :: T)', as per longest-parse rule)
47 3 for ambiguity in 'case x of y :: a -> b'
48 (don't know whether to reduce 'a' as a btype or shift the '->'.
49 conclusion: bogus expression anyway, doesn't matter)
51 1 for ambiguity in '{-# RULES "name" forall = ... #-}'
52 since 'forall' is a valid variable name, we don't know whether
53 to treat a forall on the input as the beginning of a quantifier
54 or the beginning of the rule itself. Resolving to shift means
55 it's always treated as a quantifier, hence the above is disallowed.
56 This saves explicitly defining a grammar for the rule lhs that
57 doesn't include 'forall'.
59 1 for ambiguity in 'x @ Rec{..}'.
60 Only sensible parse is 'x @ (Rec{..})', which is what resolving
63 -----------------------------------------------------------------------------
67 '_' { ITunderscore } -- Haskell keywords
72 'default' { ITdefault }
73 'deriving' { ITderiving }
83 'instance' { ITinstance }
86 'newtype' { ITnewtype }
88 'qualified' { ITqualified }
94 'forall' { ITforall } -- GHC extension keywords
95 'foreign' { ITforeign }
98 'dynamic' { ITdynamic }
100 '_ccall_' { ITccall (False, False, False) }
101 '_ccall_GC_' { ITccall (False, False, True) }
102 '_casm_' { ITccall (False, True, False) }
103 '_casm_GC_' { ITccall (False, True, True) }
105 '{-# SPECIALISE' { ITspecialise_prag }
106 '{-# SOURCE' { ITsource_prag }
107 '{-# INLINE' { ITinline_prag }
108 '{-# NOINLINE' { ITnoinline_prag }
109 '{-# RULES' { ITrules_prag }
110 '#-}' { ITclose_prag }
113 '__interface' { ITinterface } -- interface keywords
114 '__export' { IT__export }
115 '__instimport' { ITinstimport }
116 '__forall' { IT__forall }
117 '__letrec' { ITletrec }
118 '__coerce' { ITcoerce }
119 '__depends' { ITdepends }
120 '__inline' { ITinline }
121 '__DEFAULT' { ITdefaultbranch }
123 '__integer' { ITinteger_lit }
124 '__float' { ITfloat_lit }
125 '__rational' { ITrational_lit }
126 '__addr' { ITaddr_lit }
127 '__litlit' { ITlit_lit }
128 '__string' { ITstring_lit }
129 '__ccall' { ITccall $$ }
131 '__sccC' { ITsccAllCafs }
134 '__P' { ITspecialise }
136 '__U' { ITunfold $$ }
137 '__S' { ITstrict $$ }
138 '__M' { ITcprinfo $$ }
141 '..' { ITdotdot } -- reserved symbols
155 '/\\' { ITbiglam } -- GHC-extension symbols
157 '{' { ITocurly } -- special symbols
159 vccurly { ITvccurly } -- virtual close curly (from layout)
170 VARID { ITvarid $$ } -- identifiers
172 VARSYM { ITvarsym $$ }
173 CONSYM { ITconsym $$ }
174 QVARID { ITqvarid $$ }
175 QCONID { ITqconid $$ }
176 QVARSYM { ITqvarsym $$ }
177 QCONSYM { ITqconsym $$ }
179 PRAGMA { ITpragma $$ }
182 STRING { ITstring $$ }
183 INTEGER { ITinteger $$ }
184 RATIONAL { ITrational $$ }
186 PRIMCHAR { ITprimchar $$ }
187 PRIMSTRING { ITprimstring $$ }
188 PRIMINTEGER { ITprimint $$ }
189 PRIMFLOAT { ITprimfloat $$ }
190 PRIMDOUBLE { ITprimdouble $$ }
191 CLITLIT { ITlitlit $$ }
193 UNKNOWN { ITunknown $$ }
195 %monad { P } { thenP } { returnP }
196 %lexer { lexer } { ITeof }
201 -----------------------------------------------------------------------------
204 module :: { RdrNameHsModule }
205 : srcloc 'module' modid maybeexports 'where' body
206 { HsModule $3 Nothing $4 (fst $6) (snd $6) $1 }
208 { HsModule mAIN_Name Nothing Nothing (fst $2) (snd $2) $1 }
210 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
212 | layout_on top close { $2 }
214 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
215 : importdecls ';' cvtopdecls { (reverse $1,$3) }
216 | importdecls { (reverse $1,[]) }
217 | cvtopdecls { ([],$1) }
219 cvtopdecls :: { [RdrNameHsDecl] }
220 : topdecls { cvTopDecls (groupBindings $1)}
222 -----------------------------------------------------------------------------
225 maybeexports :: { Maybe [RdrNameIE] }
226 : '(' exportlist ')' { Just $2 }
227 | {- empty -} { Nothing }
229 exportlist :: { [RdrNameIE] }
230 : exportlist ',' export { $3 : $1 }
231 | exportlist ',' { $1 }
235 -- GHC extension: we allow things like [] and (,,,) to be exported
236 export :: { RdrNameIE }
238 | gtycon { IEThingAbs $1 }
239 | gtycon '(' '..' ')' { IEThingAll $1 }
240 | gtycon '(' ')' { IEThingWith $1 [] }
241 | gtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
242 | 'module' modid { IEModuleContents $2 }
244 qcnames :: { [RdrName] }
245 : qcnames ',' qcname { $3 : $1 }
248 qcname :: { RdrName }
252 -----------------------------------------------------------------------------
253 -- Import Declarations
255 -- import decls can be *empty*, or even just a string of semicolons
256 -- whereas topdecls must contain at least one topdecl.
258 importdecls :: { [RdrNameImportDecl] }
259 : importdecls ';' importdecl { $3 : $1 }
260 | importdecls ';' { $1 }
261 | importdecl { [ $1 ] }
264 importdecl :: { RdrNameImportDecl }
265 : 'import' srcloc maybe_src optqualified CONID maybeas maybeimpspec
266 { ImportDecl (mkSrcModuleFS $5) $3 $4 $6 $7 $2 }
268 maybe_src :: { WhereFrom }
269 : '{-# SOURCE' '#-}' { ImportByUserSource }
270 | {- empty -} { ImportByUser }
272 optqualified :: { Bool }
273 : 'qualified' { True }
274 | {- empty -} { False }
276 maybeas :: { Maybe ModuleName }
277 : 'as' modid { Just $2 }
278 | {- empty -} { Nothing }
280 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
281 : impspec { Just $1 }
282 | {- empty -} { Nothing }
284 impspec :: { (Bool, [RdrNameIE]) }
285 : '(' exportlist ')' { (False, reverse $2) }
286 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
288 -----------------------------------------------------------------------------
289 -- Fixity Declarations
293 | INTEGER {% checkPrec $1 `thenP_`
294 returnP (fromInteger $1) }
296 infix :: { FixityDirection }
298 | 'infixl' { InfixL }
299 | 'infixr' { InfixR }
302 : ops ',' op { $3 : $1 }
305 -----------------------------------------------------------------------------
306 -- Top-Level Declarations
308 topdecls :: { [RdrBinding] }
309 : topdecls ';' topdecl { ($3 : $1) }
310 | topdecls ';' { $1 }
313 topdecl :: { RdrBinding }
314 : srcloc 'type' simpletype '=' type
315 { RdrHsDecl (TyClD (TySynonym (fst $3) (snd $3) $5 $1)) }
317 | srcloc 'data' ctype '=' constrs deriving
318 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
319 returnP (RdrHsDecl (TyClD
320 (TyData DataType cs c ts (reverse $5) $6
321 NoDataPragmas $1))) }
323 | srcloc 'newtype' ctype '=' newconstr deriving
324 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
325 returnP (RdrHsDecl (TyClD
326 (TyData NewType cs c ts [$5] $6
327 NoDataPragmas $1))) }
329 | srcloc 'class' ctype where
330 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
332 = cvMonoBindsAndSigs cvClassOpSig
335 returnP (RdrHsDecl (TyClD
336 (mkClassDecl cs c ts sigs binds
337 NoClassPragmas $1))) }
339 | srcloc 'instance' inst_type where
341 = cvMonoBindsAndSigs cvInstDeclSig
344 (InstDecl $3 binds sigs dummyRdrVarName $1)) }
346 | srcloc 'default' '(' types0 ')'
347 { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
349 | srcloc 'foreign' 'import' callconv ext_name
350 unsafe_flag varid_no_unsafe '::' sigtype
351 { RdrHsDecl (ForD (ForeignDecl $7 (FoImport $6) $9 $5 $4 $1)) }
353 | srcloc 'foreign' 'export' callconv ext_name varid '::' sigtype
354 { RdrHsDecl (ForD (ForeignDecl $6 FoExport $8 $5 $4 $1)) }
356 | srcloc 'foreign' 'label' ext_name varid '::' sigtype
357 { RdrHsDecl (ForD (ForeignDecl $5 FoLabel $7 $4
358 defaultCallConv $1)) }
362 decls :: { [RdrBinding] }
363 : decls ';' decl { $3 : $1 }
368 decl :: { RdrBinding }
371 | valdef { RdrValBinding $1 }
372 | '{-# INLINE' srcloc qvar '#-}' { RdrSig (InlineSig $3 $2) }
373 | '{-# NOINLINE' srcloc qvar '#-}' { RdrSig (NoInlineSig $3 $2) }
374 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
375 { foldr1 RdrAndBindings
376 (map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
377 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
378 { RdrSig (SpecInstSig $4 $2) }
379 | '{-# RULES' rules '#-}' { $2 }
381 sigtypes :: { [RdrNameHsType] }
383 | sigtypes ',' sigtype { $3 : $1 }
385 wherebinds :: { RdrNameHsBinds }
386 : where { cvBinds cvValSig (groupBindings $1) }
388 where :: { [RdrBinding] }
389 : 'where' decllist { $2 }
392 declbinds :: { RdrNameHsBinds }
393 : decllist { cvBinds cvValSig (groupBindings $1) }
395 decllist :: { [RdrBinding] }
396 : '{' decls '}' { $2 }
397 | layout_on decls close { $2 }
399 fixdecl :: { RdrBinding }
400 : srcloc infix prec ops { foldr1 RdrAndBindings
401 [ RdrSig (FixSig (FixitySig n
405 signdecl :: { RdrBinding }
406 : vars srcloc '::' sigtype { foldr1 RdrAndBindings
407 [ RdrSig (Sig n $4 $2) | n <- $1 ] }
409 sigtype :: { RdrNameHsType }
410 : ctype { mkHsForAllTy Nothing [] $1 }
413 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
414 instead of qvar, we get another shift/reduce-conflict. Consider the
417 { (+) :: ... } only var
418 { (+) x y = ... } could (incorrectly) be qvar
420 We re-use expressions for patterns, so a qvar would be allowed in patterns
421 instead of a var only (which would be correct). But deciding what the + is,
422 would require more lookahead. So let's check for ourselves...
425 vars :: { [RdrName] }
426 : vars ',' var { $3 : $1 }
429 -----------------------------------------------------------------------------
430 -- Transformation Rules
432 rules :: { RdrBinding }
433 : rules ';' rule { $1 `RdrAndBindings` $3 }
436 | {- empty -} { RdrNullBind }
438 rule :: { RdrBinding }
439 : STRING rule_forall fexp '=' srcloc exp
440 { RdrHsDecl (RuleD (RuleDecl $1 [] $2 $3 $6 $5)) }
442 rule_forall :: { [RdrNameRuleBndr] }
443 : 'forall' rule_var_list '.' { $2 }
446 rule_var_list :: { [RdrNameRuleBndr] }
448 | rule_var ',' rule_var_list { $1 : $3 }
450 rule_var :: { RdrNameRuleBndr }
451 : varid { RuleBndr $1 }
452 | varid '::' ctype { RuleBndrSig $1 $3 }
454 -----------------------------------------------------------------------------
455 -- Foreign import/export
458 : VARID {% checkCallConv $1 }
459 | {- empty -} { defaultCallConv }
461 unsafe_flag :: { Bool }
463 | {- empty -} { False }
465 ext_name :: { ExtName }
466 : 'dynamic' { Dynamic }
467 | STRING { ExtName $1 Nothing }
468 | STRING STRING { ExtName $2 (Just $1) }
470 -----------------------------------------------------------------------------
473 {- ToDo: forall stuff -}
475 type :: { RdrNameHsType }
476 : btype '->' type { MonoFunTy $1 $3 }
479 btype :: { RdrNameHsType }
480 : btype atype { MonoTyApp $1 $2 }
483 atype :: { RdrNameHsType }
484 : gtycon { MonoTyVar $1 }
485 | tyvar { MonoTyVar $1 }
486 | '(' type ',' types ')' { MonoTupleTy ($2 : reverse $4) True }
487 | '(#' types '#)' { MonoTupleTy (reverse $2) False }
488 | '[' type ']' { MonoListTy $2 }
489 | '(' ctype ')' { $2 }
491 gtycon :: { RdrName }
493 | '(' ')' { unitTyCon_RDR }
494 | '(' '->' ')' { funTyCon_RDR }
495 | '[' ']' { listTyCon_RDR }
496 | '(' commas ')' { tupleTyCon_RDR $2 }
498 -- An inst_type is what occurs in the head of an instance decl
499 -- e.g. (Foo a, Gaz b) => Wibble a b
500 -- It's kept as a single type, with a MonoDictTy at the right
501 -- hand corner, for convenience.
502 inst_type :: { RdrNameHsType }
503 : ctype {% checkInstType $1 }
505 ctype :: { RdrNameHsType }
506 : 'forall' tyvars '.' context type
507 { mkHsForAllTy (Just $2) $4 $5 }
508 | 'forall' tyvars '.' type { mkHsForAllTy (Just $2) [] $4 }
509 | context type { mkHsForAllTy Nothing $1 $2 }
510 -- A type of form (context => type) is an *implicit* HsForAllTy
513 types0 :: { [RdrNameHsType] }
517 types :: { [RdrNameHsType] }
519 | types ',' type { $3 : $1 }
521 simpletype :: { (RdrName, [RdrNameHsTyVar]) }
522 : tycon tyvars { ($1, reverse $2) }
524 tyvars :: { [RdrNameHsTyVar] }
525 : tyvars tyvar { UserTyVar $2 : $1 }
528 -----------------------------------------------------------------------------
529 -- Datatype declarations
531 constrs :: { [RdrNameConDecl] }
532 : constrs '|' constr { $3 : $1 }
535 constr :: { RdrNameConDecl }
536 : srcloc forall context constr_stuff
537 { ConDecl (fst $4) $2 $3 (snd $4) $1 }
538 | srcloc forall constr_stuff
539 { ConDecl (fst $3) $2 [] (snd $3) $1 }
541 forall :: { [RdrNameHsTyVar] }
542 : 'forall' tyvars '.' { $2 }
545 context :: { RdrNameContext }
546 : btype '=>' {% checkContext $1 }
548 constr_stuff :: { (RdrName, RdrNameConDetails) }
549 : scontype { (fst $1, VanillaCon (snd $1)) }
550 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
551 | con '{' fielddecls '}' { ($1, RecCon (reverse $3)) }
553 newconstr :: { RdrNameConDecl }
554 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
555 | srcloc conid '{' var '::' type '}'
556 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
558 scontype :: { (RdrName, [RdrNameBangType]) }
559 : btype {% splitForConApp $1 [] }
562 scontype1 :: { (RdrName, [RdrNameBangType]) }
563 : btype '!' atype {% splitForConApp $1 [Banged $3] }
564 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
566 satype :: { RdrNameBangType }
567 : atype { Unbanged $1 }
568 | '!' atype { Banged $2 }
570 sbtype :: { RdrNameBangType }
571 : btype { Unbanged $1 }
572 | '!' atype { Banged $2 }
574 fielddecls :: { [([RdrName],RdrNameBangType)] }
575 : fielddecls ',' fielddecl { $3 : $1 }
578 fielddecl :: { ([RdrName],RdrNameBangType) }
579 : vars '::' stype { (reverse $1, $3) }
581 stype :: { RdrNameBangType }
582 : type { Unbanged $1 }
583 | '!' atype { Banged $2 }
585 deriving :: { Maybe [RdrName] }
586 : {- empty -} { Nothing }
587 | 'deriving' qtycls { Just [$2] }
588 | 'deriving' '(' ')' { Just [] }
589 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
591 dclasses :: { [RdrName] }
592 : dclasses ',' qtycls { $3 : $1 }
595 -----------------------------------------------------------------------------
598 valdef :: { RdrNameMonoBinds }
599 : infixexp {-ToDo: opt_sig-} srcloc rhs
600 {% checkValDef $1 Nothing $3 $2 }
602 rhs :: { RdrNameGRHSs }
603 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
605 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
607 gdrhs :: { [RdrNameGRHS] }
608 : gdrhs gdrh { $2 : $1 }
611 gdrh :: { RdrNameGRHS }
612 : '|' srcloc quals '=' exp { GRHS (reverse
613 (ExprStmt $5 $2 : $3)) $2 }
615 -----------------------------------------------------------------------------
618 exp :: { RdrNameHsExpr }
619 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
622 infixexp :: { RdrNameHsExpr }
624 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
626 exp10 :: { RdrNameHsExpr }
627 : '\\' aexp aexps opt_asig '->' srcloc exp
628 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
629 returnP (HsLam (Match [] ps $4
630 (GRHSs (unguardedRHS $7 $6)
631 EmptyBinds Nothing))) }
632 | 'let' declbinds 'in' exp { HsLet $2 $4 }
633 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
634 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
635 | '-' fexp { NegApp $2 (error "NegApp") }
636 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
638 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
639 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
640 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
641 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
643 | '_scc_' STRING exp { if opt_SccProfilingOn
649 ccallid :: { FAST_STRING }
653 fexp :: { RdrNameHsExpr }
654 : fexp aexp { HsApp $1 $2 }
657 aexps0 :: { [RdrNameHsExpr] }
658 : aexps { reverse $1 }
660 aexps :: { [RdrNameHsExpr] }
661 : aexps aexp { $2 : $1 }
664 aexp :: { RdrNameHsExpr }
665 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
668 aexp1 :: { RdrNameHsExpr }
671 | literal { HsLit $1 }
672 | '(' exp ')' { HsPar $2 }
673 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
674 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
675 | '[' list ']' { $2 }
676 | '(' infixexp qop ')' { SectionL $2 $3 }
677 | '(' qopm infixexp ')' { SectionR $2 $3 }
678 | qvar '@' aexp { EAsPat $1 $3 }
680 | '~' aexp1 { ELazyPat $2 }
683 : commas ',' { $1 + 1 }
686 texps :: { [RdrNameHsExpr] }
687 : texps ',' exp { $3 : $1 }
690 -----------------------------------------------------------------------------
693 -- The rules below are little bit contorted to keep lexps left-recursive while
694 -- avoiding another shift/reduce-conflict.
696 list :: { RdrNameHsExpr }
697 : exp { ExplicitList [$1] }
698 | lexps { ExplicitList (reverse $1) }
699 | exp '..' { ArithSeqIn (From $1) }
700 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
701 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
702 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
703 | exp srcloc '|' quals { HsDo ListComp (reverse
704 (ReturnStmt $1 : $4)) $2 }
706 lexps :: { [RdrNameHsExpr] }
707 : lexps ',' exp { $3 : $1 }
708 | exp ',' exp { [$3,$1] }
710 -----------------------------------------------------------------------------
711 -- List Comprehensions
713 quals :: { [RdrNameStmt] }
714 : quals ',' qual { $3 : $1 }
717 qual :: { RdrNameStmt }
718 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
719 returnP (BindStmt p $4 $1) }
720 | srcloc exp { GuardStmt $2 $1 }
721 | srcloc 'let' declbinds { LetStmt $3 }
723 -----------------------------------------------------------------------------
726 altslist :: { [RdrNameMatch] }
727 : '{' alts '}' { reverse $2 }
728 | layout_on alts close { reverse $2 }
731 alts :: { [RdrNameMatch] }
732 : alts ';' alt { $3 : $1 }
737 alt :: { RdrNameMatch }
738 : infixexp opt_sig ralt wherebinds
739 {% checkPattern $1 `thenP` \p ->
740 returnP (Match [] [p] $2
741 (GRHSs $3 $4 Nothing)) }
743 opt_sig :: { Maybe RdrNameHsType }
744 : {- empty -} { Nothing }
745 | '::' type { Just $2 }
747 opt_asig :: { Maybe RdrNameHsType }
748 : {- empty -} { Nothing }
749 | '::' atype { Just $2 }
751 ralt :: { [RdrNameGRHS] }
752 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
753 | gdpats { (reverse $1) }
755 gdpats :: { [RdrNameGRHS] }
756 : gdpats gdpat { $2 : $1 }
759 gdpat :: { RdrNameGRHS }
760 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
762 -----------------------------------------------------------------------------
763 -- Statement sequences
765 stmtlist :: { [RdrNameStmt] }
766 : '{' stmts '}' { reverse $2 }
767 | layout_on_for_do stmts close { reverse $2 }
769 -- Stmt list should really end in an expression, but it's not
770 -- convenient to enforce this here, so we throw out erroneous
771 -- statement sequences in the renamer instead.
773 stmts :: { [RdrNameStmt] }
777 stmts1 :: { [RdrNameStmt] }
778 : stmts1 ';' stmt { $3 : $1 }
782 stmt :: { RdrNameStmt }
783 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
784 returnP (BindStmt p $4 $1) }
785 | srcloc exp { ExprStmt $2 $1 }
786 | srcloc 'let' declbinds { LetStmt $3 }
788 -----------------------------------------------------------------------------
789 -- Record Field Update/Construction
791 fbinds :: { RdrNameHsRecordBinds }
792 : fbinds ',' fbind { $3 : $1 }
797 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
798 : qvar '=' exp { ($1,$3,False) }
800 -----------------------------------------------------------------------------
801 -- Variables, Constructors and Operators.
804 : '(' ')' { unitCon_RDR }
805 | '[' ']' { nilCon_RDR }
806 | '(' commas ')' { tupleCon_RDR $2 }
811 | '(' varsym ')' { $2 }
815 | '(' qvarsym ')' { $2 }
819 | '(' consym ')' { $2 }
823 | '(' qconsym ')' { $2 }
827 | '`' varid '`' { $2 }
829 qvarop :: { RdrName }
831 | '`' qvarid '`' { $2 }
833 qvaropm :: { RdrName }
835 | '`' qvarid '`' { $2 }
839 | '`' conid '`' { $2 }
841 qconop :: { RdrName }
843 | '`' qconid '`' { $2 }
845 -----------------------------------------------------------------------------
848 op :: { RdrName } -- used in infix decls
852 qop :: { RdrNameHsExpr } -- used in sections
853 : qvarop { HsVar $1 }
854 | qconop { HsVar $1 }
856 qopm :: { RdrNameHsExpr } -- used in sections
857 : qvaropm { HsVar $1 }
858 | qconop { HsVar $1 }
860 -----------------------------------------------------------------------------
863 qvarid :: { RdrName }
865 | QVARID { case $1 of { (mod,n) ->
866 mkSrcQual varName mod n } }
869 : VARID { mkSrcUnqual varName $1 }
870 | 'as' { as_var_RDR }
871 | 'qualified' { qualified_var_RDR }
872 | 'hiding' { hiding_var_RDR }
873 | 'forall' { forall_var_RDR }
874 | 'export' { export_var_RDR }
875 | 'label' { label_var_RDR }
876 | 'dynamic' { dynamic_var_RDR }
877 | 'unsafe' { unsafe_var_RDR }
879 varid_no_unsafe :: { RdrName }
880 : VARID { mkSrcUnqual varName $1 }
881 | 'as' { as_var_RDR }
882 | 'qualified' { qualified_var_RDR }
883 | 'hiding' { hiding_var_RDR }
884 | 'forall' { forall_var_RDR }
885 | 'export' { export_var_RDR }
886 | 'label' { label_var_RDR }
887 | 'dynamic' { dynamic_var_RDR }
889 -----------------------------------------------------------------------------
892 qconid :: { RdrName }
894 | QCONID { case $1 of { (mod,n) ->
895 mkSrcQual dataName mod n } }
898 : CONID { mkSrcUnqual dataName $1 }
900 -----------------------------------------------------------------------------
903 qconsym :: { RdrName }
905 | QCONSYM { case $1 of { (mod,n) ->
906 mkSrcQual dataName mod n } }
908 consym :: { RdrName }
909 : CONSYM { mkSrcUnqual dataName $1 }
911 -----------------------------------------------------------------------------
914 qvarsym :: { RdrName }
918 qvarsymm :: { RdrName }
922 varsym :: { RdrName }
923 : VARSYM { mkSrcUnqual varName $1 }
928 varsymm :: { RdrName } -- varsym not including '-'
929 : VARSYM { mkSrcUnqual varName $1 }
933 qvarsym1 :: { RdrName }
934 : QVARSYM { case $1 of { (mod,n) ->
935 mkSrcQual varName mod n } }
938 : INTEGER { HsInt $1 }
940 | RATIONAL { HsFrac $1 }
941 | STRING { HsString $1 }
943 | PRIMINTEGER { HsIntPrim $1 }
944 | PRIMCHAR { HsCharPrim $1 }
945 | PRIMSTRING { HsStringPrim $1 }
946 | PRIMFLOAT { HsFloatPrim $1 }
947 | PRIMDOUBLE { HsDoublePrim $1 }
948 | CLITLIT { HsLitLit $1 }
950 srcloc :: { SrcLoc } : {% getSrcLocP }
952 -----------------------------------------------------------------------------
956 : vccurly { () } -- context popped in lexer.
957 | error {% popContext }
959 layout_on :: { () } : {% layoutOn True{-strict-} }
960 layout_on_for_do :: { () } : {% layoutOn False }
962 -----------------------------------------------------------------------------
963 -- Miscellaneous (mostly renamings)
965 modid :: { ModuleName }
966 : CONID { mkSrcModuleFS $1 }
969 : CONID { mkSrcUnqual tcClsName $1 }
971 qtycon :: { RdrName }
973 | QCONID { case $1 of { (mod,n) ->
974 mkSrcQual tcClsName mod n } }
976 qtycls :: { RdrName }
980 : VARID { mkSrcUnqual tvName $1 }
981 | 'as' { as_tyvar_RDR }
982 | 'qualified' { qualified_tyvar_RDR }
983 | 'hiding' { hiding_tyvar_RDR }
984 | 'export' { export_var_RDR }
985 | 'label' { label_var_RDR }
986 | 'dynamic' { dynamic_var_RDR }
987 | 'unsafe' { unsafe_var_RDR }
990 -----------------------------------------------------------------------------
994 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)