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.Delta

Description

A `Delta` keeps track of the cursor position of the parser, so it can be referred to later, for example in error messages.

Synopsis

- data Delta
  - = Columns !Int64 !Int64
  - | Tab !Int64 !Int64 !Int64
  - | Lines !Int64 !Int64 !Int64 !Int64
  - | Directed !ByteString !Int64 !Int64 !Int64 !Int64
- class HasDelta t where
  - delta :: t -> Delta
- class HasBytes t where
  - bytes :: t -> Int64
- prettyDelta :: Delta -> Doc AnsiStyle
- nextTab :: Int64 -> Int64
- rewind :: Delta -> Delta
- near :: (HasDelta s, HasDelta t) => s -> t -> Bool
- column :: HasDelta t => t -> Int64
- columnByte :: Delta -> Int64

# Documentation

data Delta Source #

Since there are multiple ways to be at a certain location, `Delta` captures all these alternatives as a single type.

Constructors

Columns !Int64 !Int64

    ( number of characters
    , number of bytes )

Tab !Int64 !Int64 !Int64

    ( number of characters before the tab
    , number of characters after the tab
    , number of bytes )

Lines !Int64 !Int64 !Int64 !Int64

    ( number of newlines contained
    , number of characters since the last newline
    , number of bytes
    , number of bytes since the last newline )

Directed !ByteString !Int64 !Int64 !Int64 !Int64

    ( current file name
    , number of lines since the last line directive
    , number of characters since the last newline
    , number of bytes
    , number of bytes since the last newline )

#### Instances

Instances details

Monoid Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods mempty :: Delta Source # mappend :: Delta -> Delta -> Delta Source # mconcat :: [Delta] -> Delta Source #
Semigroup Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods (<>) :: Delta -> Delta -> Delta Source # sconcat :: NonEmpty Delta -> Delta Source # stimes :: Integral b => b -> Delta -> Delta Source #
Data Delta Source # |

Instance details

Defined in Text.Trifecta.Delta

Methods

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

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

toConstr :: Delta -> Constr Source #

dataTypeOf :: Delta -> DataType Source #

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

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

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

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

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

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

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

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

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

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

Generic Delta Source # |

Instance details

Defined in Text.Trifecta.Delta

Associated Types

type Rep Delta |

Instance details

Defined in Text.Trifecta.Delta

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

Methods

from :: Delta -> Rep Delta x Source #

to :: Rep Delta x -> Delta Source #

Show Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods showsPrec :: Int -> Delta -> ShowS Source # show :: Delta -> String Source # showList :: [Delta] -> ShowS Source #
Eq Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods (==) :: Delta -> Delta -> Bool Source # (/=) :: Delta -> Delta -> Bool Source #
Ord Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods compare :: Delta -> Delta -> Ordering Source # (<) :: Delta -> Delta -> Bool Source # (<=) :: Delta -> Delta -> Bool Source # (>) :: Delta -> Delta -> Bool Source # (>=) :: Delta -> Delta -> Bool Source # max :: Delta -> Delta -> Delta Source # min :: Delta -> Delta -> Delta Source #
Hashable Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods hashWithSalt :: Int -> Delta -> Int Source # hash :: Delta -> Int Source #
HasBytes Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods bytes :: Delta -> Int64 Source #
HasDelta Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods delta :: Delta -> Delta Source #
Measured Delta Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods measure :: Rope -> Delta Source #
Measured Delta Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods measure :: Strand -> Delta Source #
MarkParsing Delta Parser Source # |
Instance details Defined in Text.Trifecta.Parser Methods mark :: Parser Delta Source # release :: Delta -> Parser () Source #
type Rep Delta Source # |

Instance details

Defined in Text.Trifecta.Delta

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

class HasDelta t where Source #

Methods

delta :: t -> Delta Source #

#### Instances

Instances details

HasDelta ByteString Source # |
Instance details Defined in Text.Trifecta.Delta Methods delta :: ByteString -> Delta Source #
HasDelta Word8 Source # |
Instance details Defined in Text.Trifecta.Delta Methods delta :: Word8 -> Delta Source #
HasDelta Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods delta :: Delta -> Delta Source #
HasDelta HighlightedRope Source # |
Instance details Defined in Text.Trifecta.Highlight Methods delta :: HighlightedRope -> Delta Source #
HasDelta Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods delta :: Caret -> Delta Source #
HasDelta Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods delta :: Rendering -> Delta Source #
HasDelta Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods delta :: Rope -> Delta Source #
HasDelta Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods delta :: Strand -> Delta Source #
HasDelta Char Source # |
Instance details Defined in Text.Trifecta.Delta Methods delta :: Char -> Delta Source #
HasDelta (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods delta :: Careted a -> Delta Source #
HasDelta (Rendered a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods delta :: Rendered a -> Delta Source #
(Measured v a, HasDelta v) => HasDelta (FingerTree v a) Source # |
Instance details Defined in Text.Trifecta.Delta Methods delta :: FingerTree v a -> Delta Source #
(HasDelta l, HasDelta r) => HasDelta (Either l r) Source # |
Instance details Defined in Text.Trifecta.Delta Methods delta :: Either l r -> Delta Source #

class HasBytes t where Source #

Methods

bytes :: t -> Int64 Source #

#### Instances

Instances details

HasBytes ByteString Source # |
Instance details Defined in Text.Trifecta.Delta Methods bytes :: ByteString -> Int64 Source #
HasBytes Delta Source # |
Instance details Defined in Text.Trifecta.Delta Methods bytes :: Delta -> Int64 Source #
HasBytes HighlightedRope Source # |
Instance details Defined in Text.Trifecta.Highlight Methods bytes :: HighlightedRope -> Int64 Source #
HasBytes Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods bytes :: Caret -> Int64 Source #
HasBytes Rope Source # |
Instance details Defined in Text.Trifecta.Rope Methods bytes :: Rope -> Int64 Source #
HasBytes Strand Source # |
Instance details Defined in Text.Trifecta.Rope Methods bytes :: Strand -> Int64 Source #
HasBytes (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods bytes :: Careted a -> Int64 Source #
HasBytes (Rendered a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods bytes :: Rendered a -> Int64 Source #
(Measured v a, HasBytes v) => HasBytes (FingerTree v a) Source # |
Instance details Defined in Text.Trifecta.Delta Methods bytes :: FingerTree v a -> Int64 Source #

prettyDelta :: Delta -> Doc AnsiStyle Source #

Example: `file.txt:12:34`

nextTab :: Int64 -> Int64 Source #

Increment a column number to the next tabstop.

rewind :: Delta -> Delta Source #

Rewind a `Delta` to the beginning of the line.

near :: (HasDelta s, HasDelta t) => s -> t -> Bool Source #

Should we show two things with a `Delta` on the same line?

    >>> near (Columns 0 0) (Columns 5 5)
    True

    >>> near (Lines 1 0 1 0) (Lines 2 4 4 2)
    False

column :: HasDelta t => t -> Int64 Source #

Retrieve the character offset within the current line from this `Delta`.

columnByte :: Delta -> Int64 Source #

Retrieve the byte offset within the current line from this `Delta`.