2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.1 1999/06/01 16:40:48 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 BasicTypes ( Fixity(..), FixityDirection(..), NewOrData(..) )
31 #include "HsVersions.h"
35 -----------------------------------------------------------------------------
36 Conflicts: 13 shift/reduce
38 8 for abiguity in 'if x then y else z + 1'
39 (shift parses as 'if x then y else (z + 1)', as per longest-parse rule)
40 1 for ambiguity in 'if x then y else z :: T'
41 (shift parses as 'if x then y else (z :: T)', as per longest-parse rule)
42 3 for ambiguity in 'case x of y :: a -> b'
43 (don't know whether to reduce 'a' as a btype or shift the '->'.
44 conclusion: bogus expression anyway, doesn't matter)
46 1 for ambiguity in '{-# RULES "name" forall = ... #-}'
47 since 'forall' is a valid variable name, we don't know whether
48 to treat a forall on the input as the beginning of a quantifier
49 or the beginning of the rule itself. Resolving to shift means
50 it's always treated as a quantifier, hence the above is disallowed.
51 This saves explicitly defining a grammar for the rule lhs that
52 doesn't include 'forall'.
54 -----------------------------------------------------------------------------
58 '_' { ITunderscore } -- Haskell keywords
63 'default' { ITdefault }
64 'deriving' { ITderiving }
74 'instance' { ITinstance }
77 'newtype' { ITnewtype }
79 'qualified' { ITqualified }
84 'forall' { ITforall } -- GHC extension keywords
85 'foreign' { ITforeign }
88 'dynamic' { ITdynamic }
90 '_ccall_' { ITccall (False, False, False) }
91 '_ccall_GC_' { ITccall (False, False, True) }
92 '_casm_' { ITccall (False, True, False) }
93 '_casm_GC_' { ITccall (False, True, True) }
95 '{-# SPECIALISE' { ITspecialise_prag }
96 '{-# SOURCE' { ITsource_prag }
97 '{-# INLINE' { ITinline_prag }
98 '{-# NOINLINE' { ITnoinline_prag }
99 '{-# RULES' { ITrules_prag }
100 '#-}' { ITclose_prag }
103 '__interface' { ITinterface } -- interface keywords
104 '__export' { IT__export }
105 '__instimport' { ITinstimport }
106 '__forall' { IT__forall }
107 '__letrec' { ITletrec }
108 '__coerce' { ITcoerce }
109 '__depends' { ITdepends }
110 '__inline' { ITinline }
111 '__DEFAULT' { ITdefaultbranch }
113 '__integer' { ITinteger_lit }
114 '__float' { ITfloat_lit }
115 '__rational' { ITrational_lit }
116 '__addr' { ITaddr_lit }
117 '__litlit' { ITlit_lit }
118 '__string' { ITstring_lit }
119 '__ccall' { ITccall $$ }
121 '__sccC' { ITsccAllCafs }
124 '__P' { ITspecialise }
126 '__U' { ITunfold $$ }
127 '__S' { ITstrict $$ }
128 '__M' { ITcprinfo $$ }
131 '..' { ITdotdot } -- reserved symbols
145 '/\\' { ITbiglam } -- GHC-extension symbols
147 '{' { ITocurly } -- special symbols
149 vccurly { ITvccurly } -- virtual close curly (from layout)
160 VARID { ITvarid $$ } -- identifiers
162 VARSYM { ITvarsym $$ }
163 CONSYM { ITconsym $$ }
164 QVARID { ITqvarid $$ }
165 QCONID { ITqconid $$ }
166 QVARSYM { ITqvarsym $$ }
167 QCONSYM { ITqconsym $$ }
169 PRAGMA { ITpragma $$ }
172 STRING { ITstring $$ }
173 INTEGER { ITinteger $$ }
174 RATIONAL { ITrational $$ }
176 PRIMCHAR { ITprimchar $$ }
177 PRIMSTRING { ITprimstring $$ }
178 PRIMINTEGER { ITprimint $$ }
179 PRIMFLOAT { ITprimfloat $$ }
180 PRIMDOUBLE { ITprimdouble $$ }
181 CLITLIT { ITlitlit $$ }
183 UNKNOWN { ITunknown $$ }
185 %monad { P } { thenP } { returnP }
186 %lexer { lexer } { ITeof }
191 -----------------------------------------------------------------------------
194 module :: { RdrNameHsModule }
195 : srcloc 'module' modid maybeexports 'where' body
196 { HsModule $3 Nothing $4 (fst $6) (snd $6) $1 }
198 { HsModule mAIN_Name Nothing Nothing (fst $2) (snd $2) $1 }
200 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
202 | layout_on top close { $2 }
204 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
205 : importdecls ';' cvtopdecls { (reverse $1,$3) }
206 | importdecls { (reverse $1,[]) }
207 | cvtopdecls { ([],$1) }
209 cvtopdecls :: { [RdrNameHsDecl] }
210 : topdecls { cvTopDecls (groupBindings $1)}
212 -----------------------------------------------------------------------------
215 maybeexports :: { Maybe [RdrNameIE] }
216 : '(' exportlist ')' { Just $2 }
217 | {- empty -} { Nothing }
219 exportlist :: { [RdrNameIE] }
220 : exportlist ',' export { $3 : $1 }
221 | exportlist ',' { $1 }
225 -- GHC extension: we allow things like [] and (,,,) to be exported
226 export :: { RdrNameIE }
228 | gtycon { IEThingAbs $1 }
229 | gtycon '(' '..' ')' { IEThingAll $1 }
230 | gtycon '(' ')' { IEThingWith $1 [] }
231 | gtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
232 | 'module' modid { IEModuleContents $2 }
234 qcnames :: { [RdrName] }
235 : qcnames ',' qcname { $3 : $1 }
238 qcname :: { RdrName }
242 -----------------------------------------------------------------------------
243 -- Import Declarations
245 -- import decls can be *empty*, or even just a string of semicolons
246 -- whereas topdecls must contain at least one topdecl.
248 importdecls :: { [RdrNameImportDecl] }
249 : importdecls ';' importdecl { $3 : $1 }
250 | importdecls ';' { $1 }
251 | importdecl { [ $1 ] }
254 importdecl :: { RdrNameImportDecl }
255 : 'import' srcloc maybe_src optqualified CONID maybeas maybeimpspec
256 { ImportDecl (mkSrcModuleFS $5) $3 $4 $6 $7 $2 }
258 maybe_src :: { WhereFrom }
259 : '{-# SOURCE' '#-}' { ImportByUserSource }
260 | {- empty -} { ImportByUser }
262 optqualified :: { Bool }
263 : 'qualified' { True }
264 | {- empty -} { False }
266 maybeas :: { Maybe ModuleName }
267 : 'as' modid { Just $2 }
268 | {- empty -} { Nothing }
270 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
271 : impspec { Just $1 }
272 | {- empty -} { Nothing }
274 impspec :: { (Bool, [RdrNameIE]) }
275 : '(' exportlist ')' { (False, reverse $2) }
276 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
278 -----------------------------------------------------------------------------
279 -- Fixity Declarations
283 | INTEGER {% checkPrec $1 `thenP_`
284 returnP (fromInteger $1) }
286 infix :: { FixityDirection }
288 | 'infixl' { InfixL }
289 | 'infixr' { InfixR }
292 : ops ',' op { $3 : $1 }
295 -----------------------------------------------------------------------------
296 -- Top-Level Declarations
298 topdecls :: { [RdrBinding] }
299 : topdecls ';' topdecl { ($3 : $1) }
300 | topdecls ';' { $1 }
303 topdecl :: { RdrBinding }
304 : srcloc 'type' simpletype '=' type
305 { RdrHsDecl (TyClD (TySynonym (fst $3) (snd $3) $5 $1)) }
307 | srcloc 'data' ctype '=' constrs deriving
308 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
309 returnP (RdrHsDecl (TyClD
310 (TyData DataType cs c ts (reverse $5) $6
311 NoDataPragmas $1))) }
313 | srcloc 'newtype' ctype '=' newconstr deriving
314 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
315 returnP (RdrHsDecl (TyClD
316 (TyData NewType cs c ts [$5] $6
317 NoDataPragmas $1))) }
319 | srcloc 'class' ctype where
320 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
322 = cvMonoBindsAndSigs cvClassOpSig
325 returnP (RdrHsDecl (TyClD
326 (mkClassDecl cs c ts sigs binds
327 NoClassPragmas $1))) }
329 | srcloc 'instance' inst_type where
331 = cvMonoBindsAndSigs cvInstDeclSig
334 (InstDecl $3 binds sigs dummyRdrVarName $1)) }
336 | srcloc 'default' '(' types0 ')'
337 { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
339 | srcloc 'foreign' 'import' callconv ext_name
340 unsafe_flag varid_no_unsafe '::' sigtype
341 { RdrHsDecl (ForD (ForeignDecl $7 (FoImport $6) $9 $5 $4 $1)) }
343 | srcloc 'foreign' 'export' callconv ext_name varid '::' sigtype
344 { RdrHsDecl (ForD (ForeignDecl $6 FoExport $8 $5 $4 $1)) }
346 | srcloc 'foreign' 'label' ext_name varid '::' sigtype
347 { RdrHsDecl (ForD (ForeignDecl $5 FoLabel $7 $4
348 defaultCallConv $1)) }
352 decls :: { [RdrBinding] }
353 : decls ';' decl { $3 : $1 }
358 decl :: { RdrBinding }
361 | valdef { RdrValBinding $1 }
362 | '{-# INLINE' srcloc qvar '#-}' { RdrSig (InlineSig $3 $2) }
363 | '{-# NOINLINE' srcloc qvar '#-}' { RdrSig (NoInlineSig $3 $2) }
364 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
365 { foldr1 RdrAndBindings
366 (map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
367 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
368 { RdrSig (SpecInstSig $4 $2) }
369 | '{-# RULES' rules '#-}' { $2 }
371 sigtypes :: { [RdrNameHsType] }
373 | sigtypes ',' sigtype { $3 : $1 }
375 wherebinds :: { RdrNameHsBinds }
376 : where { cvBinds cvValSig (groupBindings $1) }
378 where :: { [RdrBinding] }
379 : 'where' decllist { $2 }
382 declbinds :: { RdrNameHsBinds }
383 : decllist { cvBinds cvValSig (groupBindings $1) }
385 decllist :: { [RdrBinding] }
386 : '{' decls '}' { $2 }
387 | layout_on decls close { $2 }
389 fixdecl :: { RdrBinding }
390 : srcloc infix prec ops { foldr1 RdrAndBindings
391 [ RdrSig (FixSig (FixitySig n
395 signdecl :: { RdrBinding }
396 : vars srcloc '::' sigtype { foldr1 RdrAndBindings
397 [ RdrSig (Sig n $4 $2) | n <- $1 ] }
399 sigtype :: { RdrNameHsType }
401 HsForAllTy _ _ _ -> $1
402 other -> HsForAllTy Nothing [] $1 }
405 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
406 instead of qvar, we get another shift/reduce-conflict. Consider the
409 { (+) :: ... } only var
410 { (+) x y = ... } could (incorrectly) be qvar
412 We re-use expressions for patterns, so a qvar would be allowed in patterns
413 instead of a var only (which would be correct). But deciding what the + is,
414 would require more lookahead. So let's check for ourselves...
417 vars :: { [RdrName] }
418 : vars ',' var { $3 : $1 }
421 -----------------------------------------------------------------------------
422 -- Transformation Rules
424 rules :: { RdrBinding }
425 : rules ';' rule { $1 `RdrAndBindings` $3 }
428 | {- empty -} { RdrNullBind }
430 rule :: { RdrBinding }
431 : STRING rule_forall fexp '=' srcloc exp
432 { RdrHsDecl (RuleD (RuleDecl $1 (error "rule tyvars")
435 rule_forall :: { [RdrNameRuleBndr] }
436 : 'forall' rule_var_list '.' { $2 }
439 rule_var_list :: { [RdrNameRuleBndr] }
441 | rule_var ',' rule_var_list { $1 : $3 }
443 rule_var :: { RdrNameRuleBndr }
444 : varid { RuleBndr $1 }
445 | varid '::' ctype { RuleBndrSig $1 $3 }
447 -----------------------------------------------------------------------------
448 -- Foreign import/export
451 : VARID {% checkCallConv $1 }
452 | {- empty -} { defaultCallConv }
454 unsafe_flag :: { Bool }
456 | {- empty -} { False }
458 ext_name :: { ExtName }
459 : 'dynamic' { Dynamic }
460 | STRING { ExtName $1 Nothing }
461 | STRING STRING { ExtName $2 (Just $1) }
463 -----------------------------------------------------------------------------
466 {- ToDo: forall stuff -}
468 type :: { RdrNameHsType }
469 : btype '->' type { MonoFunTy $1 $3 }
472 btype :: { RdrNameHsType }
473 : btype atype { MonoTyApp $1 $2 }
476 atype :: { RdrNameHsType }
477 : gtycon { MonoTyVar $1 }
478 | tyvar { MonoTyVar $1 }
479 | '(' type ',' types ')' { MonoTupleTy ($2 : reverse $4) True }
480 | '(#' types '#)' { MonoTupleTy (reverse $2) False }
481 | '[' type ']' { MonoListTy $2 }
482 | '(' ctype ')' { $2 }
484 gtycon :: { RdrName }
486 | '(' ')' { unitTyCon_RDR }
487 | '(' '->' ')' { funTyCon_RDR }
488 | '[' ']' { listTyCon_RDR }
489 | '(' commas ')' { tupleTyCon_RDR $2 }
491 -- An inst_type is what occurs in the head of an instance decl
492 -- e.g. (Foo a, Gaz b) => Wibble a b
493 -- It's kept as a single type, with a MonoDictTy at the right
494 -- hand corner, for convenience.
495 inst_type :: { RdrNameHsType }
496 : ctype {% checkInstType $1 }
498 ctype :: { RdrNameHsType }
499 : 'forall' tyvars '.' btype '=>' type
500 {% checkContext $4 `thenP` \c ->
501 returnP (HsForAllTy (Just $2) c $6) }
502 | 'forall' tyvars '.' type { HsForAllTy (Just $2) [] $4 }
503 | btype '=>' type {% checkContext $1 `thenP` \c ->
504 returnP (HsForAllTy Nothing c $3) }
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 {- ToDo: existential stuff -}
531 constr :: { RdrNameConDecl }
533 { ConDecl (fst $2) [] [] (VanillaCon (snd $2)) $1 }
534 | srcloc sbtype conop sbtype
535 { ConDecl $3 [] [] (InfixCon $2 $4) $1 }
536 | srcloc con '{' fielddecls '}'
537 { ConDecl $2 [] [] (RecCon (reverse $4)) $1 }
539 newconstr :: { RdrNameConDecl }
540 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
541 | srcloc conid '{' var '::' type '}'
542 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
544 scontype :: { (RdrName, [RdrNameBangType]) }
545 : btype {% splitForConApp $1 [] }
548 scontype1 :: { (RdrName, [RdrNameBangType]) }
549 : btype '!' atype {% splitForConApp $1 [Banged $3] }
550 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
552 satype :: { RdrNameBangType }
553 : atype { Unbanged $1 }
554 | '!' atype { Banged $2 }
556 sbtype :: { RdrNameBangType }
557 : btype { Unbanged $1 }
558 | '!' atype { Banged $2 }
560 fielddecls :: { [([RdrName],RdrNameBangType)] }
561 : fielddecls ',' fielddecl { $3 : $1 }
564 fielddecl :: { ([RdrName],RdrNameBangType) }
565 : vars '::' stype { (reverse $1, $3) }
567 stype :: { RdrNameBangType }
568 : type { Unbanged $1 }
569 | '!' atype { Banged $2 }
571 deriving :: { Maybe [RdrName] }
572 : {- empty -} { Nothing }
573 | 'deriving' qtycls { Just [$2] }
574 | 'deriving' '(' ')' { Just [] }
575 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
577 dclasses :: { [RdrName] }
578 : dclasses ',' qtycls { $3 : $1 }
581 -----------------------------------------------------------------------------
584 valdef :: { RdrNameMonoBinds }
585 : infixexp {-ToDo: opt_sig-} srcloc rhs
586 {% checkValDef $1 Nothing $3 $2 }
588 rhs :: { RdrNameGRHSs }
589 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
591 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
593 gdrhs :: { [RdrNameGRHS] }
594 : gdrhs gdrh { $2 : $1 }
597 gdrh :: { RdrNameGRHS }
598 : '|' srcloc quals '=' exp { GRHS (reverse
599 (ExprStmt $5 $2 : $3)) $2 }
601 -----------------------------------------------------------------------------
604 exp :: { RdrNameHsExpr }
605 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
608 infixexp :: { RdrNameHsExpr }
610 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
612 exp10 :: { RdrNameHsExpr }
613 : '\\' aexp aexps opt_asig '->' srcloc exp
614 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
615 returnP (HsLam (Match [] ps $4
616 (GRHSs (unguardedRHS $7 $6)
617 EmptyBinds Nothing))) }
618 | 'let' declbinds 'in' exp { HsLet $2 $4 }
619 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
620 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
621 | '-' fexp { NegApp $2 (error "NegApp") }
622 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
624 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
625 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
626 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
627 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
631 ccallid :: { FAST_STRING }
635 fexp :: { RdrNameHsExpr }
636 : fexp aexp { HsApp $1 $2 }
639 aexps0 :: { [RdrNameHsExpr] }
640 : aexps { reverse $1 }
642 aexps :: { [RdrNameHsExpr] }
643 : aexps aexp { $2 : $1 }
646 aexp :: { RdrNameHsExpr }
647 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
650 aexp1 :: { RdrNameHsExpr }
653 | literal { HsLit $1 }
654 | '(' exp ')' { HsPar $2 }
655 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
656 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
657 | '[' list ']' { $2 }
658 | '(' infixexp qop ')' { SectionL $2 $3 }
659 | '(' qopm infixexp ')' { SectionR $2 $3 }
660 | qvar '@' aexp1 { EAsPat $1 $3 }
662 | '~' aexp1 { ELazyPat $2 }
665 : commas ',' { $1 + 1 }
668 texps :: { [RdrNameHsExpr] }
669 : texps ',' exp { $3 : $1 }
672 -----------------------------------------------------------------------------
675 -- The rules below are little bit contorted to keep lexps left-recursive while
676 -- avoiding another shift/reduce-conflict.
678 list :: { RdrNameHsExpr }
679 : exp { ExplicitList [$1] }
680 | lexps { ExplicitList (reverse $1) }
681 | exp '..' { ArithSeqIn (From $1) }
682 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
683 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
684 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
685 | exp srcloc '|' quals { HsDo ListComp (reverse
686 (ReturnStmt $1 : $4)) $2 }
688 lexps :: { [RdrNameHsExpr] }
689 : lexps ',' exp { $3 : $1 }
690 | exp ',' exp { [$3,$1] }
692 -----------------------------------------------------------------------------
693 -- List Comprehensions
695 quals :: { [RdrNameStmt] }
696 : quals ',' qual { $3 : $1 }
699 qual :: { RdrNameStmt }
700 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
701 returnP (BindStmt p $4 $1) }
702 | srcloc exp { GuardStmt $2 $1 }
703 | srcloc 'let' declbinds { LetStmt $3 }
705 -----------------------------------------------------------------------------
708 altslist :: { [RdrNameMatch] }
709 : '{' alts '}' { reverse $2 }
710 | layout_on alts close { reverse $2 }
713 alts :: { [RdrNameMatch] }
714 : alts ';' alt { $3 : $1 }
719 alt :: { RdrNameMatch }
720 : infixexp opt_sig ralt wherebinds
721 {% checkPattern $1 `thenP` \p ->
722 returnP (Match [] [p] $2
723 (GRHSs $3 $4 Nothing)) }
725 opt_sig :: { Maybe RdrNameHsType }
726 : {- empty -} { Nothing }
727 | '::' type { Just $2 }
729 opt_asig :: { Maybe RdrNameHsType }
730 : {- empty -} { Nothing }
731 | '::' atype { Just $2 }
733 ralt :: { [RdrNameGRHS] }
734 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
735 | gdpats { (reverse $1) }
737 gdpats :: { [RdrNameGRHS] }
738 : gdpats gdpat { $2 : $1 }
741 gdpat :: { RdrNameGRHS }
742 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
744 -----------------------------------------------------------------------------
745 -- Statement sequences
747 stmtlist :: { [RdrNameStmt] }
748 : '{' stmts '}' { reverse $2 }
749 | layout_on stmts close { reverse $2 }
751 stmts :: { [RdrNameStmt] }
752 : stmts ';' stmt { $3 : $1 }
757 stmt :: { RdrNameStmt }
758 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
759 returnP (BindStmt p $4 $1) }
760 | srcloc exp { ExprStmt $2 $1 }
761 | srcloc 'let' declbinds { LetStmt $3 }
763 -----------------------------------------------------------------------------
764 -- Record Field Update/Construction
766 fbinds :: { RdrNameHsRecordBinds }
767 : fbinds ',' fbind { $3 : $1 }
772 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
773 : qvar '=' exp { ($1,$3,False) }
775 -----------------------------------------------------------------------------
776 -- Variables, Constructors and Operators.
779 : '(' ')' { unitCon_RDR }
780 | '[' ']' { nilCon_RDR }
781 | '(' commas ')' { tupleCon_RDR $2 }
786 | '(' varsym ')' { $2 }
790 | '(' qvarsym ')' { $2 }
794 | '(' consym ')' { $2 }
798 | '(' qconsym ')' { $2 }
802 | '`' varid '`' { $2 }
804 qvarop :: { RdrName }
806 | '`' qvarid '`' { $2 }
808 qvaropm :: { RdrName }
810 | '`' qvarid '`' { $2 }
814 | '`' conid '`' { $2 }
816 qconop :: { RdrName }
818 | '`' qconid '`' { $2 }
820 -----------------------------------------------------------------------------
823 op :: { RdrName } -- used in infix decls
827 qop :: { RdrNameHsExpr } -- used in sections
828 : qvarop { HsVar $1 }
829 | qconop { HsVar $1 }
831 qopm :: { RdrNameHsExpr } -- used in sections
832 : qvaropm { HsVar $1 }
833 | qconop { HsVar $1 }
835 -----------------------------------------------------------------------------
838 qvarid :: { RdrName }
840 | QVARID { case $1 of { (mod,n) ->
841 mkSrcQual varName mod n } }
844 : VARID { mkSrcUnqual varName $1 }
845 | 'as' { as_var_RDR }
846 | 'qualified' { qualified_var_RDR }
847 | 'hiding' { hiding_var_RDR }
848 | 'forall' { forall_var_RDR }
849 | 'export' { export_var_RDR }
850 | 'label' { label_var_RDR }
851 | 'dynamic' { dynamic_var_RDR }
852 | 'unsafe' { unsafe_var_RDR }
854 varid_no_unsafe :: { RdrName }
855 : VARID { mkSrcUnqual varName $1 }
856 | 'as' { as_var_RDR }
857 | 'qualified' { qualified_var_RDR }
858 | 'hiding' { hiding_var_RDR }
859 | 'forall' { forall_var_RDR }
860 | 'export' { export_var_RDR }
861 | 'label' { label_var_RDR }
862 | 'dynamic' { dynamic_var_RDR }
864 -----------------------------------------------------------------------------
867 qconid :: { RdrName }
869 | QCONID { case $1 of { (mod,n) ->
870 mkSrcQual dataName mod n } }
873 : CONID { mkSrcUnqual dataName $1 }
875 -----------------------------------------------------------------------------
878 qconsym :: { RdrName }
880 | QCONSYM { case $1 of { (mod,n) ->
881 mkSrcQual dataName mod n } }
883 consym :: { RdrName }
884 : CONSYM { mkSrcUnqual dataName $1 }
886 -----------------------------------------------------------------------------
889 qvarsym :: { RdrName }
893 qvarsymm :: { RdrName }
897 varsym :: { RdrName }
898 : VARSYM { mkSrcUnqual varName $1 }
903 varsymm :: { RdrName } -- varsym not including '-'
904 : VARSYM { mkSrcUnqual varName $1 }
908 qvarsym1 :: { RdrName }
909 : QVARSYM { case $1 of { (mod,n) ->
910 mkSrcQual varName mod n } }
913 : INTEGER { HsInt $1 }
915 | RATIONAL { HsFrac $1 }
916 | STRING { HsString $1 }
918 | PRIMINTEGER { HsIntPrim $1 }
919 | PRIMCHAR { HsCharPrim $1 }
920 | PRIMSTRING { HsStringPrim $1 }
921 | PRIMFLOAT { HsFloatPrim $1 }
922 | PRIMDOUBLE { HsDoublePrim $1 }
923 | CLITLIT { HsLitLit $1 }
925 srcloc :: { SrcLoc } : {% getSrcLocP }
927 -----------------------------------------------------------------------------
931 : vccurly { () } -- context popped in lexer.
932 | error {% popContext }
934 layout_on :: { () } : {% layoutOn }
936 -----------------------------------------------------------------------------
937 -- Miscellaneous (mostly renamings)
939 modid :: { ModuleName }
940 : CONID { mkSrcModuleFS $1 }
943 : CONID { mkSrcUnqual tcClsName $1 }
945 qtycon :: { RdrName }
947 | QCONID { case $1 of { (mod,n) ->
948 mkSrcQual tcClsName mod n } }
950 qtycls :: { RdrName }
954 : VARID { mkSrcUnqual tvName $1 }
955 | 'as' { as_tyvar_RDR }
956 | 'qualified' { qualified_tyvar_RDR }
957 | 'hiding' { hiding_tyvar_RDR }
958 | 'export' { export_var_RDR }
959 | 'label' { label_var_RDR }
960 | 'dynamic' { dynamic_var_RDR }
961 | 'unsafe' { unsafe_var_RDR }
964 -----------------------------------------------------------------------------
968 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)