Safe Haskell | None |
---|
- data BufLoc = BufLoc Int Int
- data BufSpan = BufSpan BufLoc BufLoc
- type LineBuf = [String]
- spanStart :: BufSpan -> BufLoc
- spanEnd :: BufSpan -> BufLoc
- unpackRealSrcSpan :: RealSrcSpan -> (FilePath, BufSpan)
- packRealSrcSpan :: (FilePath, BufSpan) -> RealSrcSpan
- normalisePath :: FilePath -> FilePath -> FilePath
- showSpan :: Maybe FilePath -> (FilePath, BufSpan) -> String
- str2LineBuf :: String -> LineBuf
- lineBuf2Str :: LineBuf -> String
- type Indentation = Int
- getIndentation :: LineBuf -> Indentation
- compareByStartLoc :: RealSrcSpan -> RealSrcSpan -> Ordering
- toBufLoc :: RealSrcLoc -> BufLoc
- toBufSpan :: RealSrcSpan -> BufSpan
- pointBufSpan :: Int -> Int -> BufSpan
- splitAtBufLoc :: LineBuf -> BufLoc -> (LineBuf, LineBuf)
- splitBufferedLinesAtBufSpan :: LineBuf -> BufSpan -> (LineBuf, LineBuf, LineBuf)
- leq :: RealSrcSpan -> RealSrcSpan -> Bool
- disjoint :: RealSrcSpan -> RealSrcSpan -> Bool
- joinSplit :: ([String], [String]) -> [String]
- reassembleSplit :: ([String], [String], [String]) -> [String]
Documentation
This is just the combination of a line number and a column number.
BufLoc Int Int | BufLoc line column |
A BufSpan is simply defined by two times a BufLoc.
This is a file/text portion buffered as list of lines.
Line buffers are used to avoid repeated IO operations and to describe line-oriented content (for example at assembling the TTree).
unpackRealSrcSpan :: RealSrcSpan -> (FilePath, BufSpan)Source
Deconstructs a RealSrcSpan to the types more often used in libhbb.
packRealSrcSpan :: (FilePath, BufSpan) -> RealSrcSpanSource
:: FilePath | The current working dir (to make pathes relative) |
-> FilePath | The path that should be adapted |
-> FilePath |
:: Maybe FilePath | The current working dir (to force relative pathes) |
-> (FilePath, BufSpan) | The location to convert to a string |
-> String |
This function converts a location in the form libhbb uses it into a
string. The string has the format that is used by 'occurrences-of' and
locate
to report locations to the client.
str2LineBuf :: String -> LineBufSource
This is an auxiliary function that splits a string at all newlines.
Note that lines from Prelude cannot be used here. The reason is following example:
lines "| ->\n" = ["| ->"] str2LineBuf "| ->\n" = ["| ->",""]
lineBuf2Str :: LineBuf -> StringSource
Converts a line buffer to a string.
Note that unlines
doesn't work here because it doesn't treat the last line
correctly.
type Indentation = IntSource
This alias can be used to have a meaningful name for indentations.
getIndentation :: LineBuf -> IndentationSource
For a line buffer this function returns the number of spaces charachters of the line with the smallest indentation.
compareByStartLoc :: RealSrcSpan -> RealSrcSpan -> OrderingSource
Compares two non-overlapping RealSrcSpan elements by their starting location.
toBufLoc :: RealSrcLoc -> BufLocSource
Converts a RealSrcLoc into a BufLoc effectively throwing away the filename.
toBufSpan :: RealSrcSpan -> BufSpanSource
Converts a RealSrcSpan into a BufSpan effectively throwing away the filename.
pointBufSpan :: Int -> Int -> BufSpanSource
Creates a BufSpan where the first and the last BufLoc is the same.
The first parameter is the line and the second one is the column.
splitAtBufLoc :: LineBuf -> BufLoc -> (LineBuf, LineBuf)Source
This function splits the passed lines (of a file-cache) at the position passed as second parameter.
Note that the line- and column-counts start with 1 (this is GHC behaviour). The split contains the character pointed to by the BufLoc in the right part of the tuple.
This means that (in case of line=1 and column=1) following applies:
splitAtBufLoc "hello world" loc == ([""],["hello world"])
splitBufferedLinesAtBufSpan :: LineBuf -> BufSpan -> (LineBuf, LineBuf, LineBuf)Source
This function splits a number of input lines in a way so that the area located to by the passed source span is isolated.
The three areas in the return tuple are:
- Initial lines (they come first)
- Subject lines (they are between the locations)
- Trailing lines (they come after the last location)
The last line of initLines and the first line of subjLines must be joined to reproduce the output. The same applies to subjLines and traiLines...
leq :: RealSrcSpan -> RealSrcSpan -> BoolSource
This function returns true if the first RealSrcSpan points to a region that is located before the one pointed to by the second RealSrcSpan.
The two spans must be disjoint otherwise the results are undefined (can be
checked with the function disjoint
)!
disjoint :: RealSrcSpan -> RealSrcSpan -> BoolSource
This function returns true when the two passed RealSrcSpans do not overlap.
This means that the end of the first RealSrcSpan is smaller or equal to the start of the second RealSrcSpan and vice versa.
joinSplit :: ([String], [String]) -> [String]Source
This function is the opposite of splitAtBufLoc.
It can rejoin a split concerning that the last and the first line in the frist respective second element of the split tuple must be joined by string concatenation. This function has been designed to run with linear time complexity.
reassembleSplit :: ([String], [String], [String]) -> [String]Source
This function combines two times joinSplit to be able to join lines that have been split by a SrcSpan.