2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.11 1999/07/26 16:06:28 simonpj 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 '.' context type
505 { HsForAllTy (Just $2) $4 $5 }
506 | 'forall' tyvars '.' type { HsForAllTy (Just $2) [] $4 }
507 | context type { HsForAllTy Nothing $1 $2 }
510 types0 :: { [RdrNameHsType] }
514 types :: { [RdrNameHsType] }
516 | types ',' type { $3 : $1 }
518 simpletype :: { (RdrName, [RdrNameHsTyVar]) }
519 : tycon tyvars { ($1, reverse $2) }
521 tyvars :: { [RdrNameHsTyVar] }
522 : tyvars tyvar { UserTyVar $2 : $1 }
525 -----------------------------------------------------------------------------
526 -- Datatype declarations
528 constrs :: { [RdrNameConDecl] }
529 : constrs '|' constr { $3 : $1 }
532 constr :: { RdrNameConDecl }
533 : srcloc forall context constr_stuff
534 { ConDecl (fst $4) $2 $3 (snd $4) $1 }
535 | srcloc forall constr_stuff
536 { ConDecl (fst $3) $2 [] (snd $3) $1 }
538 forall :: { [RdrNameHsTyVar] }
539 : 'forall' tyvars '.' { $2 }
542 context :: { RdrNameContext }
543 : btype '=>' {% checkContext $1 }
545 constr_stuff :: { (RdrName, RdrNameConDetails) }
546 : scontype { (fst $1, VanillaCon (snd $1)) }
547 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
548 | con '{' fielddecls '}' { ($1, RecCon (reverse $3)) }
550 newconstr :: { RdrNameConDecl }
551 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
552 | srcloc conid '{' var '::' type '}'
553 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
555 scontype :: { (RdrName, [RdrNameBangType]) }
556 : btype {% splitForConApp $1 [] }
559 scontype1 :: { (RdrName, [RdrNameBangType]) }
560 : btype '!' atype {% splitForConApp $1 [Banged $3] }
561 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
563 satype :: { RdrNameBangType }
564 : atype { Unbanged $1 }
565 | '!' atype { Banged $2 }
567 sbtype :: { RdrNameBangType }
568 : btype { Unbanged $1 }
569 | '!' atype { Banged $2 }
571 fielddecls :: { [([RdrName],RdrNameBangType)] }
572 : fielddecls ',' fielddecl { $3 : $1 }
575 fielddecl :: { ([RdrName],RdrNameBangType) }
576 : vars '::' stype { (reverse $1, $3) }
578 stype :: { RdrNameBangType }
579 : type { Unbanged $1 }
580 | '!' atype { Banged $2 }
582 deriving :: { Maybe [RdrName] }
583 : {- empty -} { Nothing }
584 | 'deriving' qtycls { Just [$2] }
585 | 'deriving' '(' ')' { Just [] }
586 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
588 dclasses :: { [RdrName] }
589 : dclasses ',' qtycls { $3 : $1 }
592 -----------------------------------------------------------------------------
595 valdef :: { RdrNameMonoBinds }
596 : infixexp {-ToDo: opt_sig-} srcloc rhs
597 {% checkValDef $1 Nothing $3 $2 }
599 rhs :: { RdrNameGRHSs }
600 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
602 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
604 gdrhs :: { [RdrNameGRHS] }
605 : gdrhs gdrh { $2 : $1 }
608 gdrh :: { RdrNameGRHS }
609 : '|' srcloc quals '=' exp { GRHS (reverse
610 (ExprStmt $5 $2 : $3)) $2 }
612 -----------------------------------------------------------------------------
615 exp :: { RdrNameHsExpr }
616 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
619 infixexp :: { RdrNameHsExpr }
621 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
623 exp10 :: { RdrNameHsExpr }
624 : '\\' aexp aexps opt_asig '->' srcloc exp
625 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
626 returnP (HsLam (Match [] ps $4
627 (GRHSs (unguardedRHS $7 $6)
628 EmptyBinds Nothing))) }
629 | 'let' declbinds 'in' exp { HsLet $2 $4 }
630 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
631 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
632 | '-' fexp { NegApp $2 (error "NegApp") }
633 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
635 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
636 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
637 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
638 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
640 | '_scc_' STRING exp { if opt_SccProfilingOn
646 ccallid :: { FAST_STRING }
650 fexp :: { RdrNameHsExpr }
651 : fexp aexp { HsApp $1 $2 }
654 aexps0 :: { [RdrNameHsExpr] }
655 : aexps { reverse $1 }
657 aexps :: { [RdrNameHsExpr] }
658 : aexps aexp { $2 : $1 }
661 aexp :: { RdrNameHsExpr }
662 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
665 aexp1 :: { RdrNameHsExpr }
668 | literal { HsLit $1 }
669 | '(' exp ')' { HsPar $2 }
670 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
671 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
672 | '[' list ']' { $2 }
673 | '(' infixexp qop ')' { SectionL $2 $3 }
674 | '(' qopm infixexp ')' { SectionR $2 $3 }
675 | qvar '@' aexp { EAsPat $1 $3 }
677 | '~' aexp1 { ELazyPat $2 }
680 : commas ',' { $1 + 1 }
683 texps :: { [RdrNameHsExpr] }
684 : texps ',' exp { $3 : $1 }
687 -----------------------------------------------------------------------------
690 -- The rules below are little bit contorted to keep lexps left-recursive while
691 -- avoiding another shift/reduce-conflict.
693 list :: { RdrNameHsExpr }
694 : exp { ExplicitList [$1] }
695 | lexps { ExplicitList (reverse $1) }
696 | exp '..' { ArithSeqIn (From $1) }
697 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
698 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
699 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
700 | exp srcloc '|' quals { HsDo ListComp (reverse
701 (ReturnStmt $1 : $4)) $2 }
703 lexps :: { [RdrNameHsExpr] }
704 : lexps ',' exp { $3 : $1 }
705 | exp ',' exp { [$3,$1] }
707 -----------------------------------------------------------------------------
708 -- List Comprehensions
710 quals :: { [RdrNameStmt] }
711 : quals ',' qual { $3 : $1 }
714 qual :: { RdrNameStmt }
715 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
716 returnP (BindStmt p $4 $1) }
717 | srcloc exp { GuardStmt $2 $1 }
718 | srcloc 'let' declbinds { LetStmt $3 }
720 -----------------------------------------------------------------------------
723 altslist :: { [RdrNameMatch] }
724 : '{' alts '}' { reverse $2 }
725 | layout_on alts close { reverse $2 }
728 alts :: { [RdrNameMatch] }
729 : alts ';' alt { $3 : $1 }
734 alt :: { RdrNameMatch }
735 : infixexp opt_sig ralt wherebinds
736 {% checkPattern $1 `thenP` \p ->
737 returnP (Match [] [p] $2
738 (GRHSs $3 $4 Nothing)) }
740 opt_sig :: { Maybe RdrNameHsType }
741 : {- empty -} { Nothing }
742 | '::' type { Just $2 }
744 opt_asig :: { Maybe RdrNameHsType }
745 : {- empty -} { Nothing }
746 | '::' atype { Just $2 }
748 ralt :: { [RdrNameGRHS] }
749 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
750 | gdpats { (reverse $1) }
752 gdpats :: { [RdrNameGRHS] }
753 : gdpats gdpat { $2 : $1 }
756 gdpat :: { RdrNameGRHS }
757 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
759 -----------------------------------------------------------------------------
760 -- Statement sequences
762 stmtlist :: { [RdrNameStmt] }
763 : '{' stmts '}' { $2 }
764 | layout_on_for_do stmts close { $2 }
766 -- Stmt list must end in an expression
767 -- thought the H98 report doesn't currently say so in the syntax
768 stmts :: { [RdrNameStmt] }
769 : stmts1 srcloc exp { reverse (ExprStmt $3 $2 : $1) }
771 -- A list of zero or more stmts, ending in semicolon
772 -- Returned in *reverse* order
773 stmts1 :: { [RdrNameStmt] }
774 : stmts1 stmt ';' { $2 : $1 }
778 stmt :: { RdrNameStmt }
779 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
780 returnP (BindStmt p $4 $1) }
781 | srcloc exp { ExprStmt $2 $1 }
782 | srcloc 'let' declbinds { LetStmt $3 }
784 -----------------------------------------------------------------------------
785 -- Record Field Update/Construction
787 fbinds :: { RdrNameHsRecordBinds }
788 : fbinds ',' fbind { $3 : $1 }
793 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
794 : qvar '=' exp { ($1,$3,False) }
796 -----------------------------------------------------------------------------
797 -- Variables, Constructors and Operators.
800 : '(' ')' { unitCon_RDR }
801 | '[' ']' { nilCon_RDR }
802 | '(' commas ')' { tupleCon_RDR $2 }
807 | '(' varsym ')' { $2 }
811 | '(' qvarsym ')' { $2 }
815 | '(' consym ')' { $2 }
819 | '(' qconsym ')' { $2 }
823 | '`' varid '`' { $2 }
825 qvarop :: { RdrName }
827 | '`' qvarid '`' { $2 }
829 qvaropm :: { RdrName }
831 | '`' qvarid '`' { $2 }
835 | '`' conid '`' { $2 }
837 qconop :: { RdrName }
839 | '`' qconid '`' { $2 }
841 -----------------------------------------------------------------------------
844 op :: { RdrName } -- used in infix decls
848 qop :: { RdrNameHsExpr } -- used in sections
849 : qvarop { HsVar $1 }
850 | qconop { HsVar $1 }
852 qopm :: { RdrNameHsExpr } -- used in sections
853 : qvaropm { HsVar $1 }
854 | qconop { HsVar $1 }
856 -----------------------------------------------------------------------------
859 qvarid :: { RdrName }
861 | QVARID { case $1 of { (mod,n) ->
862 mkSrcQual varName mod n } }
865 : VARID { mkSrcUnqual varName $1 }
866 | 'as' { as_var_RDR }
867 | 'qualified' { qualified_var_RDR }
868 | 'hiding' { hiding_var_RDR }
869 | 'forall' { forall_var_RDR }
870 | 'export' { export_var_RDR }
871 | 'label' { label_var_RDR }
872 | 'dynamic' { dynamic_var_RDR }
873 | 'unsafe' { unsafe_var_RDR }
875 varid_no_unsafe :: { RdrName }
876 : VARID { mkSrcUnqual varName $1 }
877 | 'as' { as_var_RDR }
878 | 'qualified' { qualified_var_RDR }
879 | 'hiding' { hiding_var_RDR }
880 | 'forall' { forall_var_RDR }
881 | 'export' { export_var_RDR }
882 | 'label' { label_var_RDR }
883 | 'dynamic' { dynamic_var_RDR }
885 -----------------------------------------------------------------------------
888 qconid :: { RdrName }
890 | QCONID { case $1 of { (mod,n) ->
891 mkSrcQual dataName mod n } }
894 : CONID { mkSrcUnqual dataName $1 }
896 -----------------------------------------------------------------------------
899 qconsym :: { RdrName }
901 | QCONSYM { case $1 of { (mod,n) ->
902 mkSrcQual dataName mod n } }
904 consym :: { RdrName }
905 : CONSYM { mkSrcUnqual dataName $1 }
907 -----------------------------------------------------------------------------
910 qvarsym :: { RdrName }
914 qvarsymm :: { RdrName }
918 varsym :: { RdrName }
919 : VARSYM { mkSrcUnqual varName $1 }
924 varsymm :: { RdrName } -- varsym not including '-'
925 : VARSYM { mkSrcUnqual varName $1 }
929 qvarsym1 :: { RdrName }
930 : QVARSYM { case $1 of { (mod,n) ->
931 mkSrcQual varName mod n } }
934 : INTEGER { HsInt $1 }
936 | RATIONAL { HsFrac $1 }
937 | STRING { HsString $1 }
939 | PRIMINTEGER { HsIntPrim $1 }
940 | PRIMCHAR { HsCharPrim $1 }
941 | PRIMSTRING { HsStringPrim $1 }
942 | PRIMFLOAT { HsFloatPrim $1 }
943 | PRIMDOUBLE { HsDoublePrim $1 }
944 | CLITLIT { HsLitLit $1 }
946 srcloc :: { SrcLoc } : {% getSrcLocP }
948 -----------------------------------------------------------------------------
952 : vccurly { () } -- context popped in lexer.
953 | error {% popContext }
955 layout_on :: { () } : {% layoutOn True{-strict-} }
956 layout_on_for_do :: { () } : {% layoutOn False }
958 -----------------------------------------------------------------------------
959 -- Miscellaneous (mostly renamings)
961 modid :: { ModuleName }
962 : CONID { mkSrcModuleFS $1 }
965 : CONID { mkSrcUnqual tcClsName $1 }
967 qtycon :: { RdrName }
969 | QCONID { case $1 of { (mod,n) ->
970 mkSrcQual tcClsName mod n } }
972 qtycls :: { RdrName }
976 : VARID { mkSrcUnqual tvName $1 }
977 | 'as' { as_tyvar_RDR }
978 | 'qualified' { qualified_tyvar_RDR }
979 | 'hiding' { hiding_tyvar_RDR }
980 | 'export' { export_var_RDR }
981 | 'label' { label_var_RDR }
982 | 'dynamic' { dynamic_var_RDR }
983 | 'unsafe' { unsafe_var_RDR }
986 -----------------------------------------------------------------------------
990 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)