HaRe-0.7.2.6: the Haskell Refactorer.

Safe HaskellNone

Language.Haskell.Refact.Utils.TokenUtils

Contents

Description

This module contains an API to manage a token stream.

This API is used internally by MonadFunctions and the other utility modules, it should probably never be used directly in a refactoring.

Synopsis

Operations at TokenCache level

syncAstToLatestCache :: Data t => TokenCache PosToken -> Located t -> Located tSource

Assuming most recent operation has stashed the old tokens, sync the given AST to the most recent stash entry

Operations at Tree Entry level

addDeclToksAfterSrcSpanSource

Arguments

:: Data t 
=> Tree (Entry PosToken)

TokenTree to be modified

-> SrcSpan

Preceding location for new tokens

-> Positioning 
-> [PosToken]

New tokens to be added

-> Located t

Declaration the tokens belong to, to be synced

-> (Tree (Entry PosToken), SrcSpan, Located t)

updated TokenTree ,SrcSpan location for -> (Tree (Entry PosToken), GHC.SrcSpan,t) -- ^ updated TokenTree ,SrcSpan location for the new tokens in the TokenTree, and updated AST element

Add new tokens belonging to an AST fragment after a given SrcSpan, and re-sync the AST fragment to match the new location

syncASTSource

Arguments

:: Data t 
=> Located t

The AST (or fragment)

-> ForestSpan

The SrcSpan created in the Tree (Entry PosToken)

-> Located t

Updated AST and tokens

Synchronise a located AST fragment to use a newly created SrcSpan in the token tree. TODO: Should this indent the tokens as well?

Utility

posToSrcSpan :: Tree (Entry PosToken) -> (SimpPos, SimpPos) -> SrcSpanSource

Convert a simple (start,end) position to a SrcSpan belonging to the file in the tree

posToSrcSpanTok :: PosToken -> (SimpPos, SimpPos) -> SrcSpanSource

Convert a simple (start,end) position to a SrcSpan belonging to the file in the given token

Internal, for testing

nonCommentSpan :: IsToken a => [a] -> (SimpPos, SimpPos)

Extract the start and end position of a span, without any leading or trailing comments

deleteGapsToks :: [Entry PosToken] -> [PosToken]Source

Process the leaf nodes of a tree to remove all deleted spans