haskell-tools-prettyprint 0.7.0.0 → 0.8.0.0
raw patch · 5 files changed
+16/−8 lines, 5 filesdep ~haskell-tools-astPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: haskell-tools-ast
API changes (from Hackage documentation)
+ Language.Haskell.Tools.Transform: lineEndings :: Partial SourceTemplateTextElem SourceTemplateTextElem String String
Files
- Language/Haskell/Tools/PrettyPrint.hs +1/−1
- Language/Haskell/Tools/Transform.hs +1/−1
- Language/Haskell/Tools/Transform/PlaceComments.hs +7/−1
- Language/Haskell/Tools/Transform/RangeTemplateToSourceTemplate.hs +5/−3
- haskell-tools-prettyprint.cabal +2/−2
Language/Haskell/Tools/PrettyPrint.hs view
@@ -97,7 +97,7 @@ = let ls = splitOn "\n" s in case ls of _:_:_ -> (unlines (init ls) ++) `mapFst` untilReaches' (last ls) (advanceSrcLoc start '\n') end - _ -> (s, srcLocCol start) + _ -> (s, srcLocCol $ foldl advanceSrcLoc start s) where untilReaches' [] curr _ = ([], srcLocCol curr) untilReaches' (c:rest) curr until | srcLocCol advancedLoc <= srcLocCol until
Language/Haskell/Tools/Transform.hs view
@@ -9,7 +9,7 @@ , sourceTemplateNodeRange, sourceTemplateNodeElems , sourceTemplateListRange, srcTmpListBefore, srcTmpListAfter, srcTmpDefaultSeparator, srcTmpIndented, srcTmpSeparators , sourceTemplateOptRange, srcTmpOptBefore, srcTmpOptAfter - , SourceTemplateElem(..), sourceTemplateTextElem, sourceTemplateTextRange, SourceTemplateTextElem(..), sourceTemplateText, isStayingText + , SourceTemplateElem(..), sourceTemplateTextElem, sourceTemplateTextRange, SourceTemplateTextElem(..), sourceTemplateText, lineEndings, isStayingText -- parts of the transformation, used for debugging purposes , rangeToSource, fixRanges, cutUpRanges, getLocIndices, mapLocIndices, fixMainRange, extractStayingElems ) where
Language/Haskell/Tools/Transform/PlaceComments.hs view
@@ -41,7 +41,7 @@ -> Ann UModule dom stage -> Ann UModule dom stage placeComments tokens comms mod = resizeAnnots (Set.filter (\rng -> srcSpanStart rng /= srcSpanEnd rng) $ Set.fromList $ concat (Map.elems tokens)) - (concatMap (map nextSrcLoc . snd) (Map.toList comms)) mod + (concatMap (map nextSrcLoc . snd) (Map.toList cleanedComments)) mod where spans = allElemSpans mod sortedElemStarts = Set.fromList $ map srcSpanStart spans sortedElemEnds = Set.fromList $ map srcSpanEnd spans @@ -49,6 +49,12 @@ = let after = fromMaybe noSrcLoc (Set.lookupLE (srcSpanStart sp) sortedElemEnds) before = fromMaybe noSrcLoc (Set.lookupGE (srcSpanEnd sp) sortedElemStarts) in ((after,before),comm) + cleanedComments = Map.map (map cleanComment) comms + cleanComment (L loc (AnnLineComment txt)) + | last txt `elem` "\n\r" = L (mkSrcSpan (srcSpanStart loc) (decreaseCol (srcSpanEnd loc))) (AnnLineComment (init txt)) + cleanComment c = c + decreaseCol (RealSrcLoc l) = mkSrcLoc (srcLocFile l) (srcLocLine l) (srcLocCol l - 1) + decreaseCol l = l allElemSpans :: (SourceInfoTraversal node, RangeInfo stage) => Ann node dom stage -> [SrcSpan] allElemSpans = execWriter . sourceInfoTraverse (SourceInfoTrf (\ni -> tell [ni ^. nodeSpan] >> pure ni) pure pure)
Language/Haskell/Tools/Transform/RangeTemplateToSourceTemplate.hs view
@@ -88,9 +88,11 @@ breakStaying = concat . Prelude.map (\(NormalText s) -> toTxtElems s) toTxtElems :: String -> [SourceTemplateTextElem] - toTxtElems = extractStaying . splitOn "\n" - extractStaying lines = Prelude.foldr appendTxt [] - $ Prelude.map (\ln -> if "#" `isPrefixOf` ln then StayingText ln "\n" else NormalText ln) lines + toTxtElems str = extractStaying $ splitOn "\n" $ str + where + extractStaying lines | not (any ("#" `isPrefixOf`) lines) = [NormalText str] + extractStaying lines = Prelude.foldr appendTxt [] + $ Prelude.map (\ln -> if "#" `isPrefixOf` ln then StayingText ln "\n" else NormalText ln) lines -- recombines the lines if they are both normal text -- otherwise it moves the windows '\r' characters to the correct position appendTxt (NormalText n1) (NormalText n2 : rest) = NormalText (n1 ++ '\n':n2) : rest
haskell-tools-prettyprint.cabal view
@@ -1,5 +1,5 @@ name: haskell-tools-prettyprint -version: 0.7.0.0 +version: 0.8.0.0 synopsis: Pretty printing of Haskell-Tools AST description: Converts the Haskell-Tools AST to text. Prepares the AST for this conversion. If the AST was created from the GHC AST this pretty printing will result in the original source code. Generated AST parts will get the default formatting. Works using the source annotations that are present in the AST. Creates a rose tree first to simplify the conversion. homepage: https://github.com/haskell-tools/haskell-tools @@ -31,5 +31,5 @@ , split >= 0.2 && < 0.3 , text >= 1.2 && < 1.3 , ghc >= 8.0 && < 8.1 - , haskell-tools-ast >= 0.7 && < 0.8 + , haskell-tools-ast >= 0.8 && < 0.9 default-language: Haskell2010