Safe Haskell | None |
---|
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.
- putDeclToksInCache :: Data t => TokenCache PosToken -> SrcSpan -> [PosToken] -> Located t -> (TokenCache PosToken, SrcSpan, Located t)
- syncAstToLatestCache :: Data t => TokenCache PosToken -> Located t -> Located t
- addDeclToksAfterSrcSpan :: Data t => Tree (Entry PosToken) -> SrcSpan -> Positioning -> [PosToken] -> Located t -> (Tree (Entry PosToken), SrcSpan, Located t)
- syncAST :: Data t => Located t -> ForestSpan -> Located t
- posToSrcSpan :: Tree (Entry PosToken) -> (SimpPos, SimpPos) -> SrcSpan
- posToSrcSpanTok :: PosToken -> (SimpPos, SimpPos) -> SrcSpan
- nonCommentSpan :: IsToken a => [a] -> (SimpPos, SimpPos)
- showSrcSpan :: SrcSpan -> String
- showSrcSpanF :: SrcSpan -> String
- ghcSpanStartEnd :: SrcSpan -> ((Int, Int), (Int, Int))
- stripForestLineFromGhc :: SrcSpan -> SrcSpan
- ghcSrcSpanToForestSpan :: SrcSpan -> ForestSpan
- deleteGapsToks :: [Entry PosToken] -> [PosToken]
Operations at TokenCache
level
putDeclToksInCache :: Data t => TokenCache PosToken -> SrcSpan -> [PosToken] -> Located t -> (TokenCache PosToken, SrcSpan, Located t)Source
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
:: 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
:: 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
showSrcSpan :: SrcSpan -> String
showSrcSpanF :: SrcSpan -> String
deleteGapsToks :: [Entry PosToken] -> [PosToken]Source
Process the leaf nodes of a tree to remove all deleted spans