2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.12 1999/07/27 07:31:18 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 }
406 : ctype { mkHsForAllTy Nothing [] $1 }
409 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
410 instead of qvar, we get another shift/reduce-conflict. Consider the
413 { (+) :: ... } only var
414 { (+) x y = ... } could (incorrectly) be qvar
416 We re-use expressions for patterns, so a qvar would be allowed in patterns
417 instead of a var only (which would be correct). But deciding what the + is,
418 would require more lookahead. So let's check for ourselves...
421 vars :: { [RdrName] }
422 : vars ',' var { $3 : $1 }
425 -----------------------------------------------------------------------------
426 -- Transformation Rules
428 rules :: { RdrBinding }
429 : rules ';' rule { $1 `RdrAndBindings` $3 }
432 | {- empty -} { RdrNullBind }
434 rule :: { RdrBinding }
435 : STRING rule_forall fexp '=' srcloc exp
436 { RdrHsDecl (RuleD (RuleDecl $1 [] $2 $3 $6 $5)) }
438 rule_forall :: { [RdrNameRuleBndr] }
439 : 'forall' rule_var_list '.' { $2 }
442 rule_var_list :: { [RdrNameRuleBndr] }
444 | rule_var ',' rule_var_list { $1 : $3 }
446 rule_var :: { RdrNameRuleBndr }
447 : varid { RuleBndr $1 }
448 | varid '::' ctype { RuleBndrSig $1 $3 }
450 -----------------------------------------------------------------------------
451 -- Foreign import/export
454 : VARID {% checkCallConv $1 }
455 | {- empty -} { defaultCallConv }
457 unsafe_flag :: { Bool }
459 | {- empty -} { False }
461 ext_name :: { ExtName }
462 : 'dynamic' { Dynamic }
463 | STRING { ExtName $1 Nothing }
464 | STRING STRING { ExtName $2 (Just $1) }
466 -----------------------------------------------------------------------------
469 {- ToDo: forall stuff -}
471 type :: { RdrNameHsType }
472 : btype '->' type { MonoFunTy $1 $3 }
475 btype :: { RdrNameHsType }
476 : btype atype { MonoTyApp $1 $2 }
479 atype :: { RdrNameHsType }
480 : gtycon { MonoTyVar $1 }
481 | tyvar { MonoTyVar $1 }
482 | '(' type ',' types ')' { MonoTupleTy ($2 : reverse $4) True }
483 | '(#' types '#)' { MonoTupleTy (reverse $2) False }
484 | '[' type ']' { MonoListTy $2 }
485 | '(' ctype ')' { $2 }
487 gtycon :: { RdrName }
489 | '(' ')' { unitTyCon_RDR }
490 | '(' '->' ')' { funTyCon_RDR }
491 | '[' ']' { listTyCon_RDR }
492 | '(' commas ')' { tupleTyCon_RDR $2 }
494 -- An inst_type is what occurs in the head of an instance decl
495 -- e.g. (Foo a, Gaz b) => Wibble a b
496 -- It's kept as a single type, with a MonoDictTy at the right
497 -- hand corner, for convenience.
498 inst_type :: { RdrNameHsType }
499 : ctype {% checkInstType $1 }
501 ctype :: { RdrNameHsType }
502 : 'forall' tyvars '.' context type
503 { mkHsForAllTy (Just $2) $4 $5 }
504 | 'forall' tyvars '.' type { mkHsForAllTy (Just $2) [] $4 }
505 | context type { mkHsForAllTy Nothing $1 $2 }
506 -- A type of form (context => type) is an *implicit* HsForAllTy
509 types0 :: { [RdrNameHsType] }
513 types :: { [RdrNameHsType] }
515 | types ',' type { $3 : $1 }
517 simpletype :: { (RdrName, [RdrNameHsTyVar]) }
518 : tycon tyvars { ($1, reverse $2) }
520 tyvars :: { [RdrNameHsTyVar] }
521 : tyvars tyvar { UserTyVar $2 : $1 }
524 -----------------------------------------------------------------------------
525 -- Datatype declarations
527 constrs :: { [RdrNameConDecl] }
528 : constrs '|' constr { $3 : $1 }
531 constr :: { RdrNameConDecl }
532 : srcloc forall context constr_stuff
533 { ConDecl (fst $4) $2 $3 (snd $4) $1 }
534 | srcloc forall constr_stuff
535 { ConDecl (fst $3) $2 [] (snd $3) $1 }
537 forall :: { [RdrNameHsTyVar] }
538 : 'forall' tyvars '.' { $2 }
541 context :: { RdrNameContext }
542 : btype '=>' {% checkContext $1 }
544 constr_stuff :: { (RdrName, RdrNameConDetails) }
545 : scontype { (fst $1, VanillaCon (snd $1)) }
546 | sbtype conop sbtype { ($2, InfixCon $1 $3) }
547 | con '{' fielddecls '}' { ($1, RecCon (reverse $3)) }
549 newconstr :: { RdrNameConDecl }
550 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
551 | srcloc conid '{' var '::' type '}'
552 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
554 scontype :: { (RdrName, [RdrNameBangType]) }
555 : btype {% splitForConApp $1 [] }
558 scontype1 :: { (RdrName, [RdrNameBangType]) }
559 : btype '!' atype {% splitForConApp $1 [Banged $3] }
560 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
562 satype :: { RdrNameBangType }
563 : atype { Unbanged $1 }
564 | '!' atype { Banged $2 }
566 sbtype :: { RdrNameBangType }
567 : btype { Unbanged $1 }
568 | '!' atype { Banged $2 }
570 fielddecls :: { [([RdrName],RdrNameBangType)] }
571 : fielddecls ',' fielddecl { $3 : $1 }
574 fielddecl :: { ([RdrName],RdrNameBangType) }
575 : vars '::' stype { (reverse $1, $3) }
577 stype :: { RdrNameBangType }
578 : type { Unbanged $1 }
579 | '!' atype { Banged $2 }
581 deriving :: { Maybe [RdrName] }
582 : {- empty -} { Nothing }
583 | 'deriving' qtycls { Just [$2] }
584 | 'deriving' '(' ')' { Just [] }
585 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
587 dclasses :: { [RdrName] }
588 : dclasses ',' qtycls { $3 : $1 }
591 -----------------------------------------------------------------------------
594 valdef :: { RdrNameMonoBinds }
595 : infixexp {-ToDo: opt_sig-} srcloc rhs
596 {% checkValDef $1 Nothing $3 $2 }
598 rhs :: { RdrNameGRHSs }
599 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
601 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
603 gdrhs :: { [RdrNameGRHS] }
604 : gdrhs gdrh { $2 : $1 }
607 gdrh :: { RdrNameGRHS }
608 : '|' srcloc quals '=' exp { GRHS (reverse
609 (ExprStmt $5 $2 : $3)) $2 }
611 -----------------------------------------------------------------------------
614 exp :: { RdrNameHsExpr }
615 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
618 infixexp :: { RdrNameHsExpr }
620 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
622 exp10 :: { RdrNameHsExpr }
623 : '\\' aexp aexps opt_asig '->' srcloc exp
624 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
625 returnP (HsLam (Match [] ps $4
626 (GRHSs (unguardedRHS $7 $6)
627 EmptyBinds Nothing))) }
628 | 'let' declbinds 'in' exp { HsLet $2 $4 }
629 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
630 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
631 | '-' fexp { NegApp $2 (error "NegApp") }
632 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
634 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
635 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
636 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
637 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
639 | '_scc_' STRING exp { if opt_SccProfilingOn
645 ccallid :: { FAST_STRING }
649 fexp :: { RdrNameHsExpr }
650 : fexp aexp { HsApp $1 $2 }
653 aexps0 :: { [RdrNameHsExpr] }
654 : aexps { reverse $1 }
656 aexps :: { [RdrNameHsExpr] }
657 : aexps aexp { $2 : $1 }
660 aexp :: { RdrNameHsExpr }
661 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
664 aexp1 :: { RdrNameHsExpr }
667 | literal { HsLit $1 }
668 | '(' exp ')' { HsPar $2 }
669 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
670 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
671 | '[' list ']' { $2 }
672 | '(' infixexp qop ')' { SectionL $2 $3 }
673 | '(' qopm infixexp ')' { SectionR $2 $3 }
674 | qvar '@' aexp { EAsPat $1 $3 }
676 | '~' aexp1 { ELazyPat $2 }
679 : commas ',' { $1 + 1 }
682 texps :: { [RdrNameHsExpr] }
683 : texps ',' exp { $3 : $1 }
686 -----------------------------------------------------------------------------
689 -- The rules below are little bit contorted to keep lexps left-recursive while
690 -- avoiding another shift/reduce-conflict.
692 list :: { RdrNameHsExpr }
693 : exp { ExplicitList [$1] }
694 | lexps { ExplicitList (reverse $1) }
695 | exp '..' { ArithSeqIn (From $1) }
696 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
697 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
698 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
699 | exp srcloc '|' quals { HsDo ListComp (reverse
700 (ReturnStmt $1 : $4)) $2 }
702 lexps :: { [RdrNameHsExpr] }
703 : lexps ',' exp { $3 : $1 }
704 | exp ',' exp { [$3,$1] }
706 -----------------------------------------------------------------------------
707 -- List Comprehensions
709 quals :: { [RdrNameStmt] }
710 : quals ',' qual { $3 : $1 }
713 qual :: { RdrNameStmt }
714 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
715 returnP (BindStmt p $4 $1) }
716 | srcloc exp { GuardStmt $2 $1 }
717 | srcloc 'let' declbinds { LetStmt $3 }
719 -----------------------------------------------------------------------------
722 altslist :: { [RdrNameMatch] }
723 : '{' alts '}' { reverse $2 }
724 | layout_on alts close { reverse $2 }
727 alts :: { [RdrNameMatch] }
728 : alts ';' alt { $3 : $1 }
733 alt :: { RdrNameMatch }
734 : infixexp opt_sig ralt wherebinds
735 {% checkPattern $1 `thenP` \p ->
736 returnP (Match [] [p] $2
737 (GRHSs $3 $4 Nothing)) }
739 opt_sig :: { Maybe RdrNameHsType }
740 : {- empty -} { Nothing }
741 | '::' type { Just $2 }
743 opt_asig :: { Maybe RdrNameHsType }
744 : {- empty -} { Nothing }
745 | '::' atype { Just $2 }
747 ralt :: { [RdrNameGRHS] }
748 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
749 | gdpats { (reverse $1) }
751 gdpats :: { [RdrNameGRHS] }
752 : gdpats gdpat { $2 : $1 }
755 gdpat :: { RdrNameGRHS }
756 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
758 -----------------------------------------------------------------------------
759 -- Statement sequences
761 stmtlist :: { [RdrNameStmt] }
762 : '{' stmts '}' { $2 }
763 | layout_on_for_do stmts close { $2 }
765 -- Stmt list must end in an expression
766 -- thought the H98 report doesn't currently say so in the syntax
767 stmts :: { [RdrNameStmt] }
768 : stmts1 srcloc exp { reverse (ExprStmt $3 $2 : $1) }
770 -- A list of zero or more stmts, ending in semicolon
771 -- Returned in *reverse* order
772 stmts1 :: { [RdrNameStmt] }
773 : stmts1 stmt ';' { $2 : $1 }
777 stmt :: { RdrNameStmt }
778 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
779 returnP (BindStmt p $4 $1) }
780 | srcloc exp { ExprStmt $2 $1 }
781 | srcloc 'let' declbinds { LetStmt $3 }
783 -----------------------------------------------------------------------------
784 -- Record Field Update/Construction
786 fbinds :: { RdrNameHsRecordBinds }
787 : fbinds ',' fbind { $3 : $1 }
792 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
793 : qvar '=' exp { ($1,$3,False) }
795 -----------------------------------------------------------------------------
796 -- Variables, Constructors and Operators.
799 : '(' ')' { unitCon_RDR }
800 | '[' ']' { nilCon_RDR }
801 | '(' commas ')' { tupleCon_RDR $2 }
806 | '(' varsym ')' { $2 }
810 | '(' qvarsym ')' { $2 }
814 | '(' consym ')' { $2 }
818 | '(' qconsym ')' { $2 }
822 | '`' varid '`' { $2 }
824 qvarop :: { RdrName }
826 | '`' qvarid '`' { $2 }
828 qvaropm :: { RdrName }
830 | '`' qvarid '`' { $2 }
834 | '`' conid '`' { $2 }
836 qconop :: { RdrName }
838 | '`' qconid '`' { $2 }
840 -----------------------------------------------------------------------------
843 op :: { RdrName } -- used in infix decls
847 qop :: { RdrNameHsExpr } -- used in sections
848 : qvarop { HsVar $1 }
849 | qconop { HsVar $1 }
851 qopm :: { RdrNameHsExpr } -- used in sections
852 : qvaropm { HsVar $1 }
853 | qconop { HsVar $1 }
855 -----------------------------------------------------------------------------
858 qvarid :: { RdrName }
860 | QVARID { case $1 of { (mod,n) ->
861 mkSrcQual varName mod n } }
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 }
872 | 'unsafe' { unsafe_var_RDR }
874 varid_no_unsafe :: { RdrName }
875 : VARID { mkSrcUnqual varName $1 }
876 | 'as' { as_var_RDR }
877 | 'qualified' { qualified_var_RDR }
878 | 'hiding' { hiding_var_RDR }
879 | 'forall' { forall_var_RDR }
880 | 'export' { export_var_RDR }
881 | 'label' { label_var_RDR }
882 | 'dynamic' { dynamic_var_RDR }
884 -----------------------------------------------------------------------------
887 qconid :: { RdrName }
889 | QCONID { case $1 of { (mod,n) ->
890 mkSrcQual dataName mod n } }
893 : CONID { mkSrcUnqual dataName $1 }
895 -----------------------------------------------------------------------------
898 qconsym :: { RdrName }
900 | QCONSYM { case $1 of { (mod,n) ->
901 mkSrcQual dataName mod n } }
903 consym :: { RdrName }
904 : CONSYM { mkSrcUnqual dataName $1 }
906 -----------------------------------------------------------------------------
909 qvarsym :: { RdrName }
913 qvarsymm :: { RdrName }
917 varsym :: { RdrName }
918 : VARSYM { mkSrcUnqual varName $1 }
923 varsymm :: { RdrName } -- varsym not including '-'
924 : VARSYM { mkSrcUnqual varName $1 }
928 qvarsym1 :: { RdrName }
929 : QVARSYM { case $1 of { (mod,n) ->
930 mkSrcQual varName mod n } }
933 : INTEGER { HsInt $1 }
935 | RATIONAL { HsFrac $1 }
936 | STRING { HsString $1 }
938 | PRIMINTEGER { HsIntPrim $1 }
939 | PRIMCHAR { HsCharPrim $1 }
940 | PRIMSTRING { HsStringPrim $1 }
941 | PRIMFLOAT { HsFloatPrim $1 }
942 | PRIMDOUBLE { HsDoublePrim $1 }
943 | CLITLIT { HsLitLit $1 }
945 srcloc :: { SrcLoc } : {% getSrcLocP }
947 -----------------------------------------------------------------------------
951 : vccurly { () } -- context popped in lexer.
952 | error {% popContext }
954 layout_on :: { () } : {% layoutOn True{-strict-} }
955 layout_on_for_do :: { () } : {% layoutOn False }
957 -----------------------------------------------------------------------------
958 -- Miscellaneous (mostly renamings)
960 modid :: { ModuleName }
961 : CONID { mkSrcModuleFS $1 }
964 : CONID { mkSrcUnqual tcClsName $1 }
966 qtycon :: { RdrName }
968 | QCONID { case $1 of { (mod,n) ->
969 mkSrcQual tcClsName mod n } }
971 qtycls :: { RdrName }
975 : VARID { mkSrcUnqual tvName $1 }
976 | 'as' { as_tyvar_RDR }
977 | 'qualified' { qualified_tyvar_RDR }
978 | 'hiding' { hiding_tyvar_RDR }
979 | 'export' { export_var_RDR }
980 | 'label' { label_var_RDR }
981 | 'dynamic' { dynamic_var_RDR }
982 | 'unsafe' { unsafe_var_RDR }
985 -----------------------------------------------------------------------------
989 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)