summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/Parser.y40
-rw-r--r--compiler/GHC/Parser/Annotation.hs36
-rw-r--r--compiler/GHC/Parser/Lexer.x7
-rw-r--r--compiler/GHC/Parser/PostProcess.hs98
4 files changed, 111 insertions, 70 deletions
diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y
index 0cc1bc732a..b0b6a89e52 100644
--- a/compiler/GHC/Parser.y
+++ b/compiler/GHC/Parser.y
@@ -936,7 +936,7 @@ body2 :: { (AnnList
top :: { ([TrailingAnn]
,([LImportDecl GhcPs], [LHsDecl GhcPs])) }
- : semis top1 { ($1, $2) }
+ : semis top1 { (reverse $1, $2) }
top1 :: { ([LImportDecl GhcPs], [LHsDecl GhcPs]) }
: importdecls_semi topdecls_cs_semi { (reverse $1, cvTopDecls $2) }
@@ -1085,7 +1085,7 @@ importdecls
importdecls_semi :: { [LImportDecl GhcPs] }
importdecls_semi
: importdecls_semi importdecl semis1
- {% do { i <- amsAl $2 (comb2 (reLoc $2) $3) (unLoc $3)
+ {% do { i <- amsAl $2 (comb2 (reLoc $2) $3) (reverse $ unLoc $3)
; return (i : $1)} }
| {- empty -} { [] }
@@ -1187,7 +1187,7 @@ topdecls :: { OrdList (LHsDecl GhcPs) }
-- May have trailing semicolons, can be empty
topdecls_semi :: { OrdList (LHsDecl GhcPs) }
- : topdecls_semi topdecl semis1 {% do { t <- amsAl $2 (comb2 (reLoc $2) $3) (unLoc $3)
+ : topdecls_semi topdecl semis1 {% do { t <- amsAl $2 (comb2 (reLoc $2) $3) (reverse $ unLoc $3)
; return ($1 `snocOL` t) }}
| {- empty -} { nilOL }
@@ -1200,7 +1200,7 @@ topdecls_cs :: { OrdList (LHsDecl GhcPs) }
-- May have trailing semicolons, can be empty
topdecls_cs_semi :: { OrdList (LHsDecl GhcPs) }
- : topdecls_cs_semi topdecl_cs semis1 {% do { t <- amsAl $2 (comb2 (reLoc $2) $3) (unLoc $3)
+ : topdecls_cs_semi topdecl_cs semis1 {% do { t <- amsAl $2 (comb2 (reLoc $2) $3) (reverse $ unLoc $3)
; return ($1 `snocOL` t) }}
| {- empty -} { nilOL }
@@ -1680,7 +1680,7 @@ decl_cls : at_decl_cls { $1 }
decls_cls :: { Located ([AddEpAnn],OrdList (LHsDecl GhcPs)) } -- Reversed
: decls_cls ';' decl_cls {% if isNilOL (snd $ unLoc $1)
- then return (sLLlA $1 $> ((mz AnnSemi $2) ++ (fst $ unLoc $1)
+ then return (sLLlA $1 $> ((fst $ unLoc $1) ++ (mz AnnSemi $2)
, unitOL $3))
else case (snd $ unLoc $1) of
SnocOL hs t -> do
@@ -1688,7 +1688,7 @@ decls_cls :: { Located ([AddEpAnn],OrdList (LHsDecl GhcPs)) } -- Reversed
return (sLLlA $1 $> (fst $ unLoc $1
, snocOL hs t' `appOL` unitOL $3)) }
| decls_cls ';' {% if isNilOL (snd $ unLoc $1)
- then return (sLL $1 $> ((mz AnnSemi $2) ++ (fst $ unLoc $1)
+ then return (sLL $1 $> ( (fst $ unLoc $1) ++ (mz AnnSemi $2)
,snd $ unLoc $1))
else case (snd $ unLoc $1) of
SnocOL hs t -> do
@@ -1726,7 +1726,7 @@ decl_inst : at_decl_inst { sL1A $1 (unitOL (sL1 $1 (InstD noExtFi
decls_inst :: { Located ([AddEpAnn],OrdList (LHsDecl GhcPs)) } -- Reversed
: decls_inst ';' decl_inst {% if isNilOL (snd $ unLoc $1)
- then return (sLL $1 $> ((mz AnnSemi $2) ++ (fst $ unLoc $1)
+ then return (sLL $1 $> ((fst $ unLoc $1) ++ (mz AnnSemi $2)
, unLoc $3))
else case (snd $ unLoc $1) of
SnocOL hs t -> do
@@ -1734,7 +1734,7 @@ decls_inst :: { Located ([AddEpAnn],OrdList (LHsDecl GhcPs)) } -- Reversed
return (sLL $1 $> (fst $ unLoc $1
, snocOL hs t' `appOL` unLoc $3)) }
| decls_inst ';' {% if isNilOL (snd $ unLoc $1)
- then return (sLL $1 $> ((mz AnnSemi $2) ++ (fst $ unLoc $1)
+ then return (sLL $1 $> ((fst $ unLoc $1) ++ (mz AnnSemi $2)
,snd $ unLoc $1))
else case (snd $ unLoc $1) of
SnocOL hs t -> do
@@ -1764,7 +1764,7 @@ where_inst :: { Located ([AddEpAnn]
--
decls :: { Located ([TrailingAnn], OrdList (LHsDecl GhcPs)) }
: decls ';' decl {% if isNilOL (snd $ unLoc $1)
- then return (sLLlA $1 $> ((msemi $2) ++ (fst $ unLoc $1)
+ then return (sLLlA $1 $> ((fst $ unLoc $1) ++ (msemi $2)
, unitOL $3))
else case (snd $ unLoc $1) of
SnocOL hs t -> do
@@ -1775,7 +1775,7 @@ decls :: { Located ([TrailingAnn], OrdList (LHsDecl GhcPs)) }
return (rest `seq` this `seq` these `seq`
(sLLlA $1 $> (fst $ unLoc $1, these))) }
| decls ';' {% if isNilOL (snd $ unLoc $1)
- then return (sLL $1 $> (((msemi $2) ++ (fst $ unLoc $1)
+ then return (sLL $1 $> (((fst $ unLoc $1) ++ (msemi $2)
,snd $ unLoc $1)))
else case (snd $ unLoc $1) of
SnocOL hs t -> do
@@ -3217,21 +3217,21 @@ alts :: { forall b. DisambECP b => PV (Located ([AddEpAnn],[LMatch GhcPs (Loc
: alts1 { $1 >>= \ $1 -> return $
sL1 $1 (fst $ unLoc $1,snd $ unLoc $1) }
| ';' alts { $2 >>= \ $2 -> return $
- sLL $1 $> (((mz AnnSemi $1) ++ (fst $ unLoc $2))
+ sLL $1 $> (((mz AnnSemi $1) ++ (fst $ unLoc $2) )
,snd $ unLoc $2) }
alts1 :: { forall b. DisambECP b => PV (Located ([AddEpAnn],[LMatch GhcPs (LocatedA b)])) }
: alts1 ';' alt { $1 >>= \ $1 ->
$3 >>= \ $3 ->
case snd $ unLoc $1 of
- [] -> return (sLL $1 (reLoc $>) ((mz AnnSemi $2) ++(fst $ unLoc $1)
+ [] -> return (sLL $1 (reLoc $>) ((fst $ unLoc $1) ++ (mz AnnSemi $2)
,[$3]))
(h:t) -> do
h' <- addTrailingSemiA h (gl $2)
return (sLL $1 (reLoc $>) (fst $ unLoc $1,$3 : h' : t)) }
| alts1 ';' { $1 >>= \ $1 ->
case snd $ unLoc $1 of
- [] -> return (sLL $1 $> ((mz AnnSemi $2) ++(fst $ unLoc $1)
+ [] -> return (sLL $1 $> ((fst $ unLoc $1) ++ (mz AnnSemi $2)
,[]))
(h:t) -> do
h' <- addTrailingSemiA h (gl $2)
@@ -3301,9 +3301,9 @@ apats :: { [LPat GhcPs] }
stmtlist :: { forall b. DisambECP b => PV (LocatedL [LocatedA (Stmt GhcPs (LocatedA b))]) }
: '{' stmts '}' { $2 >>= \ $2 -> amsrl
- (sLL $1 $> (reverse $ snd $ unLoc $2)) (AnnList (Just $ glR $2) (Just $ moc $1) (Just $ mcc $3) (fst $ unLoc $2) []) } -- AZ:performance of reverse?
+ (sLL $1 $> (reverse $ snd $ unLoc $2)) (AnnList (Just $ glR $2) (Just $ moc $1) (Just $ mcc $3) (fromOL $ fst $ unLoc $2) []) }
| vocurly stmts close { $2 >>= \ $2 -> amsrl
- (L (gl $2) (reverse $ snd $ unLoc $2)) (AnnList (Just $ glR $2) Nothing Nothing (fst $ unLoc $2) []) }
+ (L (gl $2) (reverse $ snd $ unLoc $2)) (AnnList (Just $ glR $2) Nothing Nothing (fromOL $ fst $ unLoc $2) []) }
-- do { ;; s ; s ; ; s ;; }
-- The last Stmt should be an expression, but that's hard to enforce
@@ -3311,11 +3311,11 @@ stmtlist :: { forall b. DisambECP b => PV (LocatedL [LocatedA (Stmt GhcPs (Locat
-- So we use BodyStmts throughout, and switch the last one over
-- in ParseUtils.checkDo instead
-stmts :: { forall b. DisambECP b => PV (Located ([AddEpAnn],[LStmt GhcPs (LocatedA b)])) }
+stmts :: { forall b. DisambECP b => PV (Located (OrdList AddEpAnn,[LStmt GhcPs (LocatedA b)])) }
: stmts ';' stmt { $1 >>= \ $1 ->
$3 >>= \ ($3 :: LStmt GhcPs (LocatedA b)) ->
case (snd $ unLoc $1) of
- [] -> return (sLL $1 (reLoc $>) ((mj AnnSemi $2) : (fst $ unLoc $1)
+ [] -> return (sLL $1 (reLoc $>) ((fst $ unLoc $1) `snocOL` (mj AnnSemi $2)
,$3 : (snd $ unLoc $1)))
(h:t) -> do
{ h' <- addTrailingSemiA h (gl $2)
@@ -3323,13 +3323,13 @@ stmts :: { forall b. DisambECP b => PV (Located ([AddEpAnn],[LStmt GhcPs (Locate
| stmts ';' { $1 >>= \ $1 ->
case (snd $ unLoc $1) of
- [] -> return (sLL $1 $> ((mj AnnSemi $2) : (fst $ unLoc $1),snd $ unLoc $1))
+ [] -> return (sLL $1 $> ((fst $ unLoc $1) `snocOL` (mj AnnSemi $2),snd $ unLoc $1))
(h:t) -> do
{ h' <- addTrailingSemiA h (gl $2)
; return $ sL1 $1 (fst $ unLoc $1,h':t) }}
| stmt { $1 >>= \ $1 ->
- return $ sL1A $1 ([],[$1]) }
- | {- empty -} { return $ noLoc ([],[]) }
+ return $ sL1A $1 (nilOL,[$1]) }
+ | {- empty -} { return $ noLoc (nilOL,[]) }
-- For typing stmts at the GHCi prompt, where
diff --git a/compiler/GHC/Parser/Annotation.hs b/compiler/GHC/Parser/Annotation.hs
index 1692d394b5..9555291530 100644
--- a/compiler/GHC/Parser/Annotation.hs
+++ b/compiler/GHC/Parser/Annotation.hs
@@ -100,7 +100,7 @@ import qualified GHC.Data.Strict as Strict
{-
Note [exact print annotations]
-~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Given a parse tree of a Haskell module, how can we reconstruct
the original Haskell source code, retaining all whitespace and
source code comments? We need to track the locations of all
@@ -394,7 +394,7 @@ instance Outputable EpaComment where
-- The usual way an 'AddEpAnn' is created is using the 'mj' ("make
-- jump") function, and then it can be inserted into the appropriate
-- annotation.
-data AddEpAnn = AddEpAnn AnnKeywordId EpaLocation deriving (Data,Eq,Ord)
+data AddEpAnn = AddEpAnn AnnKeywordId EpaLocation deriving (Data,Eq)
-- | The anchor for an @'AnnKeywordId'@. The Parser inserts the
-- @'EpaSpan'@ variant, giving the exact location of the original item
@@ -460,6 +460,9 @@ instance Outputable EpaLocation where
instance Outputable AddEpAnn where
ppr (AddEpAnn kw ss) = text "AddEpAnn" <+> ppr kw <+> ppr ss
+instance Ord AddEpAnn where
+ compare (AddEpAnn kw1 loc1) (AddEpAnn kw2 loc2) = compare (loc1, kw1) (loc2,kw2)
+
-- ---------------------------------------------------------------------
-- | The exact print annotations (EPAs) are kept in the HsSyn AST for
@@ -802,7 +805,8 @@ addTrailingAnnToL s t cs EpAnnNotUsed
addTrailingAnnToL _ t cs n = n { anns = addTrailing (anns n)
, comments = comments n <> cs }
where
- addTrailing n = n { al_trailing = t : al_trailing n }
+ -- See Note [list append in addTrailing*]
+ addTrailing n = n { al_trailing = al_trailing n ++ [t]}
-- | Helper function used in the parser to add a 'TrailingAnn' items
-- to an existing annotation.
@@ -813,7 +817,8 @@ addTrailingAnnToA s t cs EpAnnNotUsed
addTrailingAnnToA _ t cs n = n { anns = addTrailing (anns n)
, comments = comments n <> cs }
where
- addTrailing n = n { lann_trailing = t : lann_trailing n }
+ -- See Note [list append in addTrailing*]
+ addTrailing n = n { lann_trailing = lann_trailing n ++ [t] }
-- | Helper function used in the parser to add a comma location to an
-- existing annotation.
@@ -822,8 +827,29 @@ addTrailingCommaToN s EpAnnNotUsed l
= EpAnn (spanAsAnchor s) (NameAnnTrailing [AddCommaAnn l]) emptyComments
addTrailingCommaToN _ n l = n { anns = addTrailing (anns n) l }
where
+ -- See Note [list append in addTrailing*]
addTrailing :: NameAnn -> EpaLocation -> NameAnn
- addTrailing n l = n { nann_trailing = AddCommaAnn l : nann_trailing n }
+ addTrailing n l = n { nann_trailing = nann_trailing n ++ [AddCommaAnn l]}
+
+{-
+Note [list append in addTrailing*]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The addTrailingAnnToL, addTrailingAnnToA and addTrailingCommaToN
+functions are used to add a separator for an item when it occurs in a
+list. So they are used to capture a comma, vbar, semicolon and similar.
+
+In general, a given element will have zero or one of these. In
+extreme (test) cases, there may be multiple semicolons.
+
+In exact printing we sometimes convert the EpaLocation variant for an
+trailing annotation to the EpaDelta variant, which cannot be sorted.
+
+Hence it is critical that these annotations are captured in the order
+they appear in the original source file.
+
+And so we use the less efficient list append to preserve the order,
+knowing that in most cases the original list is empty.
+-}
-- ---------------------------------------------------------------------
diff --git a/compiler/GHC/Parser/Lexer.x b/compiler/GHC/Parser/Lexer.x
index 10568814d7..d74d17be8f 100644
--- a/compiler/GHC/Parser/Lexer.x
+++ b/compiler/GHC/Parser/Lexer.x
@@ -3490,12 +3490,11 @@ clean_pragma prag = canon_ws (map toLower (unprefix prag))
-}
--- |Given a 'SrcSpan' that surrounds a 'HsPar' or 'HsParTy', generate
+-- |Given a 'RealSrcSpan' that surrounds a 'HsPar' or 'HsParTy', generate
-- 'AddEpAnn' values for the opening and closing bordering on the start
-- and end of the span
-mkParensEpAnn :: SrcSpan -> [AddEpAnn]
-mkParensEpAnn (UnhelpfulSpan _) = []
-mkParensEpAnn (RealSrcSpan ss _) = [AddEpAnn AnnOpenP (EpaSpan lo),AddEpAnn AnnCloseP (EpaSpan lc)]
+mkParensEpAnn :: RealSrcSpan -> (AddEpAnn, AddEpAnn)
+mkParensEpAnn ss = (AddEpAnn AnnOpenP (EpaSpan lo),AddEpAnn AnnCloseP (EpaSpan lc))
where
f = srcSpanFile ss
sl = srcSpanStartLine ss
diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs
index ae19e7b7b3..b5511334ec 100644
--- a/compiler/GHC/Parser/PostProcess.hs
+++ b/compiler/GHC/Parser/PostProcess.hs
@@ -852,26 +852,36 @@ checkTyVars pp_what equals_or_where tc tparms
where
check (HsTypeArg _ ki@(L loc _)) = addFatalError $ mkPlainErrorMsgEnvelope (locA loc) $
(PsErrUnexpectedTypeAppInDecl ki pp_what (unLoc tc))
- check (HsValArg ty) = chkParens [] emptyComments ty
+ check (HsValArg ty) = chkParens [] [] emptyComments ty
check (HsArgPar sp) = addFatalError $ mkPlainErrorMsgEnvelope sp $
(PsErrMalformedDecl pp_what (unLoc tc))
-- Keep around an action for adjusting the annotations of extra parens
- chkParens :: [AddEpAnn] -> EpAnnComments -> LHsType GhcPs
+ chkParens :: [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> LHsType GhcPs
-> P (LHsTyVarBndr () GhcPs)
- chkParens acc cs (L l (HsParTy an ty))
- = chkParens (mkParensEpAnn (locA l) ++ acc) (cs Semi.<> epAnnComments an) ty
- chkParens acc cs ty = chk acc cs ty
+ chkParens ops cps cs (L l (HsParTy an ty))
+ = let
+ (o,c) = mkParensEpAnn (realSrcSpan $ locA l)
+ in
+ chkParens (o:ops) (c:cps) (cs Semi.<> epAnnComments an) ty
+ chkParens ops cps cs ty = chk ops cps cs ty
-- Check that the name space is correct!
- chk :: [AddEpAnn] -> EpAnnComments -> LHsType GhcPs -> P (LHsTyVarBndr () GhcPs)
- chk an cs (L l (HsKindSig annk (L annt (HsTyVar ann _ (L lv tv))) k))
+ chk :: [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> LHsType GhcPs -> P (LHsTyVarBndr () GhcPs)
+ chk ops cps cs (L l (HsKindSig annk (L annt (HsTyVar ann _ (L lv tv))) k))
| isRdrTyVar tv
- = return (L (widenLocatedAn (l Semi.<> annt) an)
- (KindedTyVar (addAnns (annk Semi.<> ann) an cs) () (L lv tv) k))
- chk an cs (L l (HsTyVar ann _ (L ltv tv)))
- | isRdrTyVar tv = return (L (widenLocatedAn l an)
+ = let
+ an = (reverse ops) ++ cps
+ in
+ return (L (widenLocatedAn (l Semi.<> annt) an)
+ (KindedTyVar (addAnns (annk Semi.<> ann) an cs) () (L lv tv) k))
+ chk ops cps cs (L l (HsTyVar ann _ (L ltv tv)))
+ | isRdrTyVar tv
+ = let
+ an = (reverse ops) ++ cps
+ in
+ return (L (widenLocatedAn l an)
(UserTyVar (addAnns ann an cs) () (L ltv tv)))
- chk _ _ t@(L loc _)
+ chk _ _ _ t@(L loc _)
= addFatalError $ mkPlainErrorMsgEnvelope (locA loc) $
(PsErrUnexpectedTypeInDecl t pp_what (unLoc tc) tparms equals_or_where)
@@ -951,34 +961,36 @@ checkTyClHdr :: Bool -- True <=> class header
-- Int :*: Bool into (:*:, [Int, Bool])
-- returning the pieces
checkTyClHdr is_cls ty
- = goL ty [] [] Prefix
+ = goL ty [] [] [] Prefix
where
- goL (L l ty) acc ann fix = go (locA l) ty acc ann fix
+ goL (L l ty) acc ops cps fix = go (locA l) ty acc ops cps fix
-- workaround to define '*' despite StarIsType
- go _ (HsParTy an (L l (HsStarTy _ isUni))) acc ann' fix
+ go _ (HsParTy an (L l (HsStarTy _ isUni))) acc ops' cps' fix
= do { addPsMessage (locA l) PsWarnStarBinder
; let name = mkOccName tcClsName (starSym isUni)
; let a' = newAnns l an
; return (L a' (Unqual name), acc, fix
- , ann') }
-
- go _ (HsTyVar _ _ ltc@(L _ tc)) acc ann fix
- | isRdrTc tc = return (ltc, acc, fix, ann)
- go _ (HsOpTy _ t1 ltc@(L _ tc) t2) acc ann _fix
- | isRdrTc tc = return (ltc, HsValArg t1:HsValArg t2:acc, Infix, ann)
- go l (HsParTy _ ty) acc ann fix = goL ty acc (ann ++mkParensEpAnn l) fix
- go _ (HsAppTy _ t1 t2) acc ann fix = goL t1 (HsValArg t2:acc) ann fix
- go _ (HsAppKindTy l ty ki) acc ann fix = goL ty (HsTypeArg l ki:acc) ann fix
- go l (HsTupleTy _ HsBoxedOrConstraintTuple ts) [] ann fix
+ , (reverse ops') ++ cps') }
+
+ go _ (HsTyVar _ _ ltc@(L _ tc)) acc ops cps fix
+ | isRdrTc tc = return (ltc, acc, fix, (reverse ops) ++ cps)
+ go _ (HsOpTy _ t1 ltc@(L _ tc) t2) acc ops cps _fix
+ | isRdrTc tc = return (ltc, HsValArg t1:HsValArg t2:acc, Infix, (reverse ops) ++ cps)
+ go l (HsParTy _ ty) acc ops cps fix = goL ty acc (o:ops) (c:cps) fix
+ where
+ (o,c) = mkParensEpAnn (realSrcSpan l)
+ go _ (HsAppTy _ t1 t2) acc ops cps fix = goL t1 (HsValArg t2:acc) ops cps fix
+ go _ (HsAppKindTy l ty ki) acc ops cps fix = goL ty (HsTypeArg l ki:acc) ops cps fix
+ go l (HsTupleTy _ HsBoxedOrConstraintTuple ts) [] ops cps fix
= return (L (noAnnSrcSpan l) (nameRdrName tup_name)
- , map HsValArg ts, fix, ann)
+ , map HsValArg ts, fix, (reverse ops)++cps)
where
arity = length ts
tup_name | is_cls = cTupleTyConName arity
| otherwise = getName (tupleTyCon Boxed arity)
-- See Note [Unit tuples] in GHC.Hs.Type (TODO: is this still relevant?)
- go l _ _ _ _
+ go l _ _ _ _ _
= addFatalError $ mkPlainErrorMsgEnvelope l $
(PsErrMalformedTyOrClDecl ty)
@@ -1054,7 +1066,8 @@ checkContext orig_t@(L (SrcSpanAnn _ l) _orig_t) =
EpAnnNotUsed -> ([],[],emptyComments)
EpAnn _ (AnnParen _ o c) cs -> ([o],[c],cs)
return (L (SrcSpanAnn (EpAnn (spanAsAnchor l)
- (AnnContext Nothing (op Semi.<> oparens) (cp Semi.<> cparens)) (cs Semi.<> cs')) l) ts)
+ -- Append parens so that the original order in the source is maintained
+ (AnnContext Nothing (oparens ++ op) (cp ++ cparens)) (cs Semi.<> cs')) l) ts)
check (opi,cpi,csi) (L _lp1 (HsParTy ann' ty))
-- to be sure HsParTy doesn't get into the way
@@ -1311,26 +1324,29 @@ isFunLhs :: LocatedA (PatBuilder GhcPs)
[LocatedA (PatBuilder GhcPs)],[AddEpAnn]))
-- A variable binding is parsed as a FunBind.
-- Just (fun, is_infix, arg_pats) if e is a function LHS
-isFunLhs e = go e [] []
+isFunLhs e = go e [] [] []
where
- go (L _ (PatBuilderVar (L loc f))) es ann
- | not (isRdrDataCon f) = return (Just (L loc f, Prefix, es, ann))
- go (L _ (PatBuilderApp f e)) es ann = go f (e:es) ann
- go (L l (PatBuilderPar _ e _)) es@(_:_) ann
- = go e es (ann ++ mkParensEpAnn (locA l))
- go (L loc (PatBuilderOpApp l (L loc' op) r (EpAnn loca anns cs))) es ann
+ go (L _ (PatBuilderVar (L loc f))) es ops cps
+ | not (isRdrDataCon f) = return (Just (L loc f, Prefix, es, (reverse ops) ++ cps))
+ go (L _ (PatBuilderApp f e)) es ops cps = go f (e:es) ops cps
+ go (L l (PatBuilderPar _ e _)) es@(_:_) ops cps
+ = let
+ (o,c) = mkParensEpAnn (realSrcSpan $ locA l)
+ in
+ go e es (o:ops) (c:cps)
+ go (L loc (PatBuilderOpApp l (L loc' op) r (EpAnn loca anns cs))) es ops cps
| not (isRdrDataCon op) -- We have found the function!
- = return (Just (L loc' op, Infix, (l:r:es), (anns ++ ann)))
+ = return (Just (L loc' op, Infix, (l:r:es), (anns ++ reverse ops ++ cps)))
| otherwise -- Infix data con; keep going
- = do { mb_l <- go l es ann
+ = do { mb_l <- go l es ops cps
; case mb_l of
- Just (op', Infix, j : k : es', ann')
- -> return (Just (op', Infix, j : op_app : es', ann'))
+ Just (op', Infix, j : k : es', anns')
+ -> return (Just (op', Infix, j : op_app : es', anns'))
where
op_app = L loc (PatBuilderOpApp k
- (L loc' op) r (EpAnn loca anns cs))
+ (L loc' op) r (EpAnn loca (reverse ops++cps) cs))
_ -> return Nothing }
- go _ _ _ = return Nothing
+ go _ _ _ _ = return Nothing
mkBangTy :: EpAnn [AddEpAnn] -> SrcStrictness -> LHsType GhcPs -> HsType GhcPs
mkBangTy anns strictness =