Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Point = Point {
- pointLine :: Int
- pointColumn :: Int
- (.-.) :: Point -> Point -> Point
- (.+.) :: Point -> Point -> Point
- type Size = Point
- linesSize :: Int -> Point
- stringSize :: Int -> Point
- data Region = Region {
- regionFrom :: Point
- regionTo :: Point
- regionLines :: Region -> Int
- emptyRegion :: Region -> Bool
- line :: Int -> Region
- region :: Point -> Point -> Region
- regionSize :: Point -> Size -> Region
- at :: Editable a => Contents a -> Region -> Contents a
- newtype Map = Map {}
- apply :: Map -> Region -> Region
- back :: Map -> Map
- cut :: Region -> Map
- insert :: Region -> Map
- cutRegion :: Region -> Region -> Region
- insertRegion :: Region -> Region -> Region
- type Contents a = [a]
- data Edit a = Edit {}
- newtype EditM s a = EditM {}
- editRegion :: Region -> (Region -> Edit a) -> EditM a ()
- mapRegion :: Region -> EditM a Region
- runEdit :: Editable s => EditM s a -> (a, Edit s)
- edit :: Editable s => s -> EditM s a -> s
- editEval :: Editable s => s -> EditM s a -> (a, s)
- data Prefix a = Prefix {
- prefixLines :: [a]
- prefixLine :: a
- prefix :: Contents a -> Prefix a
- data Suffix a = Suffix {
- suffixLine :: a
- suffixLines :: [a]
- suffix :: Contents a -> Suffix a
- concatCts :: Monoid a => Prefix a -> Suffix a -> Contents a
- splitCts :: Editable a => Point -> Contents a -> (Prefix a, Suffix a)
- class Monoid a => Editable a where
- measure :: Editable s => Contents s -> Size
- erase :: Editable s => Region -> EditM s ()
- write :: Editable s => Point -> Contents s -> EditM s ()
- replace :: Editable s => Region -> Contents s -> EditM s ()
- data Replace s = Replace {
- replaceRegion :: Region
- replaceWith :: Contents s
- eraser :: Monoid s => Region -> Replace s
- writer :: Editable s => Point -> s -> Replace s
- replacer :: Editable s => Region -> s -> Replace s
- run :: Editable s => [Replace s] -> EditM s ()
Documentation
Point at text: line and column
Point | |
|
(.-.) :: Point -> Point -> Point Source
Distance between points is measured in lines and columns.
And it is defined, that distance between point at l:c and point (l + 1):0 is one line no matter c is
because we need to go to new line to reach destination point
Columns are taken into account only if points are on the same line
pt .-. base
is distance from base
to pt
Distance can't be less then zero lines and columns
stringSize :: Int -> Point Source
Distance in n
chars within one line
Region | |
|
emptyRegion :: Region -> Bool Source
Is Region empty
n'th line region, starts at the beginning of line and ends on the next line
regionSize :: Point -> Size -> Region Source
Make region from starting point and its size
Mappings
Main idea is that there are only two basic actions , that chances regions: inserting and cutting When something is cutted out or inserted in, region positions must be updated All editings can be represented as many cuts and inserts, so we can combine them to get function which maps source regions to regions on updated data Because insert is dual to cut (and therefore composes iso), we can also get function to map regions back Combining this functions while edit, we get function, that maps regions from source data to edited one To get back function, we must also combine opposite actions, or we can represent actions as isomorphisms Same idea goes for modifying contents, represent each action as isomorphism and combine them together
cutRegion :: Region -> Region -> Region Source
Update second region position as if it was data cutted at first region
insertRegion :: Region -> Region -> Region Source
Update second region position as if it was data inserted at first region
Edited data
Edit data
Edit | Map region from source contents to edited |
Monoid (Edit a) | |
MonadState (Edit s) (EditM s) |
Edit monad is state on Edit, it also collects region mappings
Monad (EditM s) | |
Functor (EditM s) | |
Applicative (EditM s) | |
MonadState (Edit s) (EditM s) |
editRegion :: Region -> (Region -> Edit a) -> EditM a () Source
Basic edit action in monad It takes region, region edit function and contents updater and passes mapped region to these functions to get new state
Prefix of contents cutted at some point
Prefix | |
|
Suffix of contents
Suffix | |
|
concatCts :: Monoid a => Prefix a -> Suffix a -> Contents a Source
Concat prefix and suffix. First line of suffix is appended to last line of prefix
splitCts :: Editable a => Point -> Contents a -> (Prefix a, Suffix a) Source
Split contents at point. First argument is function to split one line at position.
Editable class
Actions
Replace action
Replace | |
|