2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.14 1999/09/01 14:08:19 sof 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 qvar '#-}' { RdrSig (InlineSig $3 $2) }
371 | '{-# NOINLINE' srcloc qvar '#-}' { RdrSig (NoInlineSig $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 sigtypes :: { [RdrNameHsType] }
381 | sigtypes ',' sigtype { $3 : $1 }
383 wherebinds :: { RdrNameHsBinds }
384 : where { cvBinds cvValSig (groupBindings $1) }
386 where :: { [RdrBinding] }
387 : 'where' decllist { $2 }
390 declbinds :: { RdrNameHsBinds }
391 : decllist { cvBinds cvValSig (groupBindings $1) }
393 decllist :: { [RdrBinding] }
394 : '{' decls '}' { $2 }
395 | layout_on decls close { $2 }
397 fixdecl :: { RdrBinding }
398 : srcloc infix prec ops { foldr1 RdrAndBindings
399 [ RdrSig (FixSig (FixitySig n
403 signdecl :: { RdrBinding }
404 : vars srcloc '::' sigtype { foldr1 RdrAndBindings
405 [ RdrSig (Sig n $4 $2) | n <- $1 ] }
407 sigtype :: { RdrNameHsType }
408 : ctype { mkHsForAllTy Nothing [] $1 }
411 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
412 instead of qvar, we get another shift/reduce-conflict. Consider the
415 { (+) :: ... } only var
416 { (+) x y = ... } could (incorrectly) be qvar
418 We re-use expressions for patterns, so a qvar would be allowed in patterns
419 instead of a var only (which would be correct). But deciding what the + is,
420 would require more lookahead. So let's check for ourselves...
423 vars :: { [RdrName] }
424 : vars ',' var { $3 : $1 }
427 -----------------------------------------------------------------------------
428 -- Transformation Rules
430 rules :: { RdrBinding }
431 : rules ';' rule { $1 `RdrAndBindings` $3 }
434 | {- empty -} { RdrNullBind }
436 rule :: { RdrBinding }
437 : STRING rule_forall fexp '=' srcloc exp
438 { RdrHsDecl (RuleD (RuleDecl $1 [] $2 $3 $6 $5)) }
440 rule_forall :: { [RdrNameRuleBndr] }
441 : 'forall' rule_var_list '.' { $2 }
444 rule_var_list :: { [RdrNameRuleBndr] }
446 | rule_var ',' rule_var_list { $1 : $3 }
448 rule_var :: { RdrNameRuleBndr }
449 : varid { RuleBndr $1 }
450 | varid '::' ctype { RuleBndrSig $1 $3 }
452 -----------------------------------------------------------------------------
453 -- Foreign import/export
456 : 'stdcall' { stdCallConv }
457 | 'ccall' { cCallConv }
458 | {- empty -} { defaultCallConv }
460 unsafe_flag :: { Bool }
462 | {- empty -} { False }
464 ext_name :: { Maybe ExtName }
465 : 'dynamic' { Just Dynamic }
466 | STRING { Just (ExtName $1 Nothing) }
467 | STRING STRING { Just (ExtName $2 (Just $1)) }
468 | {- empty -} { Nothing }
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 }
878 | 'stdcall' { stdcall_var_RDR }
879 | 'ccall' { ccall_var_RDR }
881 varid_no_unsafe :: { RdrName }
882 : VARID { mkSrcUnqual varName $1 }
883 | 'as' { as_var_RDR }
884 | 'qualified' { qualified_var_RDR }
885 | 'hiding' { hiding_var_RDR }
886 | 'forall' { forall_var_RDR }
887 | 'export' { export_var_RDR }
888 | 'label' { label_var_RDR }
889 | 'dynamic' { dynamic_var_RDR }
890 | 'stdcall' { stdcall_var_RDR }
891 | 'ccall' { ccall_var_RDR }
893 -----------------------------------------------------------------------------
896 qconid :: { RdrName }
898 | QCONID { case $1 of { (mod,n) ->
899 mkSrcQual dataName mod n } }
902 : CONID { mkSrcUnqual dataName $1 }
904 -----------------------------------------------------------------------------
907 qconsym :: { RdrName }
909 | QCONSYM { case $1 of { (mod,n) ->
910 mkSrcQual dataName mod n } }
912 consym :: { RdrName }
913 : CONSYM { mkSrcUnqual dataName $1 }
915 -----------------------------------------------------------------------------
918 qvarsym :: { RdrName }
922 qvarsymm :: { RdrName }
926 varsym :: { RdrName }
927 : VARSYM { mkSrcUnqual varName $1 }
932 varsymm :: { RdrName } -- varsym not including '-'
933 : VARSYM { mkSrcUnqual varName $1 }
937 qvarsym1 :: { RdrName }
938 : QVARSYM { case $1 of { (mod,n) ->
939 mkSrcQual varName mod n } }
942 : INTEGER { HsInt $1 }
944 | RATIONAL { HsFrac $1 }
945 | STRING { HsString $1 }
947 | PRIMINTEGER { HsIntPrim $1 }
948 | PRIMCHAR { HsCharPrim $1 }
949 | PRIMSTRING { HsStringPrim $1 }
950 | PRIMFLOAT { HsFloatPrim $1 }
951 | PRIMDOUBLE { HsDoublePrim $1 }
952 | CLITLIT { HsLitLit $1 }
954 srcloc :: { SrcLoc } : {% getSrcLocP }
956 -----------------------------------------------------------------------------
960 : vccurly { () } -- context popped in lexer.
961 | error {% popContext }
963 layout_on :: { () } : {% layoutOn True{-strict-} }
964 layout_on_for_do :: { () } : {% layoutOn False }
966 -----------------------------------------------------------------------------
967 -- Miscellaneous (mostly renamings)
969 modid :: { ModuleName }
970 : CONID { mkSrcModuleFS $1 }
973 : CONID { mkSrcUnqual tcClsName $1 }
975 qtycon :: { RdrName }
977 | QCONID { case $1 of { (mod,n) ->
978 mkSrcQual tcClsName mod n } }
980 qtycls :: { RdrName }
984 : VARID { mkSrcUnqual tvName $1 }
985 | 'as' { as_tyvar_RDR }
986 | 'qualified' { qualified_tyvar_RDR }
987 | 'hiding' { hiding_tyvar_RDR }
988 | 'export' { export_tyvar_RDR }
989 | 'label' { label_tyvar_RDR }
990 | 'dynamic' { dynamic_tyvar_RDR }
991 | 'unsafe' { unsafe_tyvar_RDR }
992 | 'stdcall' { stdcall_tyvar_RDR }
993 | 'ccall' { ccall_tyvar_RDR }
996 -----------------------------------------------------------------------------
1000 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)