trifecta-2.1.4: A modern parser combinator library with convenient diagnostics

Copyright | (C) 2011-2019 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Text.Trifecta.Rope

Description

A rope is a data strucure to efficiently store and manipulate long strings. Wikipedia provides a nice overview: https://en.wikipedia.org/wiki/Rope_(data_structure)

Synopsis

- data Rope = Rope !Delta !(FingerTree Delta Strand)
- rope :: FingerTree Delta Strand -> Rope
- ropeBS :: ByteString -> Rope
- data Strand
  - = Strand !ByteString !Delta
  - | Skipping !Delta
- strand :: ByteString -> Strand
- strands :: Rope -> FingerTree Delta Strand
- grabRest :: Delta -> Rope -> r -> (Delta -> ByteString -> r) -> r
- grabLine :: Delta -> Rope -> r -> (Delta -> ByteString -> r) -> r

# Documentation

data Rope Source #

Constructors

Rope !Delta !(FingerTree Delta Strand) |

#### Instances

Instances details

Monoid Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods mempty :: Rope Source # mappend :: Rope -> Rope -> Rope Source # mconcat :: [Rope] -> Rope Source #
Semigroup Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods (<>) :: Rope -> Rope -> Rope Source # sconcat :: NonEmpty Rope -> Rope Source # stimes :: Integral b => b -> Rope -> Rope Source #
Show Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods showsPrec :: Int -> Rope -> ShowS Source # show :: Rope -> String Source # showList :: [Rope] -> ShowS Source #
HasBytes Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods bytes :: Rope -> Int64 Source #
HasDelta Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods delta :: Rope -> Delta Source #
Measured Delta Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods measure :: Rope -> Delta Source #
Reducer ByteString Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods unit :: ByteString -> Rope Source # snoc :: Rope -> ByteString -> Rope Source # cons :: ByteString -> Rope -> Rope Source #
Reducer Rope Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods unit :: Rope -> Rope Source # snoc :: Rope -> Rope -> Rope Source # cons :: Rope -> Rope -> Rope Source #
Reducer Strand Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods unit :: Strand -> Rope Source # snoc :: Rope -> Strand -> Rope Source # cons :: Strand -> Rope -> Rope Source #
Reducer [Char] Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods unit :: [Char] -> Rope Source # snoc :: Rope -> [Char] -> Rope Source # cons :: [Char] -> Rope -> Rope Source #

rope :: FingerTree Delta Strand -> Rope Source #

ropeBS :: ByteString -> Rope Source #

Construct a `Rope` out of a single `ByteString` strand.

data Strand Source #

Constructors

Strand !ByteString !Delta | Data of a certain length
Skipping !Delta | Absence of data of a certain length

#### Instances

Instances details

Data Strand Source # |

Instance details

Defined in Text.Trifecta.Rope

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Strand -> c Strand Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Strand Source #

toConstr :: Strand -> Constr Source #

dataTypeOf :: Strand -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Strand) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Strand) Source #

gmapT :: (forall b. Data b => b -> b) -> Strand -> Strand Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Strand -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Strand -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Strand -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Strand -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Strand -> m Strand Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Strand -> m Strand Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Strand -> m Strand Source #

Generic Strand Source # |

Instance details

Defined in Text.Trifecta.Rope

Associated Types

type Rep Strand |

Instance details

Defined in Text.Trifecta.Rope

type Rep Strand = D1 ('MetaData "Strand" "Text.Trifecta.Rope" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons "Strand" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta)) :+: C1 ('MetaCons "Skipping" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta)))

Methods

from :: Strand -> Rep Strand x Source #

to :: Rep Strand x -> Strand Source #

Show Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods showsPrec :: Int -> Strand -> ShowS Source # show :: Strand -> String Source # showList :: [Strand] -> ShowS Source #
Eq Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods (==) :: Strand -> Strand -> Bool Source # (/=) :: Strand -> Strand -> Bool Source #
Hashable Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods hashWithSalt :: Int -> Strand -> Int Source # hash :: Strand -> Int Source #
HasBytes Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods bytes :: Strand -> Int64 Source #
HasDelta Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods delta :: Strand -> Delta Source #
Measured Delta Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods measure :: Strand -> Delta Source #
Reducer Strand Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods unit :: Strand -> Rope Source # snoc :: Rope -> Strand -> Rope Source # cons :: Strand -> Rope -> Rope Source #
type Rep Strand Source # |

Instance details

Defined in Text.Trifecta.Rope

type Rep Strand = D1 ('MetaData "Strand" "Text.Trifecta.Rope" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons "Strand" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ByteString) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta)) :+: C1 ('MetaCons "Skipping" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta)))

strand :: ByteString -> Strand Source #

Construct a single `Strand` out of a `ByteString`.

strands :: Rope -> FingerTree Delta Strand Source #

grabRest Source #

Arguments

:: Delta | Initial offset
-> Rope | Input
-> r | Default value if there is no input left
-> (Delta -> ByteString -> r) | If there is some input left, create an `r` out of the data from the initial offset until the end
-> r |

Grab the entire rest of the input `Rope`, starting at an initial offset, or return a default if we’re already at or beyond the end. Also see `grabLine`.

Extract a suffix of a certain length from the input:

    >>> grabRest (delta ("Hello " :: ByteString)) (ropeBS "Hello World\nLorem") Nothing (\x y -> Just (x, Lazy.toString y))
    Just (Columns 6 6,"World\nLorem")

Same deal, but over multiple strands:

    >>> grabRest (delta ("Hel" :: ByteString)) (ropeBS "Hello" <> ropeBS "World") Nothing (\x y -> Just (x, Lazy.toString y))
    Just (Columns 3 3,"loWorld")

When the offset is too long, fall back to a default:

    >>> grabRest (delta ("OffetTooLong" :: ByteString)) (ropeBS "Hello") Nothing (\x y -> Just (x, Lazy.toString y))
    Nothing

grabLine Source #

Arguments

:: Delta | Initial offset
-> Rope | Input
-> r | Default value if there is no input left
-> (Delta -> ByteString -> r) | If there is some input left, create an `r` out of the data from the initial offset until the end of the line
-> r |

Grab the rest of the line at a certain offset in the input `Rope`, or return a default if there is no newline left in the input. Also see `grabRest`.

    >>> grabLine (delta ("Hello " :: ByteString)) (ropeBS "Hello" <> ropeBS " World\nLorem") Nothing (\x y -> Just (x, Strict.toString y))
    Just (Columns 6 6,"World\n")