2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.5 1999/06/03 14:44:23 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
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 '_ccall_' { ITccall (False, False, False) }
97 '_ccall_GC_' { ITccall (False, False, True) }
98 '_casm_' { ITccall (False, True, False) }
99 '_casm_GC_' { ITccall (False, True, True) }
101 '{-# SPECIALISE' { ITspecialise_prag }
102 '{-# SOURCE' { ITsource_prag }
103 '{-# INLINE' { ITinline_prag }
104 '{-# NOINLINE' { ITnoinline_prag }
105 '{-# RULES' { ITrules_prag }
106 '#-}' { ITclose_prag }
109 '__interface' { ITinterface } -- interface keywords
110 '__export' { IT__export }
111 '__instimport' { ITinstimport }
112 '__forall' { IT__forall }
113 '__letrec' { ITletrec }
114 '__coerce' { ITcoerce }
115 '__depends' { ITdepends }
116 '__inline' { ITinline }
117 '__DEFAULT' { ITdefaultbranch }
119 '__integer' { ITinteger_lit }
120 '__float' { ITfloat_lit }
121 '__rational' { ITrational_lit }
122 '__addr' { ITaddr_lit }
123 '__litlit' { ITlit_lit }
124 '__string' { ITstring_lit }
125 '__ccall' { ITccall $$ }
127 '__sccC' { ITsccAllCafs }
130 '__P' { ITspecialise }
132 '__U' { ITunfold $$ }
133 '__S' { ITstrict $$ }
134 '__M' { ITcprinfo $$ }
137 '..' { ITdotdot } -- reserved symbols
151 '/\\' { ITbiglam } -- GHC-extension symbols
153 '{' { ITocurly } -- special symbols
155 vccurly { ITvccurly } -- virtual close curly (from layout)
166 VARID { ITvarid $$ } -- identifiers
168 VARSYM { ITvarsym $$ }
169 CONSYM { ITconsym $$ }
170 QVARID { ITqvarid $$ }
171 QCONID { ITqconid $$ }
172 QVARSYM { ITqvarsym $$ }
173 QCONSYM { ITqconsym $$ }
175 PRAGMA { ITpragma $$ }
178 STRING { ITstring $$ }
179 INTEGER { ITinteger $$ }
180 RATIONAL { ITrational $$ }
182 PRIMCHAR { ITprimchar $$ }
183 PRIMSTRING { ITprimstring $$ }
184 PRIMINTEGER { ITprimint $$ }
185 PRIMFLOAT { ITprimfloat $$ }
186 PRIMDOUBLE { ITprimdouble $$ }
187 CLITLIT { ITlitlit $$ }
189 UNKNOWN { ITunknown $$ }
191 %monad { P } { thenP } { returnP }
192 %lexer { lexer } { ITeof }
197 -----------------------------------------------------------------------------
200 module :: { RdrNameHsModule }
201 : srcloc 'module' modid maybeexports 'where' body
202 { HsModule $3 Nothing $4 (fst $6) (snd $6) $1 }
204 { HsModule mAIN_Name Nothing Nothing (fst $2) (snd $2) $1 }
206 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
208 | layout_on top close { $2 }
210 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
211 : importdecls ';' cvtopdecls { (reverse $1,$3) }
212 | importdecls { (reverse $1,[]) }
213 | cvtopdecls { ([],$1) }
215 cvtopdecls :: { [RdrNameHsDecl] }
216 : topdecls { cvTopDecls (groupBindings $1)}
218 -----------------------------------------------------------------------------
221 maybeexports :: { Maybe [RdrNameIE] }
222 : '(' exportlist ')' { Just $2 }
223 | {- empty -} { Nothing }
225 exportlist :: { [RdrNameIE] }
226 : exportlist ',' export { $3 : $1 }
227 | exportlist ',' { $1 }
231 -- GHC extension: we allow things like [] and (,,,) to be exported
232 export :: { RdrNameIE }
234 | gtycon { IEThingAbs $1 }
235 | gtycon '(' '..' ')' { IEThingAll $1 }
236 | gtycon '(' ')' { IEThingWith $1 [] }
237 | gtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
238 | 'module' modid { IEModuleContents $2 }
240 qcnames :: { [RdrName] }
241 : qcnames ',' qcname { $3 : $1 }
244 qcname :: { RdrName }
248 -----------------------------------------------------------------------------
249 -- Import Declarations
251 -- import decls can be *empty*, or even just a string of semicolons
252 -- whereas topdecls must contain at least one topdecl.
254 importdecls :: { [RdrNameImportDecl] }
255 : importdecls ';' importdecl { $3 : $1 }
256 | importdecls ';' { $1 }
257 | importdecl { [ $1 ] }
260 importdecl :: { RdrNameImportDecl }
261 : 'import' srcloc maybe_src optqualified CONID maybeas maybeimpspec
262 { ImportDecl (mkSrcModuleFS $5) $3 $4 $6 $7 $2 }
264 maybe_src :: { WhereFrom }
265 : '{-# SOURCE' '#-}' { ImportByUserSource }
266 | {- empty -} { ImportByUser }
268 optqualified :: { Bool }
269 : 'qualified' { True }
270 | {- empty -} { False }
272 maybeas :: { Maybe ModuleName }
273 : 'as' modid { Just $2 }
274 | {- empty -} { Nothing }
276 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
277 : impspec { Just $1 }
278 | {- empty -} { Nothing }
280 impspec :: { (Bool, [RdrNameIE]) }
281 : '(' exportlist ')' { (False, reverse $2) }
282 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
284 -----------------------------------------------------------------------------
285 -- Fixity Declarations
289 | INTEGER {% checkPrec $1 `thenP_`
290 returnP (fromInteger $1) }
292 infix :: { FixityDirection }
294 | 'infixl' { InfixL }
295 | 'infixr' { InfixR }
298 : ops ',' op { $3 : $1 }
301 -----------------------------------------------------------------------------
302 -- Top-Level Declarations
304 topdecls :: { [RdrBinding] }
305 : topdecls ';' topdecl { ($3 : $1) }
306 | topdecls ';' { $1 }
309 topdecl :: { RdrBinding }
310 : srcloc 'type' simpletype '=' type
311 { RdrHsDecl (TyClD (TySynonym (fst $3) (snd $3) $5 $1)) }
313 | srcloc 'data' ctype '=' constrs deriving
314 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
315 returnP (RdrHsDecl (TyClD
316 (TyData DataType cs c ts (reverse $5) $6
317 NoDataPragmas $1))) }
319 | srcloc 'newtype' ctype '=' newconstr deriving
320 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
321 returnP (RdrHsDecl (TyClD
322 (TyData NewType cs c ts [$5] $6
323 NoDataPragmas $1))) }
325 | srcloc 'class' ctype where
326 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
328 = cvMonoBindsAndSigs cvClassOpSig
331 returnP (RdrHsDecl (TyClD
332 (mkClassDecl cs c ts sigs binds
333 NoClassPragmas $1))) }
335 | srcloc 'instance' inst_type where
337 = cvMonoBindsAndSigs cvInstDeclSig
340 (InstDecl $3 binds sigs dummyRdrVarName $1)) }
342 | srcloc 'default' '(' types0 ')'
343 { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
345 | srcloc 'foreign' 'import' callconv ext_name
346 unsafe_flag varid_no_unsafe '::' sigtype
347 { RdrHsDecl (ForD (ForeignDecl $7 (FoImport $6) $9 $5 $4 $1)) }
349 | srcloc 'foreign' 'export' callconv ext_name varid '::' sigtype
350 { RdrHsDecl (ForD (ForeignDecl $6 FoExport $8 $5 $4 $1)) }
352 | srcloc 'foreign' 'label' ext_name varid '::' sigtype
353 { RdrHsDecl (ForD (ForeignDecl $5 FoLabel $7 $4
354 defaultCallConv $1)) }
358 decls :: { [RdrBinding] }
359 : decls ';' decl { $3 : $1 }
364 decl :: { RdrBinding }
367 | valdef { RdrValBinding $1 }
368 | '{-# INLINE' srcloc qvar '#-}' { RdrSig (InlineSig $3 $2) }
369 | '{-# NOINLINE' srcloc qvar '#-}' { RdrSig (NoInlineSig $3 $2) }
370 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
371 { foldr1 RdrAndBindings
372 (map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
373 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
374 { RdrSig (SpecInstSig $4 $2) }
375 | '{-# RULES' rules '#-}' { $2 }
377 sigtypes :: { [RdrNameHsType] }
379 | sigtypes ',' sigtype { $3 : $1 }
381 wherebinds :: { RdrNameHsBinds }
382 : where { cvBinds cvValSig (groupBindings $1) }
384 where :: { [RdrBinding] }
385 : 'where' decllist { $2 }
388 declbinds :: { RdrNameHsBinds }
389 : decllist { cvBinds cvValSig (groupBindings $1) }
391 decllist :: { [RdrBinding] }
392 : '{' decls '}' { $2 }
393 | layout_on decls close { $2 }
395 fixdecl :: { RdrBinding }
396 : srcloc infix prec ops { foldr1 RdrAndBindings
397 [ RdrSig (FixSig (FixitySig n
401 signdecl :: { RdrBinding }
402 : vars srcloc '::' sigtype { foldr1 RdrAndBindings
403 [ RdrSig (Sig n $4 $2) | n <- $1 ] }
405 sigtype :: { RdrNameHsType }
407 HsForAllTy _ _ _ -> $1
408 other -> HsForAllTy 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 : VARID {% checkCallConv $1 }
457 | {- empty -} { defaultCallConv }
459 unsafe_flag :: { Bool }
461 | {- empty -} { False }
463 ext_name :: { ExtName }
464 : 'dynamic' { Dynamic }
465 | STRING { ExtName $1 Nothing }
466 | STRING STRING { ExtName $2 (Just $1) }
468 -----------------------------------------------------------------------------
471 {- ToDo: forall stuff -}
473 type :: { RdrNameHsType }
474 : btype '->' type { MonoFunTy $1 $3 }
477 btype :: { RdrNameHsType }
478 : btype atype { MonoTyApp $1 $2 }
481 atype :: { RdrNameHsType }
482 : gtycon { MonoTyVar $1 }
483 | tyvar { MonoTyVar $1 }
484 | '(' type ',' types ')' { MonoTupleTy ($2 : reverse $4) True }
485 | '(#' types '#)' { MonoTupleTy (reverse $2) False }
486 | '[' type ']' { MonoListTy $2 }
487 | '(' ctype ')' { $2 }
489 gtycon :: { RdrName }
491 | '(' ')' { unitTyCon_RDR }
492 | '(' '->' ')' { funTyCon_RDR }
493 | '[' ']' { listTyCon_RDR }
494 | '(' commas ')' { tupleTyCon_RDR $2 }
496 -- An inst_type is what occurs in the head of an instance decl
497 -- e.g. (Foo a, Gaz b) => Wibble a b
498 -- It's kept as a single type, with a MonoDictTy at the right
499 -- hand corner, for convenience.
500 inst_type :: { RdrNameHsType }
501 : ctype {% checkInstType $1 }
503 ctype :: { RdrNameHsType }
504 : 'forall' tyvars '.' btype '=>' type
505 {% checkContext $4 `thenP` \c ->
506 returnP (HsForAllTy (Just $2) c $6) }
507 | 'forall' tyvars '.' type { HsForAllTy (Just $2) [] $4 }
508 | btype '=>' type {% checkContext $1 `thenP` \c ->
509 returnP (HsForAllTy Nothing c $3) }
512 types0 :: { [RdrNameHsType] }
516 types :: { [RdrNameHsType] }
518 | types ',' type { $3 : $1 }
520 simpletype :: { (RdrName, [RdrNameHsTyVar]) }
521 : tycon tyvars { ($1, reverse $2) }
523 tyvars :: { [RdrNameHsTyVar] }
524 : tyvars tyvar { UserTyVar $2 : $1 }
527 -----------------------------------------------------------------------------
528 -- Datatype declarations
530 constrs :: { [RdrNameConDecl] }
531 : constrs '|' constr { $3 : $1 }
534 {- ToDo: existential stuff -}
536 constr :: { RdrNameConDecl }
538 { ConDecl (fst $2) [] [] (VanillaCon (snd $2)) $1 }
539 | srcloc sbtype conop sbtype
540 { ConDecl $3 [] [] (InfixCon $2 $4) $1 }
541 | srcloc con '{' fielddecls '}'
542 { ConDecl $2 [] [] (RecCon (reverse $4)) $1 }
544 newconstr :: { RdrNameConDecl }
545 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
546 | srcloc conid '{' var '::' type '}'
547 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
549 scontype :: { (RdrName, [RdrNameBangType]) }
550 : btype {% splitForConApp $1 [] }
553 scontype1 :: { (RdrName, [RdrNameBangType]) }
554 : btype '!' atype {% splitForConApp $1 [Banged $3] }
555 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
557 satype :: { RdrNameBangType }
558 : atype { Unbanged $1 }
559 | '!' atype { Banged $2 }
561 sbtype :: { RdrNameBangType }
562 : btype { Unbanged $1 }
563 | '!' atype { Banged $2 }
565 fielddecls :: { [([RdrName],RdrNameBangType)] }
566 : fielddecls ',' fielddecl { $3 : $1 }
569 fielddecl :: { ([RdrName],RdrNameBangType) }
570 : vars '::' stype { (reverse $1, $3) }
572 stype :: { RdrNameBangType }
573 : type { Unbanged $1 }
574 | '!' atype { Banged $2 }
576 deriving :: { Maybe [RdrName] }
577 : {- empty -} { Nothing }
578 | 'deriving' qtycls { Just [$2] }
579 | 'deriving' '(' ')' { Just [] }
580 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
582 dclasses :: { [RdrName] }
583 : dclasses ',' qtycls { $3 : $1 }
586 -----------------------------------------------------------------------------
589 valdef :: { RdrNameMonoBinds }
590 : infixexp {-ToDo: opt_sig-} srcloc rhs
591 {% checkValDef $1 Nothing $3 $2 }
593 rhs :: { RdrNameGRHSs }
594 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
596 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
598 gdrhs :: { [RdrNameGRHS] }
599 : gdrhs gdrh { $2 : $1 }
602 gdrh :: { RdrNameGRHS }
603 : '|' srcloc quals '=' exp { GRHS (reverse
604 (ExprStmt $5 $2 : $3)) $2 }
606 -----------------------------------------------------------------------------
609 exp :: { RdrNameHsExpr }
610 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
613 infixexp :: { RdrNameHsExpr }
615 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
617 exp10 :: { RdrNameHsExpr }
618 : '\\' aexp aexps opt_asig '->' srcloc exp
619 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
620 returnP (HsLam (Match [] ps $4
621 (GRHSs (unguardedRHS $7 $6)
622 EmptyBinds Nothing))) }
623 | 'let' declbinds 'in' exp { HsLet $2 $4 }
624 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
625 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
626 | '-' fexp { NegApp $2 (error "NegApp") }
627 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
629 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
630 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
631 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
632 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
634 | '_scc_' STRING exp { if opt_SccProfilingOn
640 ccallid :: { FAST_STRING }
644 fexp :: { RdrNameHsExpr }
645 : fexp aexp { HsApp $1 $2 }
648 aexps0 :: { [RdrNameHsExpr] }
649 : aexps { reverse $1 }
651 aexps :: { [RdrNameHsExpr] }
652 : aexps aexp { $2 : $1 }
655 aexp :: { RdrNameHsExpr }
656 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
659 aexp1 :: { RdrNameHsExpr }
662 | literal { HsLit $1 }
663 | '(' exp ')' { HsPar $2 }
664 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
665 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
666 | '[' list ']' { $2 }
667 | '(' infixexp qop ')' { SectionL $2 $3 }
668 | '(' qopm infixexp ')' { SectionR $2 $3 }
669 | qvar '@' aexp { EAsPat $1 $3 }
671 | '~' aexp1 { ELazyPat $2 }
674 : commas ',' { $1 + 1 }
677 texps :: { [RdrNameHsExpr] }
678 : texps ',' exp { $3 : $1 }
681 -----------------------------------------------------------------------------
684 -- The rules below are little bit contorted to keep lexps left-recursive while
685 -- avoiding another shift/reduce-conflict.
687 list :: { RdrNameHsExpr }
688 : exp { ExplicitList [$1] }
689 | lexps { ExplicitList (reverse $1) }
690 | exp '..' { ArithSeqIn (From $1) }
691 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
692 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
693 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
694 | exp srcloc '|' quals { HsDo ListComp (reverse
695 (ReturnStmt $1 : $4)) $2 }
697 lexps :: { [RdrNameHsExpr] }
698 : lexps ',' exp { $3 : $1 }
699 | exp ',' exp { [$3,$1] }
701 -----------------------------------------------------------------------------
702 -- List Comprehensions
704 quals :: { [RdrNameStmt] }
705 : quals ',' qual { $3 : $1 }
708 qual :: { RdrNameStmt }
709 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
710 returnP (BindStmt p $4 $1) }
711 | srcloc exp { GuardStmt $2 $1 }
712 | srcloc 'let' declbinds { LetStmt $3 }
714 -----------------------------------------------------------------------------
717 altslist :: { [RdrNameMatch] }
718 : '{' alts '}' { reverse $2 }
719 | layout_on alts close { reverse $2 }
722 alts :: { [RdrNameMatch] }
723 : alts ';' alt { $3 : $1 }
728 alt :: { RdrNameMatch }
729 : infixexp opt_sig ralt wherebinds
730 {% checkPattern $1 `thenP` \p ->
731 returnP (Match [] [p] $2
732 (GRHSs $3 $4 Nothing)) }
734 opt_sig :: { Maybe RdrNameHsType }
735 : {- empty -} { Nothing }
736 | '::' type { Just $2 }
738 opt_asig :: { Maybe RdrNameHsType }
739 : {- empty -} { Nothing }
740 | '::' atype { Just $2 }
742 ralt :: { [RdrNameGRHS] }
743 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
744 | gdpats { (reverse $1) }
746 gdpats :: { [RdrNameGRHS] }
747 : gdpats gdpat { $2 : $1 }
750 gdpat :: { RdrNameGRHS }
751 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
753 -----------------------------------------------------------------------------
754 -- Statement sequences
756 stmtlist :: { [RdrNameStmt] }
757 : '{' stmts '}' { reverse $2 }
758 | layout_on stmts close { reverse $2 }
760 stmts :: { [RdrNameStmt] }
761 : stmts ';' stmt { $3 : $1 }
766 stmt :: { RdrNameStmt }
767 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
768 returnP (BindStmt p $4 $1) }
769 | srcloc exp { ExprStmt $2 $1 }
770 | srcloc 'let' declbinds { LetStmt $3 }
772 -----------------------------------------------------------------------------
773 -- Record Field Update/Construction
775 fbinds :: { RdrNameHsRecordBinds }
776 : fbinds ',' fbind { $3 : $1 }
781 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
782 : qvar '=' exp { ($1,$3,False) }
784 -----------------------------------------------------------------------------
785 -- Variables, Constructors and Operators.
788 : '(' ')' { unitCon_RDR }
789 | '[' ']' { nilCon_RDR }
790 | '(' commas ')' { tupleCon_RDR $2 }
795 | '(' varsym ')' { $2 }
799 | '(' qvarsym ')' { $2 }
803 | '(' consym ')' { $2 }
807 | '(' qconsym ')' { $2 }
811 | '`' varid '`' { $2 }
813 qvarop :: { RdrName }
815 | '`' qvarid '`' { $2 }
817 qvaropm :: { RdrName }
819 | '`' qvarid '`' { $2 }
823 | '`' conid '`' { $2 }
825 qconop :: { RdrName }
827 | '`' qconid '`' { $2 }
829 -----------------------------------------------------------------------------
832 op :: { RdrName } -- used in infix decls
836 qop :: { RdrNameHsExpr } -- used in sections
837 : qvarop { HsVar $1 }
838 | qconop { HsVar $1 }
840 qopm :: { RdrNameHsExpr } -- used in sections
841 : qvaropm { HsVar $1 }
842 | qconop { HsVar $1 }
844 -----------------------------------------------------------------------------
847 qvarid :: { RdrName }
849 | QVARID { case $1 of { (mod,n) ->
850 mkSrcQual varName mod n } }
853 : VARID { mkSrcUnqual varName $1 }
854 | 'as' { as_var_RDR }
855 | 'qualified' { qualified_var_RDR }
856 | 'hiding' { hiding_var_RDR }
857 | 'forall' { forall_var_RDR }
858 | 'export' { export_var_RDR }
859 | 'label' { label_var_RDR }
860 | 'dynamic' { dynamic_var_RDR }
861 | 'unsafe' { unsafe_var_RDR }
863 varid_no_unsafe :: { RdrName }
864 : VARID { mkSrcUnqual varName $1 }
865 | 'as' { as_var_RDR }
866 | 'qualified' { qualified_var_RDR }
867 | 'hiding' { hiding_var_RDR }
868 | 'forall' { forall_var_RDR }
869 | 'export' { export_var_RDR }
870 | 'label' { label_var_RDR }
871 | 'dynamic' { dynamic_var_RDR }
873 -----------------------------------------------------------------------------
876 qconid :: { RdrName }
878 | QCONID { case $1 of { (mod,n) ->
879 mkSrcQual dataName mod n } }
882 : CONID { mkSrcUnqual dataName $1 }
884 -----------------------------------------------------------------------------
887 qconsym :: { RdrName }
889 | QCONSYM { case $1 of { (mod,n) ->
890 mkSrcQual dataName mod n } }
892 consym :: { RdrName }
893 : CONSYM { mkSrcUnqual dataName $1 }
895 -----------------------------------------------------------------------------
898 qvarsym :: { RdrName }
902 qvarsymm :: { RdrName }
906 varsym :: { RdrName }
907 : VARSYM { mkSrcUnqual varName $1 }
912 varsymm :: { RdrName } -- varsym not including '-'
913 : VARSYM { mkSrcUnqual varName $1 }
917 qvarsym1 :: { RdrName }
918 : QVARSYM { case $1 of { (mod,n) ->
919 mkSrcQual varName mod n } }
922 : INTEGER { HsInt $1 }
924 | RATIONAL { HsFrac $1 }
925 | STRING { HsString $1 }
927 | PRIMINTEGER { HsIntPrim $1 }
928 | PRIMCHAR { HsCharPrim $1 }
929 | PRIMSTRING { HsStringPrim $1 }
930 | PRIMFLOAT { HsFloatPrim $1 }
931 | PRIMDOUBLE { HsDoublePrim $1 }
932 | CLITLIT { HsLitLit $1 }
934 srcloc :: { SrcLoc } : {% getSrcLocP }
936 -----------------------------------------------------------------------------
940 : vccurly { () } -- context popped in lexer.
941 | error {% popContext }
943 layout_on :: { () } : {% layoutOn }
945 -----------------------------------------------------------------------------
946 -- Miscellaneous (mostly renamings)
948 modid :: { ModuleName }
949 : CONID { mkSrcModuleFS $1 }
952 : CONID { mkSrcUnqual tcClsName $1 }
954 qtycon :: { RdrName }
956 | QCONID { case $1 of { (mod,n) ->
957 mkSrcQual tcClsName mod n } }
959 qtycls :: { RdrName }
963 : VARID { mkSrcUnqual tvName $1 }
964 | 'as' { as_tyvar_RDR }
965 | 'qualified' { qualified_tyvar_RDR }
966 | 'hiding' { hiding_tyvar_RDR }
967 | 'export' { export_var_RDR }
968 | 'label' { label_var_RDR }
969 | 'dynamic' { dynamic_var_RDR }
970 | 'unsafe' { unsafe_var_RDR }
973 -----------------------------------------------------------------------------
977 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)