parsnip-0: A fast, minimal parser
Safe HaskellNone
LanguageHaskell2010

Text.Parsnip.Parser

Synopsis

Documentation

data Parser s a Source #

Instances

Instances details
Monad (Parser s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Parser

Methods

(>>=) :: Parser s a -> (a -> Parser s b) -> Parser s b #

(>>) :: Parser s a -> Parser s b -> Parser s b #

return :: a -> Parser s a #

Functor (Parser s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Parser

Methods

fmap :: (a -> b) -> Parser s a -> Parser s b #

(<$) :: a -> Parser s b -> Parser s a #

Applicative (Parser s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Parser

Methods

pure :: a -> Parser s a #

(<*>) :: Parser s (a -> b) -> Parser s a -> Parser s b #

liftA2 :: (a -> b -> c) -> Parser s a -> Parser s b -> Parser s c #

(*>) :: Parser s a -> Parser s b -> Parser s b #

(<*) :: Parser s a -> Parser s b -> Parser s a #

Alternative (Parser s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Parser

Methods

empty :: Parser s a #

(<|>) :: Parser s a -> Parser s a -> Parser s a #

some :: Parser s a -> Parser s [a] #

many :: Parser s a -> Parser s [a] #

MonadPlus (Parser s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Parser

Methods

mzero :: Parser s a #

mplus :: Parser s a -> Parser s a -> Parser s a #

PrimMonad (Parser s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Parser

Associated Types

type PrimState (Parser s)

Methods

primitive :: (State# (PrimState (Parser s)) -> (# State# (PrimState (Parser s)), a #)) -> Parser s a

a ~ ByteString => IsString (Parser s a) Source # 
Instance details

Defined in Text.Parsnip.Internal.Parser

Methods

fromString :: String -> Parser s a #

type PrimState (Parser s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Parser

type PrimState (Parser s) = s

class KnownBase (s :: Type) Source #

Minimal complete definition

reflectBase

parse :: (forall s. KnownBase s => Parser s a) -> ByteString -> Either Location a Source #

try :: Parser s a -> Parser s a Source #

skip :: forall s. KnownBase s => Int -> Parser s () Source #

We can do this two ways, this way is O(1) but needs KnownBase.

skip0 :: Int -> Parser s () Source #

Linear time, but no KnownBase dependency.

take :: forall s. KnownBase s => Int -> Parser s ByteString Source #

data Mark s Source #

Instances

Instances details
KnownBase s => Bounded (Mark s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Mark

Methods

minBound :: Mark s #

maxBound :: Mark s #

KnownBase s => Enum (Mark s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Mark

Methods

succ :: Mark s -> Mark s #

pred :: Mark s -> Mark s #

toEnum :: Int -> Mark s #

fromEnum :: Mark s -> Int #

enumFrom :: Mark s -> [Mark s] #

enumFromThen :: Mark s -> Mark s -> [Mark s] #

enumFromTo :: Mark s -> Mark s -> [Mark s] #

enumFromThenTo :: Mark s -> Mark s -> Mark s -> [Mark s] #

Eq (Mark s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Mark

Methods

(==) :: Mark s -> Mark s -> Bool #

(/=) :: Mark s -> Mark s -> Bool #

Ord (Mark s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Mark

Methods

compare :: Mark s -> Mark s -> Ordering #

(<) :: Mark s -> Mark s -> Bool #

(<=) :: Mark s -> Mark s -> Bool #

(>) :: Mark s -> Mark s -> Bool #

(>=) :: Mark s -> Mark s -> Bool #

max :: Mark s -> Mark s -> Mark s #

min :: Mark s -> Mark s -> Mark s #

Show (Mark s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Mark

Methods

showsPrec :: Int -> Mark s -> ShowS #

show :: Mark s -> String #

showList :: [Mark s] -> ShowS #

Ix (Mark s) Source # 
Instance details

Defined in Text.Parsnip.Internal.Mark

Methods

range :: (Mark s, Mark s) -> [Mark s] #

index :: (Mark s, Mark s) -> Mark s -> Int #

unsafeIndex :: (Mark s, Mark s) -> Mark s -> Int #

inRange :: (Mark s, Mark s) -> Mark s -> Bool #

rangeSize :: (Mark s, Mark s) -> Int #

unsafeRangeSize :: (Mark s, Mark s) -> Int #

mark :: Parser s (Mark s) Source #

Record the current position

release :: Mark s -> Parser s () Source #

Return to a previous location.

snip :: forall s. KnownBase s => Mark s -> Mark s -> ByteString Source #

To grab all the text covered by a given parser, consider using snipping and applying it to a combinator simply recognizes the content rather than returns it. snipping a ByteString is significantly cheaper than assembling one from smaller fragments.

snipping :: forall s a. KnownBase s => Parser s a -> Parser s ByteString Source #

input :: KnownBase s => Parser s ByteString Source #

input = snip minBound maxBound

pos :: forall s. KnownBase s => Parser s Int Source #

mark is generally faster

betwixt :: forall s. KnownBase s => Int -> Int -> ByteString Source #

snip is a smidge faster, easier to type, if less fun to say, and doesn't need you to fiddle with explicit type application to actually apply.

The benefit of this combinator is that it is easy to come up with numbers of bytes into a file, and this combinator will automatically trim the result to the actual range of bytes available, whereas constructing an illegal Mark will error in toEnumfromEnumsucc or whatever other combinator tries to produce one out of range to maintain the invariant that a mark is always a well formed location in the content.

rest :: KnownBase s => Parser s ByteString Source #

rest = mark >>= p -> snip p maxBound