trifecta-2.1.2: A modern parser combinator library with convenient diagnostics
Copyright(C) 2011-2019 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Documentation

data Rope Source #

Constructors

Rope !Delta !(FingerTree Delta Strand) 

Instances

Instances details
Show Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

showsPrec :: Int -> Rope -> ShowS #

show :: Rope -> String #

showList :: [Rope] -> ShowS #

Semigroup Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

(<>) :: Rope -> Rope -> Rope #

sconcat :: NonEmpty Rope -> Rope #

stimes :: Integral b => b -> Rope -> Rope #

Monoid Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

mempty :: Rope #

mappend :: Rope -> Rope -> Rope #

mconcat :: [Rope] -> Rope #

HasDelta Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

delta :: Rope -> Delta Source #

HasBytes Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

bytes :: Rope -> Int64 Source #

Measured Delta Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

measure :: Rope -> Delta #

Reducer ByteString Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Reducer Rope Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

unit :: Rope -> Rope #

snoc :: Rope -> Rope -> Rope #

cons :: Rope -> Rope -> Rope #

Reducer Strand Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

unit :: Strand -> Rope #

snoc :: Rope -> Strand -> Rope #

cons :: Strand -> Rope -> Rope #

Reducer [Char] Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

unit :: [Char] -> Rope #

snoc :: Rope -> [Char] -> Rope #

cons :: [Char] -> Rope -> Rope #

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
Eq Strand Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

(==) :: Strand -> Strand -> Bool #

(/=) :: Strand -> Strand -> Bool #

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 #

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

toConstr :: Strand -> Constr #

dataTypeOf :: Strand -> DataType #

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

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

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

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

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

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

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

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

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

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

Show Strand Source # 
Instance details

Defined in Text.Trifecta.Rope

Generic Strand Source # 
Instance details

Defined in Text.Trifecta.Rope

Associated Types

type Rep Strand :: Type -> Type #

Methods

from :: Strand -> Rep Strand x #

to :: Rep Strand x -> Strand #

Hashable Strand Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

hashWithSalt :: Int -> Strand -> Int #

hash :: Strand -> Int #

HasDelta Strand Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

delta :: Strand -> Delta Source #

HasBytes Strand Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

bytes :: Strand -> Int64 Source #

Measured Delta Strand Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

measure :: Strand -> Delta #

Reducer Strand Rope Source # 
Instance details

Defined in Text.Trifecta.Rope

Methods

unit :: Strand -> Rope #

snoc :: Rope -> Strand -> Rope #

cons :: Strand -> Rope -> Rope #

type Rep Strand Source # 
Instance details

Defined in Text.Trifecta.Rope

strand :: ByteString -> Strand Source #

Construct a single Strand out of a ByteString.

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")