DOCPREV { L _ (ITdocCommentPrev _) }
DOCNAMED { L _ (ITdocCommentNamed _) }
DOCSECTION { L _ (ITdocSection _ _) }
- DOCOPTIONS { L _ (ITdocOptions _) }
-- Template Haskell
'[|' { L _ ITopenExpQuote }
-- know what they are doing. :-)
module :: { Located (HsModule RdrName) }
- : optdoc 'module' modid maybemoddeprec maybeexports 'where' body
- {% fileSrcSpan >>= \ loc -> case $1 of { (opt, info, doc) ->
- return (L loc (HsModule (Just $3) $5 (fst $7) (snd $7) $4
- opt info doc) )}}
+ : maybedocheader 'module' modid maybemoddeprec maybeexports 'where' body
+ {% fileSrcSpan >>= \ loc -> case $1 of { (info, doc) ->
+ return (L loc (HsModule (Just $3) $5 (fst $7) (snd $7) $4
+ info doc) )}}
| body2
{% fileSrcSpan >>= \ loc ->
- return (L loc (HsModule Nothing Nothing
- (fst $1) (snd $1) Nothing Nothing emptyHaddockModInfo
+ return (L loc (HsModule Nothing Nothing
+ (fst $1) (snd $1) Nothing emptyHaddockModInfo
Nothing)) }
-optdoc :: { (Maybe String, HaddockModInfo RdrName, Maybe (HsDoc RdrName)) }
- : moduleheader { (Nothing, fst $1, snd $1) }
- | docoptions { (Just $1, emptyHaddockModInfo, Nothing)}
- | docoptions moduleheader { (Just $1, fst $2, snd $2) }
- | moduleheader docoptions { (Just $2, fst $1, snd $1) }
- | {- empty -} { (Nothing, emptyHaddockModInfo, Nothing) }
+maybedocheader :: { (HaddockModInfo RdrName, Maybe (HsDoc RdrName)) }
+ : moduleheader { (fst $1, snd $1) }
+ | {- empty -} { (emptyHaddockModInfo, Nothing) }
missing_module_keyword :: { () }
: {- empty -} {% pushCurrentContext }
-- Module declaration & imports only
header :: { Located (HsModule RdrName) }
- : optdoc 'module' modid maybemoddeprec maybeexports 'where' header_body
- {% fileSrcSpan >>= \ loc -> case $1 of { (opt, info, doc) ->
- return (L loc (HsModule (Just $3) $5 $7 [] $4
- opt info doc))}}
+ : maybedocheader 'module' modid maybemoddeprec maybeexports 'where' header_body
+ {% fileSrcSpan >>= \ loc -> case $1 of { (info, doc) ->
+ return (L loc (HsModule (Just $3) $5 $7 [] $4
+ info doc))}}
| missing_module_keyword importdecls
{% fileSrcSpan >>= \ loc ->
- return (L loc (HsModule Nothing Nothing $2 [] Nothing
- Nothing emptyHaddockModInfo Nothing)) }
+ return (L loc (HsModule Nothing Nothing $2 [] Nothing
+ emptyHaddockModInfo Nothing)) }
header_body :: { [LImportDecl RdrName] }
: '{' importdecls { $2 }
aexp :: { LHsExpr RdrName }
: qvar '@' aexp { LL $ EAsPat $1 $3 }
| '~' aexp { LL $ ELazyPat $2 }
- | aexp1 { $1 }
+ | aexp1 { $1 }
aexp1 :: { LHsExpr RdrName }
: aexp1 '{' fbinds '}' {% do { r <- mkRecConstrOrUpdate $1 (comb2 $2 $4) $3
| literal { L1 (HsLit $! unLoc $1) }
-- This will enable overloaded strings permanently. Normally the renamer turns HsString
-- into HsOverLit when -foverloaded-strings is on.
--- | STRING { L1 (HsOverLit $! mkHsIsString (getSTRING $1)) }
- | INTEGER { L1 (HsOverLit $! mkHsIntegral (getINTEGER $1)) }
- | RATIONAL { L1 (HsOverLit $! mkHsFractional (getRATIONAL $1)) }
- | '(' exp ')' { LL (HsPar $2) }
+-- | STRING { sL (getLoc $1) (HsOverLit $! mkHsIsString (getSTRING $1) placeHolderType) }
+ | INTEGER { sL (getLoc $1) (HsOverLit $! mkHsIntegral (getINTEGER $1) placeHolderType) }
+ | RATIONAL { sL (getLoc $1) (HsOverLit $! mkHsFractional (getRATIONAL $1) placeHolderType) }
+ -- N.B.: sections get parsed by these next two productions.
+ -- This allows you to write, e.g., '(+ 3, 4 -)', which isn't correct Haskell98
+ -- (you'd have to write '((+ 3), (4 -))')
+ -- but the less cluttered version fell out of having texps.
+ | '(' texp ')' { LL (HsPar $2) }
| '(' texp ',' texps ')' { LL $ ExplicitTuple ($2 : reverse $4) Boxed }
| '(#' texps '#)' { LL $ ExplicitTuple (reverse $2) Unboxed }
| '[' list ']' { LL (unLoc $2) }
| '[:' parr ':]' { LL (unLoc $2) }
- | '(' infixexp qop ')' { LL $ SectionL $2 $3 }
- | '(' qopm infixexp ')' { LL $ SectionR $2 $3 }
| '_' { L1 EWildPat }
-- Template Haskell Extension
: {- empty -} { [] }
| cvtopdecls { $1 }
+-- tuple expressions: things that can appear unparenthesized as long as they're
+-- inside parens or delimitted by commas
texp :: { LHsExpr RdrName }
: exp { $1 }
- | qopm infixexp { LL $ SectionR $1 $2 }
- -- The second production is really here only for bang patterns
- -- but
+ -- Technically, this should only be used for bang patterns,
+ -- but we can be a little more liberal here and avoid parens
+ -- inside tuples
+ | infixexp qop { LL $ SectionL $1 $2 }
+ | qopm infixexp { LL $ SectionR $1 $2 }
+ -- view patterns get parenthesized above
+ | exp '->' exp { LL $ EViewPat $1 $3 }
texps :: { [LHsExpr RdrName] }
: texps ',' texp { $3 : $1 }
docnext :: { LHsDoc RdrName }
: DOCNEXT {% case parseHaddockParagraphs (tokenise (getDOCNEXT $1)) of {
- Left err -> parseError (getLoc $1) err;
- Right doc -> return (L1 doc) } }
+ MyLeft err -> parseError (getLoc $1) err;
+ MyRight doc -> return (L1 doc) } }
docprev :: { LHsDoc RdrName }
: DOCPREV {% case parseHaddockParagraphs (tokenise (getDOCPREV $1)) of {
- Left err -> parseError (getLoc $1) err;
- Right doc -> return (L1 doc) } }
+ MyLeft err -> parseError (getLoc $1) err;
+ MyRight doc -> return (L1 doc) } }
docnamed :: { Located (String, (HsDoc RdrName)) }
: DOCNAMED {%
let string = getDOCNAMED $1
(name, rest) = break isSpace string
in case parseHaddockParagraphs (tokenise rest) of {
- Left err -> parseError (getLoc $1) err;
- Right doc -> return (L1 (name, doc)) } }
+ MyLeft err -> parseError (getLoc $1) err;
+ MyRight doc -> return (L1 (name, doc)) } }
docsection :: { Located (n, HsDoc RdrName) }
: DOCSECTION {% let (n, doc) = getDOCSECTION $1 in
case parseHaddockString (tokenise doc) of {
- Left err -> parseError (getLoc $1) err;
- Right doc -> return (L1 (n, doc)) } }
-
-docoptions :: { String }
- : DOCOPTIONS { getDOCOPTIONS $1 }
+ MyLeft err -> parseError (getLoc $1) err;
+ MyRight doc -> return (L1 (n, doc)) } }
moduleheader :: { (HaddockModInfo RdrName, Maybe (HsDoc RdrName)) }
: DOCNEXT {% let string = getDOCNEXT $1 in
case parseModuleHeader string of {
Right (str, info) ->
case parseHaddockParagraphs (tokenise str) of {
- Left err -> parseError (getLoc $1) err;
- Right doc -> return (info, Just doc);
+ MyLeft err -> parseError (getLoc $1) err;
+ MyRight doc -> return (info, Just doc);
};
Left err -> parseError (getLoc $1) err
} }
getDOCPREV (L _ (ITdocCommentPrev x)) = x
getDOCNAMED (L _ (ITdocCommentNamed x)) = x
getDOCSECTION (L _ (ITdocSection n x)) = (n, x)
-getDOCOPTIONS (L _ (ITdocOptions x)) = x
-- Utilities for combining source spans
comb2 :: Located a -> Located b -> SrcSpan