ghc-exactprint 1.14.0.0 → 1.14.1.0
raw patch · 6 files changed
+55/−4 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog +3/−0
- ghc-exactprint.cabal +1/−1
- src/Language/Haskell/GHC/ExactPrint/ExactPrint.hs +3/−3
- tests/Test/Transform.hs +22/−0
- tests/examples/transform/InstanceGraft.hs +12/−0
- tests/examples/transform/InstanceGraft.hs.expected +14/−0
ChangeLog view
@@ -1,3 +1,6 @@+2026-08-06 v1.14.1.0+ * Add layout processing for HsLam+ * Establish a layout offset for class and instance bodies (@simonhorlick) 2025-10-14 v1.14.0.0 * Support GHC 9.14.1 2025-01-21 v1.12.0.0
ghc-exactprint.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: ghc-exactprint-version: 1.14.0.0+version: 1.14.1.0 synopsis: ExactPrint for GHC description: Using the API Annotations available from GHC 9.2.1, this library provides a means to round trip any code that can
src/Language/Haskell/GHC/ExactPrint/ExactPrint.hs view
@@ -2217,7 +2217,7 @@ (mbWarn', i', w', mbOverlap', inst_ty') <- top_matter oc' <- markEpToken oc semis' <- mapM markEpToken semis- (sortKey', ds) <- withSortKey sortKey+ (sortKey', ds) <- setLayoutBoth $ withSortKey sortKey [(ClsAtTag, prepareListAnnotationA ats), (ClsAtdTag, prepareListAnnotationF adts), (ClsMethodTag, prepareListAnnotationA binds),@@ -2883,7 +2883,7 @@ LamSingle -> return an0 LamCase -> markLensFun an0 lepl_case (\ml -> mapM (\l -> printStringAtAA l "case") ml) LamCases -> markLensFun an0 lepl_case (\ml -> mapM (\l -> printStringAtAA l "cases") ml)- mg' <- markAnnotated mg+ mg' <- setLayoutBoth $ markAnnotated mg return (HsLam an1 lam_variant mg') exact (HsApp an e1 e2) = do@@ -3606,7 +3606,7 @@ (c', w', vb', fds', lclas', tyvars',context') <- top_matter oc' <- markEpToken oc semis' <- mapM markEpToken semis- (sortKey', ds) <- withSortKey sortKey+ (sortKey', ds) <- setLayoutBoth $ withSortKey sortKey [(ClsSigTag, prepareListAnnotationA sigs), (ClsMethodTag, prepareListAnnotationA methods), (ClsAtTag, prepareListAnnotationA ats),
tests/Test/Transform.hs view
@@ -21,6 +21,7 @@ import System.FilePath import Data.List+import Data.List.NonEmpty (NonEmpty ((:|))) import Test.Common @@ -62,6 +63,7 @@ , mkTestModChange libdir changeLocalDecls2 "LocalDecls2.hs" , mkTestModChange libdir changeWhereIn3a "WhereIn3a.hs" , mkTestModChange libdir changeWhereIn3b "WhereIn3b.hs"+ , mkTestModChange libdir changeInstanceGraft "InstanceGraft.hs" -- , mkTestModChange changeCifToCase "C.hs" "C" ] @@ -99,6 +101,26 @@ debugM $ "changeWhereIn3a:de1:" ++ showAst de1 let p2 = p { hsmodDecls = decls} return (L l p2)++-- ---------------------------------------------------------------------++-- | A delta-anchored expression grafted into a class or instance method+-- must indent its continuation lines relative to the method declarations+-- layout column.+changeInstanceGraft :: Changer+changeInstanceGraft _libdir top = do+ let lp = makeDeltaAst top+ grab :: HsBind GhcPs -> [LHsExpr GhcPs]+ grab FunBind{ fun_id = L _ n+ , fun_matches = MG{mg_alts = L _ [L _ Match{m_grhss = GRHSs _ (L _ (GRHS _ _ e) :| []) _}]}}+ | occNameString (rdrNameOcc n) == "combine" = [e]+ grab _ = []+ [body] = everything (++) ([] `mkQ` grab) lp+ replace :: LHsExpr GhcPs -> LHsExpr GhcPs+ replace (L _ (HsVar _ (L _ n)))+ | occNameString (rdrNameOcc n) == "todo" = setEntryDP body (SameLine 1)+ replace x = x+ return (everywhere (mkT replace) lp) -- ---------------------------------------------------------------------
+ tests/examples/transform/InstanceGraft.hs view
@@ -0,0 +1,12 @@+module InstanceGraft where++combine :: Int -> Int -> Int+combine a b = a+ + b++class C t where+ go :: t -> Int+ go n = todo++instance C Int where+ go n = todo
+ tests/examples/transform/InstanceGraft.hs.expected view
@@ -0,0 +1,14 @@+module InstanceGraft where++combine :: Int -> Int -> Int+combine a b = a+ + b++class C t where+ go :: t -> Int+ go n = a+ + b++instance C Int where+ go n = a+ + b