2 -----------------------------------------------------------------------------
3 $Id: Parser.y,v 1.3 1999/06/02 15:50:25 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: 13 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 -----------------------------------------------------------------------------
59 '_' { ITunderscore } -- Haskell keywords
64 'default' { ITdefault }
65 'deriving' { ITderiving }
75 'instance' { ITinstance }
78 'newtype' { ITnewtype }
80 'qualified' { ITqualified }
86 'forall' { ITforall } -- GHC extension keywords
87 'foreign' { ITforeign }
90 'dynamic' { ITdynamic }
92 '_ccall_' { ITccall (False, False, False) }
93 '_ccall_GC_' { ITccall (False, False, True) }
94 '_casm_' { ITccall (False, True, False) }
95 '_casm_GC_' { ITccall (False, True, True) }
97 '{-# SPECIALISE' { ITspecialise_prag }
98 '{-# SOURCE' { ITsource_prag }
99 '{-# INLINE' { ITinline_prag }
100 '{-# NOINLINE' { ITnoinline_prag }
101 '{-# RULES' { ITrules_prag }
102 '#-}' { ITclose_prag }
105 '__interface' { ITinterface } -- interface keywords
106 '__export' { IT__export }
107 '__instimport' { ITinstimport }
108 '__forall' { IT__forall }
109 '__letrec' { ITletrec }
110 '__coerce' { ITcoerce }
111 '__depends' { ITdepends }
112 '__inline' { ITinline }
113 '__DEFAULT' { ITdefaultbranch }
115 '__integer' { ITinteger_lit }
116 '__float' { ITfloat_lit }
117 '__rational' { ITrational_lit }
118 '__addr' { ITaddr_lit }
119 '__litlit' { ITlit_lit }
120 '__string' { ITstring_lit }
121 '__ccall' { ITccall $$ }
123 '__sccC' { ITsccAllCafs }
126 '__P' { ITspecialise }
128 '__U' { ITunfold $$ }
129 '__S' { ITstrict $$ }
130 '__M' { ITcprinfo $$ }
133 '..' { ITdotdot } -- reserved symbols
147 '/\\' { ITbiglam } -- GHC-extension symbols
149 '{' { ITocurly } -- special symbols
151 vccurly { ITvccurly } -- virtual close curly (from layout)
162 VARID { ITvarid $$ } -- identifiers
164 VARSYM { ITvarsym $$ }
165 CONSYM { ITconsym $$ }
166 QVARID { ITqvarid $$ }
167 QCONID { ITqconid $$ }
168 QVARSYM { ITqvarsym $$ }
169 QCONSYM { ITqconsym $$ }
171 PRAGMA { ITpragma $$ }
174 STRING { ITstring $$ }
175 INTEGER { ITinteger $$ }
176 RATIONAL { ITrational $$ }
178 PRIMCHAR { ITprimchar $$ }
179 PRIMSTRING { ITprimstring $$ }
180 PRIMINTEGER { ITprimint $$ }
181 PRIMFLOAT { ITprimfloat $$ }
182 PRIMDOUBLE { ITprimdouble $$ }
183 CLITLIT { ITlitlit $$ }
185 UNKNOWN { ITunknown $$ }
187 %monad { P } { thenP } { returnP }
188 %lexer { lexer } { ITeof }
193 -----------------------------------------------------------------------------
196 module :: { RdrNameHsModule }
197 : srcloc 'module' modid maybeexports 'where' body
198 { HsModule $3 Nothing $4 (fst $6) (snd $6) $1 }
200 { HsModule mAIN_Name Nothing Nothing (fst $2) (snd $2) $1 }
202 body :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
204 | layout_on top close { $2 }
206 top :: { ([RdrNameImportDecl], [RdrNameHsDecl]) }
207 : importdecls ';' cvtopdecls { (reverse $1,$3) }
208 | importdecls { (reverse $1,[]) }
209 | cvtopdecls { ([],$1) }
211 cvtopdecls :: { [RdrNameHsDecl] }
212 : topdecls { cvTopDecls (groupBindings $1)}
214 -----------------------------------------------------------------------------
217 maybeexports :: { Maybe [RdrNameIE] }
218 : '(' exportlist ')' { Just $2 }
219 | {- empty -} { Nothing }
221 exportlist :: { [RdrNameIE] }
222 : exportlist ',' export { $3 : $1 }
223 | exportlist ',' { $1 }
227 -- GHC extension: we allow things like [] and (,,,) to be exported
228 export :: { RdrNameIE }
230 | gtycon { IEThingAbs $1 }
231 | gtycon '(' '..' ')' { IEThingAll $1 }
232 | gtycon '(' ')' { IEThingWith $1 [] }
233 | gtycon '(' qcnames ')' { IEThingWith $1 (reverse $3) }
234 | 'module' modid { IEModuleContents $2 }
236 qcnames :: { [RdrName] }
237 : qcnames ',' qcname { $3 : $1 }
240 qcname :: { RdrName }
244 -----------------------------------------------------------------------------
245 -- Import Declarations
247 -- import decls can be *empty*, or even just a string of semicolons
248 -- whereas topdecls must contain at least one topdecl.
250 importdecls :: { [RdrNameImportDecl] }
251 : importdecls ';' importdecl { $3 : $1 }
252 | importdecls ';' { $1 }
253 | importdecl { [ $1 ] }
256 importdecl :: { RdrNameImportDecl }
257 : 'import' srcloc maybe_src optqualified CONID maybeas maybeimpspec
258 { ImportDecl (mkSrcModuleFS $5) $3 $4 $6 $7 $2 }
260 maybe_src :: { WhereFrom }
261 : '{-# SOURCE' '#-}' { ImportByUserSource }
262 | {- empty -} { ImportByUser }
264 optqualified :: { Bool }
265 : 'qualified' { True }
266 | {- empty -} { False }
268 maybeas :: { Maybe ModuleName }
269 : 'as' modid { Just $2 }
270 | {- empty -} { Nothing }
272 maybeimpspec :: { Maybe (Bool, [RdrNameIE]) }
273 : impspec { Just $1 }
274 | {- empty -} { Nothing }
276 impspec :: { (Bool, [RdrNameIE]) }
277 : '(' exportlist ')' { (False, reverse $2) }
278 | 'hiding' '(' exportlist ')' { (True, reverse $3) }
280 -----------------------------------------------------------------------------
281 -- Fixity Declarations
285 | INTEGER {% checkPrec $1 `thenP_`
286 returnP (fromInteger $1) }
288 infix :: { FixityDirection }
290 | 'infixl' { InfixL }
291 | 'infixr' { InfixR }
294 : ops ',' op { $3 : $1 }
297 -----------------------------------------------------------------------------
298 -- Top-Level Declarations
300 topdecls :: { [RdrBinding] }
301 : topdecls ';' topdecl { ($3 : $1) }
302 | topdecls ';' { $1 }
305 topdecl :: { RdrBinding }
306 : srcloc 'type' simpletype '=' type
307 { RdrHsDecl (TyClD (TySynonym (fst $3) (snd $3) $5 $1)) }
309 | srcloc 'data' ctype '=' constrs deriving
310 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
311 returnP (RdrHsDecl (TyClD
312 (TyData DataType cs c ts (reverse $5) $6
313 NoDataPragmas $1))) }
315 | srcloc 'newtype' ctype '=' newconstr deriving
316 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
317 returnP (RdrHsDecl (TyClD
318 (TyData NewType cs c ts [$5] $6
319 NoDataPragmas $1))) }
321 | srcloc 'class' ctype where
322 {% checkDataHeader $3 `thenP` \(cs,c,ts) ->
324 = cvMonoBindsAndSigs cvClassOpSig
327 returnP (RdrHsDecl (TyClD
328 (mkClassDecl cs c ts sigs binds
329 NoClassPragmas $1))) }
331 | srcloc 'instance' inst_type where
333 = cvMonoBindsAndSigs cvInstDeclSig
336 (InstDecl $3 binds sigs dummyRdrVarName $1)) }
338 | srcloc 'default' '(' types0 ')'
339 { RdrHsDecl (DefD (DefaultDecl $4 $1)) }
341 | srcloc 'foreign' 'import' callconv ext_name
342 unsafe_flag varid_no_unsafe '::' sigtype
343 { RdrHsDecl (ForD (ForeignDecl $7 (FoImport $6) $9 $5 $4 $1)) }
345 | srcloc 'foreign' 'export' callconv ext_name varid '::' sigtype
346 { RdrHsDecl (ForD (ForeignDecl $6 FoExport $8 $5 $4 $1)) }
348 | srcloc 'foreign' 'label' ext_name varid '::' sigtype
349 { RdrHsDecl (ForD (ForeignDecl $5 FoLabel $7 $4
350 defaultCallConv $1)) }
354 decls :: { [RdrBinding] }
355 : decls ';' decl { $3 : $1 }
360 decl :: { RdrBinding }
363 | valdef { RdrValBinding $1 }
364 | '{-# INLINE' srcloc qvar '#-}' { RdrSig (InlineSig $3 $2) }
365 | '{-# NOINLINE' srcloc qvar '#-}' { RdrSig (NoInlineSig $3 $2) }
366 | '{-# SPECIALISE' srcloc qvar '::' sigtypes '#-}'
367 { foldr1 RdrAndBindings
368 (map (\t -> RdrSig (SpecSig $3 t $2)) $5) }
369 | '{-# SPECIALISE' srcloc 'instance' inst_type '#-}'
370 { RdrSig (SpecInstSig $4 $2) }
371 | '{-# RULES' rules '#-}' { $2 }
373 sigtypes :: { [RdrNameHsType] }
375 | sigtypes ',' sigtype { $3 : $1 }
377 wherebinds :: { RdrNameHsBinds }
378 : where { cvBinds cvValSig (groupBindings $1) }
380 where :: { [RdrBinding] }
381 : 'where' decllist { $2 }
384 declbinds :: { RdrNameHsBinds }
385 : decllist { cvBinds cvValSig (groupBindings $1) }
387 decllist :: { [RdrBinding] }
388 : '{' decls '}' { $2 }
389 | layout_on decls close { $2 }
391 fixdecl :: { RdrBinding }
392 : srcloc infix prec ops { foldr1 RdrAndBindings
393 [ RdrSig (FixSig (FixitySig n
397 signdecl :: { RdrBinding }
398 : vars srcloc '::' sigtype { foldr1 RdrAndBindings
399 [ RdrSig (Sig n $4 $2) | n <- $1 ] }
401 sigtype :: { RdrNameHsType }
403 HsForAllTy _ _ _ -> $1
404 other -> HsForAllTy Nothing [] $1 }
407 ATTENTION: Dirty Hackery Ahead! If the second alternative of vars is var
408 instead of qvar, we get another shift/reduce-conflict. Consider the
411 { (+) :: ... } only var
412 { (+) x y = ... } could (incorrectly) be qvar
414 We re-use expressions for patterns, so a qvar would be allowed in patterns
415 instead of a var only (which would be correct). But deciding what the + is,
416 would require more lookahead. So let's check for ourselves...
419 vars :: { [RdrName] }
420 : vars ',' var { $3 : $1 }
423 -----------------------------------------------------------------------------
424 -- Transformation Rules
426 rules :: { RdrBinding }
427 : rules ';' rule { $1 `RdrAndBindings` $3 }
430 | {- empty -} { RdrNullBind }
432 rule :: { RdrBinding }
433 : STRING rule_forall fexp '=' srcloc exp
434 { RdrHsDecl (RuleD (RuleDecl $1 [] $2 $3 $6 $5)) }
436 rule_forall :: { [RdrNameRuleBndr] }
437 : 'forall' rule_var_list '.' { $2 }
440 rule_var_list :: { [RdrNameRuleBndr] }
442 | rule_var ',' rule_var_list { $1 : $3 }
444 rule_var :: { RdrNameRuleBndr }
445 : varid { RuleBndr $1 }
446 | varid '::' ctype { RuleBndrSig $1 $3 }
448 -----------------------------------------------------------------------------
449 -- Foreign import/export
452 : VARID {% checkCallConv $1 }
453 | {- empty -} { defaultCallConv }
455 unsafe_flag :: { Bool }
457 | {- empty -} { False }
459 ext_name :: { ExtName }
460 : 'dynamic' { Dynamic }
461 | STRING { ExtName $1 Nothing }
462 | STRING STRING { ExtName $2 (Just $1) }
464 -----------------------------------------------------------------------------
467 {- ToDo: forall stuff -}
469 type :: { RdrNameHsType }
470 : btype '->' type { MonoFunTy $1 $3 }
473 btype :: { RdrNameHsType }
474 : btype atype { MonoTyApp $1 $2 }
477 atype :: { RdrNameHsType }
478 : gtycon { MonoTyVar $1 }
479 | tyvar { MonoTyVar $1 }
480 | '(' type ',' types ')' { MonoTupleTy ($2 : reverse $4) True }
481 | '(#' types '#)' { MonoTupleTy (reverse $2) False }
482 | '[' type ']' { MonoListTy $2 }
483 | '(' ctype ')' { $2 }
485 gtycon :: { RdrName }
487 | '(' ')' { unitTyCon_RDR }
488 | '(' '->' ')' { funTyCon_RDR }
489 | '[' ']' { listTyCon_RDR }
490 | '(' commas ')' { tupleTyCon_RDR $2 }
492 -- An inst_type is what occurs in the head of an instance decl
493 -- e.g. (Foo a, Gaz b) => Wibble a b
494 -- It's kept as a single type, with a MonoDictTy at the right
495 -- hand corner, for convenience.
496 inst_type :: { RdrNameHsType }
497 : ctype {% checkInstType $1 }
499 ctype :: { RdrNameHsType }
500 : 'forall' tyvars '.' btype '=>' type
501 {% checkContext $4 `thenP` \c ->
502 returnP (HsForAllTy (Just $2) c $6) }
503 | 'forall' tyvars '.' type { HsForAllTy (Just $2) [] $4 }
504 | btype '=>' type {% checkContext $1 `thenP` \c ->
505 returnP (HsForAllTy Nothing c $3) }
508 types0 :: { [RdrNameHsType] }
512 types :: { [RdrNameHsType] }
514 | types ',' type { $3 : $1 }
516 simpletype :: { (RdrName, [RdrNameHsTyVar]) }
517 : tycon tyvars { ($1, reverse $2) }
519 tyvars :: { [RdrNameHsTyVar] }
520 : tyvars tyvar { UserTyVar $2 : $1 }
523 -----------------------------------------------------------------------------
524 -- Datatype declarations
526 constrs :: { [RdrNameConDecl] }
527 : constrs '|' constr { $3 : $1 }
530 {- ToDo: existential stuff -}
532 constr :: { RdrNameConDecl }
534 { ConDecl (fst $2) [] [] (VanillaCon (snd $2)) $1 }
535 | srcloc sbtype conop sbtype
536 { ConDecl $3 [] [] (InfixCon $2 $4) $1 }
537 | srcloc con '{' fielddecls '}'
538 { ConDecl $2 [] [] (RecCon (reverse $4)) $1 }
540 newconstr :: { RdrNameConDecl }
541 : srcloc conid atype { ConDecl $2 [] [] (NewCon $3 Nothing) $1 }
542 | srcloc conid '{' var '::' type '}'
543 { ConDecl $2 [] [] (NewCon $6 (Just $4)) $1 }
545 scontype :: { (RdrName, [RdrNameBangType]) }
546 : btype {% splitForConApp $1 [] }
549 scontype1 :: { (RdrName, [RdrNameBangType]) }
550 : btype '!' atype {% splitForConApp $1 [Banged $3] }
551 | scontype1 satype { (fst $1, snd $1 ++ [$2] ) }
553 satype :: { RdrNameBangType }
554 : atype { Unbanged $1 }
555 | '!' atype { Banged $2 }
557 sbtype :: { RdrNameBangType }
558 : btype { Unbanged $1 }
559 | '!' atype { Banged $2 }
561 fielddecls :: { [([RdrName],RdrNameBangType)] }
562 : fielddecls ',' fielddecl { $3 : $1 }
565 fielddecl :: { ([RdrName],RdrNameBangType) }
566 : vars '::' stype { (reverse $1, $3) }
568 stype :: { RdrNameBangType }
569 : type { Unbanged $1 }
570 | '!' atype { Banged $2 }
572 deriving :: { Maybe [RdrName] }
573 : {- empty -} { Nothing }
574 | 'deriving' qtycls { Just [$2] }
575 | 'deriving' '(' ')' { Just [] }
576 | 'deriving' '(' dclasses ')' { Just (reverse $3) }
578 dclasses :: { [RdrName] }
579 : dclasses ',' qtycls { $3 : $1 }
582 -----------------------------------------------------------------------------
585 valdef :: { RdrNameMonoBinds }
586 : infixexp {-ToDo: opt_sig-} srcloc rhs
587 {% checkValDef $1 Nothing $3 $2 }
589 rhs :: { RdrNameGRHSs }
590 : '=' srcloc exp wherebinds { GRHSs (unguardedRHS $3 $2)
592 | gdrhs wherebinds { GRHSs (reverse $1) $2 Nothing }
594 gdrhs :: { [RdrNameGRHS] }
595 : gdrhs gdrh { $2 : $1 }
598 gdrh :: { RdrNameGRHS }
599 : '|' srcloc quals '=' exp { GRHS (reverse
600 (ExprStmt $5 $2 : $3)) $2 }
602 -----------------------------------------------------------------------------
605 exp :: { RdrNameHsExpr }
606 : infixexp '::' sigtype { ExprWithTySig $1 $3 }
609 infixexp :: { RdrNameHsExpr }
611 | infixexp qop exp10 { OpApp $1 $2 (panic "fixity") $3 }
613 exp10 :: { RdrNameHsExpr }
614 : '\\' aexp aexps opt_asig '->' srcloc exp
615 {% checkPatterns ($2 : reverse $3) `thenP` \ ps ->
616 returnP (HsLam (Match [] ps $4
617 (GRHSs (unguardedRHS $7 $6)
618 EmptyBinds Nothing))) }
619 | 'let' declbinds 'in' exp { HsLet $2 $4 }
620 | 'if' srcloc exp 'then' exp 'else' exp { HsIf $3 $5 $7 $2 }
621 | 'case' srcloc exp 'of' altslist { HsCase $3 $5 $2 }
622 | '-' fexp { NegApp $2 (error "NegApp") }
623 | srcloc 'do' stmtlist { HsDo DoStmt $3 $1 }
625 | '_ccall_' ccallid aexps0 { CCall $2 $3 False False cbot }
626 | '_ccall_GC_' ccallid aexps0 { CCall $2 $3 True False cbot }
627 | '_casm_' CLITLIT aexps0 { CCall $2 $3 False True cbot }
628 | '_casm_GC_' CLITLIT aexps0 { CCall $2 $3 True True cbot }
630 | '_scc_' STRING exp { if opt_SccProfilingOn
636 ccallid :: { FAST_STRING }
640 fexp :: { RdrNameHsExpr }
641 : fexp aexp { HsApp $1 $2 }
644 aexps0 :: { [RdrNameHsExpr] }
645 : aexps { reverse $1 }
647 aexps :: { [RdrNameHsExpr] }
648 : aexps aexp { $2 : $1 }
651 aexp :: { RdrNameHsExpr }
652 : aexp '{' fbinds '}' {% mkRecConstrOrUpdate $1 (reverse $3) }
655 aexp1 :: { RdrNameHsExpr }
658 | literal { HsLit $1 }
659 | '(' exp ')' { HsPar $2 }
660 | '(' exp ',' texps ')' { ExplicitTuple ($2 : reverse $4) True }
661 | '(#' texps '#)' { ExplicitTuple (reverse $2) False }
662 | '[' list ']' { $2 }
663 | '(' infixexp qop ')' { SectionL $2 $3 }
664 | '(' qopm infixexp ')' { SectionR $2 $3 }
665 | qvar '@' aexp1 { EAsPat $1 $3 }
667 | '~' aexp1 { ELazyPat $2 }
670 : commas ',' { $1 + 1 }
673 texps :: { [RdrNameHsExpr] }
674 : texps ',' exp { $3 : $1 }
677 -----------------------------------------------------------------------------
680 -- The rules below are little bit contorted to keep lexps left-recursive while
681 -- avoiding another shift/reduce-conflict.
683 list :: { RdrNameHsExpr }
684 : exp { ExplicitList [$1] }
685 | lexps { ExplicitList (reverse $1) }
686 | exp '..' { ArithSeqIn (From $1) }
687 | exp ',' exp '..' { ArithSeqIn (FromThen $1 $3) }
688 | exp '..' exp { ArithSeqIn (FromTo $1 $3) }
689 | exp ',' exp '..' exp { ArithSeqIn (FromThenTo $1 $3 $5) }
690 | exp srcloc '|' quals { HsDo ListComp (reverse
691 (ReturnStmt $1 : $4)) $2 }
693 lexps :: { [RdrNameHsExpr] }
694 : lexps ',' exp { $3 : $1 }
695 | exp ',' exp { [$3,$1] }
697 -----------------------------------------------------------------------------
698 -- List Comprehensions
700 quals :: { [RdrNameStmt] }
701 : quals ',' qual { $3 : $1 }
704 qual :: { RdrNameStmt }
705 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
706 returnP (BindStmt p $4 $1) }
707 | srcloc exp { GuardStmt $2 $1 }
708 | srcloc 'let' declbinds { LetStmt $3 }
710 -----------------------------------------------------------------------------
713 altslist :: { [RdrNameMatch] }
714 : '{' alts '}' { reverse $2 }
715 | layout_on alts close { reverse $2 }
718 alts :: { [RdrNameMatch] }
719 : alts ';' alt { $3 : $1 }
724 alt :: { RdrNameMatch }
725 : infixexp opt_sig ralt wherebinds
726 {% checkPattern $1 `thenP` \p ->
727 returnP (Match [] [p] $2
728 (GRHSs $3 $4 Nothing)) }
730 opt_sig :: { Maybe RdrNameHsType }
731 : {- empty -} { Nothing }
732 | '::' type { Just $2 }
734 opt_asig :: { Maybe RdrNameHsType }
735 : {- empty -} { Nothing }
736 | '::' atype { Just $2 }
738 ralt :: { [RdrNameGRHS] }
739 : '->' srcloc exp { [GRHS [ExprStmt $3 $2] $2] }
740 | gdpats { (reverse $1) }
742 gdpats :: { [RdrNameGRHS] }
743 : gdpats gdpat { $2 : $1 }
746 gdpat :: { RdrNameGRHS }
747 : srcloc '|' quals '->' exp { GRHS (reverse (ExprStmt $5 $1:$3)) $1}
749 -----------------------------------------------------------------------------
750 -- Statement sequences
752 stmtlist :: { [RdrNameStmt] }
753 : '{' stmts '}' { reverse $2 }
754 | layout_on stmts close { reverse $2 }
756 stmts :: { [RdrNameStmt] }
757 : stmts ';' stmt { $3 : $1 }
762 stmt :: { RdrNameStmt }
763 : srcloc infixexp '<-' exp {% checkPattern $2 `thenP` \p ->
764 returnP (BindStmt p $4 $1) }
765 | srcloc exp { ExprStmt $2 $1 }
766 | srcloc 'let' declbinds { LetStmt $3 }
768 -----------------------------------------------------------------------------
769 -- Record Field Update/Construction
771 fbinds :: { RdrNameHsRecordBinds }
772 : fbinds ',' fbind { $3 : $1 }
777 fbind :: { (RdrName, RdrNameHsExpr, Bool) }
778 : qvar '=' exp { ($1,$3,False) }
780 -----------------------------------------------------------------------------
781 -- Variables, Constructors and Operators.
784 : '(' ')' { unitCon_RDR }
785 | '[' ']' { nilCon_RDR }
786 | '(' commas ')' { tupleCon_RDR $2 }
791 | '(' varsym ')' { $2 }
795 | '(' qvarsym ')' { $2 }
799 | '(' consym ')' { $2 }
803 | '(' qconsym ')' { $2 }
807 | '`' varid '`' { $2 }
809 qvarop :: { RdrName }
811 | '`' qvarid '`' { $2 }
813 qvaropm :: { RdrName }
815 | '`' qvarid '`' { $2 }
819 | '`' conid '`' { $2 }
821 qconop :: { RdrName }
823 | '`' qconid '`' { $2 }
825 -----------------------------------------------------------------------------
828 op :: { RdrName } -- used in infix decls
832 qop :: { RdrNameHsExpr } -- used in sections
833 : qvarop { HsVar $1 }
834 | qconop { HsVar $1 }
836 qopm :: { RdrNameHsExpr } -- used in sections
837 : qvaropm { HsVar $1 }
838 | qconop { HsVar $1 }
840 -----------------------------------------------------------------------------
843 qvarid :: { RdrName }
845 | QVARID { case $1 of { (mod,n) ->
846 mkSrcQual varName mod n } }
849 : VARID { mkSrcUnqual varName $1 }
850 | 'as' { as_var_RDR }
851 | 'qualified' { qualified_var_RDR }
852 | 'hiding' { hiding_var_RDR }
853 | 'forall' { forall_var_RDR }
854 | 'export' { export_var_RDR }
855 | 'label' { label_var_RDR }
856 | 'dynamic' { dynamic_var_RDR }
857 | 'unsafe' { unsafe_var_RDR }
859 varid_no_unsafe :: { RdrName }
860 : VARID { mkSrcUnqual varName $1 }
861 | 'as' { as_var_RDR }
862 | 'qualified' { qualified_var_RDR }
863 | 'hiding' { hiding_var_RDR }
864 | 'forall' { forall_var_RDR }
865 | 'export' { export_var_RDR }
866 | 'label' { label_var_RDR }
867 | 'dynamic' { dynamic_var_RDR }
869 -----------------------------------------------------------------------------
872 qconid :: { RdrName }
874 | QCONID { case $1 of { (mod,n) ->
875 mkSrcQual dataName mod n } }
878 : CONID { mkSrcUnqual dataName $1 }
880 -----------------------------------------------------------------------------
883 qconsym :: { RdrName }
885 | QCONSYM { case $1 of { (mod,n) ->
886 mkSrcQual dataName mod n } }
888 consym :: { RdrName }
889 : CONSYM { mkSrcUnqual dataName $1 }
891 -----------------------------------------------------------------------------
894 qvarsym :: { RdrName }
898 qvarsymm :: { RdrName }
902 varsym :: { RdrName }
903 : VARSYM { mkSrcUnqual varName $1 }
908 varsymm :: { RdrName } -- varsym not including '-'
909 : VARSYM { mkSrcUnqual varName $1 }
913 qvarsym1 :: { RdrName }
914 : QVARSYM { case $1 of { (mod,n) ->
915 mkSrcQual varName mod n } }
918 : INTEGER { HsInt $1 }
920 | RATIONAL { HsFrac $1 }
921 | STRING { HsString $1 }
923 | PRIMINTEGER { HsIntPrim $1 }
924 | PRIMCHAR { HsCharPrim $1 }
925 | PRIMSTRING { HsStringPrim $1 }
926 | PRIMFLOAT { HsFloatPrim $1 }
927 | PRIMDOUBLE { HsDoublePrim $1 }
928 | CLITLIT { HsLitLit $1 }
930 srcloc :: { SrcLoc } : {% getSrcLocP }
932 -----------------------------------------------------------------------------
936 : vccurly { () } -- context popped in lexer.
937 | error {% popContext }
939 layout_on :: { () } : {% layoutOn }
941 -----------------------------------------------------------------------------
942 -- Miscellaneous (mostly renamings)
944 modid :: { ModuleName }
945 : CONID { mkSrcModuleFS $1 }
948 : CONID { mkSrcUnqual tcClsName $1 }
950 qtycon :: { RdrName }
952 | QCONID { case $1 of { (mod,n) ->
953 mkSrcQual tcClsName mod n } }
955 qtycls :: { RdrName }
959 : VARID { mkSrcUnqual tvName $1 }
960 | 'as' { as_tyvar_RDR }
961 | 'qualified' { qualified_tyvar_RDR }
962 | 'hiding' { hiding_tyvar_RDR }
963 | 'export' { export_var_RDR }
964 | 'label' { label_var_RDR }
965 | 'dynamic' { dynamic_var_RDR }
966 | 'unsafe' { unsafe_var_RDR }
969 -----------------------------------------------------------------------------
973 happyError buf PState{ loc = loc } = PFailed (srcParseErr buf loc)