haskell-tools-prettyprint 1.0.0.4 → 1.0.1.1
raw patch · 9 files changed
+16/−19 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Language/Haskell/Tools/PrettyPrint.hs +7/−8
- Language/Haskell/Tools/PrettyPrint/Prepare/PlaceComments.hs +1/−0
- Language/Haskell/Tools/PrettyPrint/Prepare/RangeTemplate.hs +1/−0
- Language/Haskell/Tools/PrettyPrint/Prepare/RangeTemplateToSourceTemplate.hs +1/−0
- Language/Haskell/Tools/PrettyPrint/Prepare/RangeToRangeTemplate.hs +1/−0
- Language/Haskell/Tools/PrettyPrint/Prepare/SourceTemplate.hs +1/−0
- Language/Haskell/Tools/PrettyPrint/Prepare/SourceTemplateHelpers.hs +1/−0
- Language/Haskell/Tools/PrettyPrint/RoseTree.hs +2/−10
- haskell-tools-prettyprint.cabal +1/−1
Language/Haskell/Tools/PrettyPrint.hs view
@@ -1,12 +1,13 @@-{-# LANGUAGE FlexibleContexts, FlexibleInstances, NamedFieldPuns, UndecidableInstances #-} +{-# LANGUAGE FlexibleContexts, RecordPuns, UndecidableInstances #-} + -- | Pretty printing the AST module Language.Haskell.Tools.PrettyPrint (prettyPrint, toRoseTree, PrettyPrintProblem(..)) where import FastString (fsLit) import SrcLoc -import Language.Haskell.Tools.AST (SrcTemplateStage, SourceInfoTraversal(..)) +import Language.Haskell.Tools.AST import Language.Haskell.Tools.PrettyPrint.Prepare.SourceTemplate import Language.Haskell.Tools.PrettyPrint.RoseTree @@ -39,13 +40,11 @@ printTemplateElems (ChildElem : rest) (child : children) = printRose' parent child >+< printTemplateElems rest children printTemplateElems [] [] = return empty printTemplateElems _ [] - = pprProblem $ "More child elem in template than actual children (elems: " ++ show elems - ++ ", children: " ++ show children - ++ "). Check that the default templates for AST elements are correct." + = pprProblem $ "More child elem in template than actual children in: " + ++ shortShowSpanWithFile (srcLocSpan $ RealSrcLoc parent) printTemplateElems [] _ - = pprProblem $ "Not all children are used to pretty printing. (elems: " - ++ show elems ++ ", children: " ++ show children - ++ "). Check that the default templates for AST elements are correct." + = pprProblem $ "Not all children are used to pretty printing in: " + ++ shortShowSpanWithFile (srcLocSpan $ RealSrcLoc parent) min = minInd `max` getPosByRelative parent relInd
Language/Haskell/Tools/PrettyPrint/Prepare/PlaceComments.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts, LambdaCase, ScopedTypeVariables #-} + -- | This transformation expands nodes to contain the comments that should be attached to them. After this, a -- normalizing transformation should be performed that expands parents to contain their children. module Language.Haskell.Tools.PrettyPrint.Prepare.PlaceComments where
Language/Haskell/Tools/PrettyPrint/Prepare/RangeTemplate.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveDataTypeable, FlexibleInstances, RecordWildCards, TypeFamilies #-} + -- | The range template is an intermediate annotation level, where the children nodes of the tree -- had been cut from the parent nodes, but the annotations still contain ranges instead of text. module Language.Haskell.Tools.PrettyPrint.Prepare.RangeTemplate where
Language/Haskell/Tools/PrettyPrint/Prepare/RangeTemplateToSourceTemplate.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts #-} + -- | This module converts range templates into source templates. -- Basically it reads the source file and attaches parts of the source file to the AST elements that have the range of the given source code fragment. module Language.Haskell.Tools.PrettyPrint.Prepare.RangeTemplateToSourceTemplate where
Language/Haskell/Tools/PrettyPrint/Prepare/RangeToRangeTemplate.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-} + -- | Transform a syntax tree with ranges to a syntax tree that has range templates. Cuts the ranges of children -- from the ranges of their parents and replaces it with placeholders. module Language.Haskell.Tools.PrettyPrint.Prepare.RangeToRangeTemplate (cutUpRanges, fixRanges, BreakUpProblem(..)) where
Language/Haskell/Tools/PrettyPrint/Prepare/SourceTemplate.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveDataTypeable, FlexibleContexts, FlexibleInstances, RecordWildCards, TemplateHaskell, TypeFamilies #-} + -- | The final version of the source annotation. Each node contains its original textual format, with the places of -- the children specified by placeholders. module Language.Haskell.Tools.PrettyPrint.Prepare.SourceTemplate where
Language/Haskell/Tools/PrettyPrint/Prepare/SourceTemplateHelpers.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts, FlexibleInstances, OverloadedStrings #-} + -- | Helper functions for working with source templates module Language.Haskell.Tools.PrettyPrint.Prepare.SourceTemplateHelpers where
Language/Haskell/Tools/PrettyPrint/RoseTree.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE FlexibleContexts, LambdaCase, NamedFieldPuns, StandaloneDeriving #-} +{-# LANGUAGE FlexibleContexts, LambdaCase, RecordPuns #-} + -- | A simpler representation of the original AST. module Language.Haskell.Tools.PrettyPrint.RoseTree where @@ -16,15 +17,6 @@ = RoseSpan (SpanInfo st) | RoseList (ListInfo st) | RoseOptional (OptionalInfo st) - -deriving instance SourceInfo st => Show (RoseSourceInfo st) - -instance SourceInfo st => Show (RoseTree st) where - show = show' 0 - where show' i RoseTree{roseInfo,roseChildren} - = "\n" ++ replicate (2*i) '#' - ++ show roseInfo - ++ concatMap (show' (i+1)) roseChildren -- | Transforms the heterogeneous AST into a homogeneous representation for pretty printing toRoseTree :: (SourceInfoTraversal n) => n dom st -> RoseTree st
haskell-tools-prettyprint.cabal view
@@ -1,5 +1,5 @@ name: haskell-tools-prettyprint -version: 1.0.0.4 +version: 1.0.1.1 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