diff options
author | Alan Zimmerman <alan.zimm@gmail.com> | 2021-10-11 23:05:08 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-10-14 14:34:07 -0400 |
commit | 8b7f5424c67b5ec005e061db87d30e124cf7234d (patch) | |
tree | 49b7c66079e415d6151d7edd2c180169a26e991a /compiler/GHC/Parser.y | |
parent | f450e9481eafa3a00c648c81154a9a8be2da7650 (diff) | |
download | haskell-8b7f5424c67b5ec005e061db87d30e124cf7234d.tar.gz |
EPA: Preserve semicolon order in annotations
Ensure the AddSemiAnn items appear in increasing order, so that if
they are converted to delta format they are still in the correct
order.
Prior to this the exact printer sorted by Span, which is meaningless
for EpaDelta locations.
Diffstat (limited to 'compiler/GHC/Parser.y')
-rw-r--r-- | compiler/GHC/Parser.y | 40 |
1 files changed, 20 insertions, 20 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 |