Safe Haskell | None |
---|---|
Language | Haskell2010 |
Language.Haskell.Tools.PrettyPrint.Prepare
Description
A module for preparing the representation of the AST for pretty printing.
Synopsis
- prepareAST :: StringBuffer -> Ann UModule dom RangeStage -> Ann UModule dom SrcTemplateStage
- prepareASTCpp :: StringBuffer -> Ann UModule dom RangeStage -> Ann UModule dom SrcTemplateStage
- placeComments :: RangeInfo stage => Map ApiAnnKey [SrcSpan] -> Map SrcSpan [Located AnnotationComment] -> Ann UModule dom stage -> Ann UModule dom stage
- getNormalComments :: Map SrcSpan [Located AnnotationComment] -> Map SrcSpan [Located AnnotationComment]
- getPragmaComments :: Map SrcSpan [Located AnnotationComment] -> Map String [Located String]
- child :: SpanInfo SrcTemplateStage
- opt :: OptionalInfo SrcTemplateStage
- list :: ListInfo SrcTemplateStage
- after :: AfterBefore i => String -> i -> i
- followedBy :: AfterBefore i => String -> i -> i
- relativeIndented :: RelativeIndent i => Int -> i -> i
- minimumIndented :: MinimumIndent i => Int -> i -> i
- separatedBy :: String -> ListInfo SrcTemplateStage -> ListInfo SrcTemplateStage
- indented :: ListInfo SrcTemplateStage -> ListInfo SrcTemplateStage
- sourceTemplateNodeRange :: Simple Lens (SpanInfo SrcTemplateStage) SrcSpan
- sourceTemplateNodeElems :: Simple Lens (SpanInfo SrcTemplateStage) [SourceTemplateElem]
- sourceTemplateListRange :: Simple Lens (ListInfo SrcTemplateStage) SrcSpan
- srcTmpListBefore :: Simple Lens (ListInfo SrcTemplateStage) String
- srcTmpListAfter :: Simple Lens (ListInfo SrcTemplateStage) String
- srcTmpDefaultSeparator :: Simple Lens (ListInfo SrcTemplateStage) String
- srcTmpIndented :: Simple Lens (ListInfo SrcTemplateStage) (Maybe [Bool])
- srcTmpSeparators :: Simple Lens (ListInfo SrcTemplateStage) [([SourceTemplateTextElem], SrcSpan)]
- sourceTemplateOptRange :: Simple Lens (OptionalInfo SrcTemplateStage) SrcSpan
- srcTmpOptBefore :: Simple Lens (OptionalInfo SrcTemplateStage) String
- srcTmpOptAfter :: Simple Lens (OptionalInfo SrcTemplateStage) String
- data SourceTemplateElem
- sourceTemplateTextElem :: Partial SourceTemplateElem SourceTemplateElem [SourceTemplateTextElem] [SourceTemplateTextElem]
- sourceTemplateTextRange :: Partial SourceTemplateElem SourceTemplateElem SrcSpan SrcSpan
- data SourceTemplateTextElem
- = NormalText { }
- | StayingText { }
- sourceTemplateText :: Lens SourceTemplateTextElem SourceTemplateTextElem String String
- lineEndings :: Partial SourceTemplateTextElem SourceTemplateTextElem String String
- isStayingText :: SourceTemplateTextElem -> Bool
- rangeToSource :: SourceInfoTraversal node => StringBuffer -> Ann node dom RngTemplateStage -> Ann node dom SrcTemplateStage
- fixRanges :: SourceInfoTraversal node => Ann node dom RangeStage -> Ann node dom NormRangeStage
- cutUpRanges :: forall node dom. SourceInfoTraversal node => Ann node dom NormRangeStage -> Ann node dom RngTemplateStage
- getLocIndices :: SourceInfoTraversal e => Ann e dom RngTemplateStage -> Set (RealSrcLoc, Int)
- mapLocIndices :: Ord k => StringBuffer -> Set (RealSrcLoc, k) -> Map k String
- fixMainRange :: StringBuffer -> Ann UModule dom RangeStage -> Ann UModule dom RangeStage
- extractStayingElems :: SourceInfoTraversal node => Ann node dom SrcTemplateStage -> Ann node dom SrcTemplateStage
- sourceTemplateMinimalIndent :: Simple Lens (SpanInfo SrcTemplateStage) Int
- srcTmpListMinimalIndent :: Simple Lens (ListInfo SrcTemplateStage) Int
- srcTmpOptMinimalIndent :: Simple Lens (OptionalInfo SrcTemplateStage) Int
- data TransformationProblem = TransformationProblem String
- data BreakUpProblem = BreakUpProblem {
- bupOuter :: RealSrcSpan
- bupInner :: SrcSpan
- bupSiblings :: [SrcSpan]
Documentation
prepareAST :: StringBuffer -> Ann UModule dom RangeStage -> Ann UModule dom SrcTemplateStage Source #
Prepares the AST for pretty printing
prepareASTCpp :: StringBuffer -> Ann UModule dom RangeStage -> Ann UModule dom SrcTemplateStage Source #
placeComments :: RangeInfo stage => Map ApiAnnKey [SrcSpan] -> Map SrcSpan [Located AnnotationComment] -> Ann UModule dom stage -> Ann UModule dom stage Source #
Puts comments in the nodes they should be attached to. Watches for lexical tokens that may divide the comment and the supposed element. Leaves the AST in a state where parent nodes does not contain all of their children.
getNormalComments :: Map SrcSpan [Located AnnotationComment] -> Map SrcSpan [Located AnnotationComment] Source #
getPragmaComments :: Map SrcSpan [Located AnnotationComment] -> Map String [Located String] Source #
after :: AfterBefore i => String -> i -> i Source #
Put the given string before the element if it is not empty
followedBy :: AfterBefore i => String -> i -> i Source #
The given string should follow the element if it is not empty
relativeIndented :: RelativeIndent i => Int -> i -> i Source #
The element should be indented relatively to its parent
minimumIndented :: MinimumIndent i => Int -> i -> i Source #
The elements should be indented at least to the given number of spaces
separatedBy :: String -> ListInfo SrcTemplateStage -> ListInfo SrcTemplateStage Source #
The elements of the list should be separated by the given string by default (might be overridden)
indented :: ListInfo SrcTemplateStage -> ListInfo SrcTemplateStage Source #
The elements of the list should be indented on the same column
sourceTemplateNodeRange :: Simple Lens (SpanInfo SrcTemplateStage) SrcSpan Source #
sourceTemplateNodeElems :: Simple Lens (SpanInfo SrcTemplateStage) [SourceTemplateElem] Source #
sourceTemplateListRange :: Simple Lens (ListInfo SrcTemplateStage) SrcSpan Source #
srcTmpListBefore :: Simple Lens (ListInfo SrcTemplateStage) String Source #
srcTmpListAfter :: Simple Lens (ListInfo SrcTemplateStage) String Source #
srcTmpDefaultSeparator :: Simple Lens (ListInfo SrcTemplateStage) String Source #
srcTmpIndented :: Simple Lens (ListInfo SrcTemplateStage) (Maybe [Bool]) Source #
srcTmpSeparators :: Simple Lens (ListInfo SrcTemplateStage) [([SourceTemplateTextElem], SrcSpan)] Source #
sourceTemplateOptRange :: Simple Lens (OptionalInfo SrcTemplateStage) SrcSpan Source #
srcTmpOptBefore :: Simple Lens (OptionalInfo SrcTemplateStage) String Source #
srcTmpOptAfter :: Simple Lens (OptionalInfo SrcTemplateStage) String Source #
data SourceTemplateElem Source #
An element of a source template for a singleton AST node.
Constructors
TextElem | Source text belonging to the current node |
ChildElem | Placeholder for the next children of the node |
Instances
sourceTemplateTextElem :: Partial SourceTemplateElem SourceTemplateElem [SourceTemplateTextElem] [SourceTemplateTextElem] Source #
data SourceTemplateTextElem Source #
Constructors
NormalText | |
Fields | |
StayingText | |
Fields |
Instances
rangeToSource :: SourceInfoTraversal node => StringBuffer -> Ann node dom RngTemplateStage -> Ann node dom SrcTemplateStage Source #
fixRanges :: SourceInfoTraversal node => Ann node dom RangeStage -> Ann node dom NormRangeStage Source #
Modifies ranges to contain their children
cutUpRanges :: forall node dom. SourceInfoTraversal node => Ann node dom NormRangeStage -> Ann node dom RngTemplateStage Source #
Creates a source template from the ranges and the input file. All source ranges must be good ranges.
getLocIndices :: SourceInfoTraversal e => Ann e dom RngTemplateStage -> Set (RealSrcLoc, Int) Source #
Assigns an index (in the order they are used) for each range
mapLocIndices :: Ord k => StringBuffer -> Set (RealSrcLoc, k) -> Map k String Source #
Partitions the source file in the order where the parts are used in the AST
fixMainRange :: StringBuffer -> Ann UModule dom RangeStage -> Ann UModule dom RangeStage Source #
extractStayingElems :: SourceInfoTraversal node => Ann node dom SrcTemplateStage -> Ann node dom SrcTemplateStage Source #
Marks template elements in the AST that should always be present in the source code, regardless of their containing elements being deleted. Currently it recognizes CPP pragmas (lines starting with #) This function should only be applied to an AST if CPP is enabled.
sourceTemplateMinimalIndent :: Simple Lens (SpanInfo SrcTemplateStage) Int Source #
srcTmpListMinimalIndent :: Simple Lens (ListInfo SrcTemplateStage) Int Source #
srcTmpOptMinimalIndent :: Simple Lens (OptionalInfo SrcTemplateStage) Int Source #
data TransformationProblem Source #
Constructors
TransformationProblem String |
Instances
Show TransformationProblem Source # | |
Defined in Language.Haskell.Tools.PrettyPrint.Prepare.RangeTemplate Methods showsPrec :: Int -> TransformationProblem -> ShowS # show :: TransformationProblem -> String # showList :: [TransformationProblem] -> ShowS # | |
Exception TransformationProblem Source # | |
data BreakUpProblem Source #
Constructors
BreakUpProblem | |
Fields
|
Instances
Show BreakUpProblem Source # | |
Defined in Language.Haskell.Tools.PrettyPrint.Prepare.RangeToRangeTemplate Methods showsPrec :: Int -> BreakUpProblem -> ShowS # show :: BreakUpProblem -> String # showList :: [BreakUpProblem] -> ShowS # | |
Exception BreakUpProblem Source # | |
Defined in Language.Haskell.Tools.PrettyPrint.Prepare.RangeToRangeTemplate Methods toException :: BreakUpProblem -> SomeException # |