scanner-0.3.1: Fast non-backtracking incremental combinator parsing for bytestrings

Safe Haskell | Safe-Inferred
Language | Haskell2010

Scanner.Internal

Description

Scanner implementation

Synopsis

- newtype Scanner a = Scanner {
  - run :: forall r. ByteString -> Next a r -> Result r
  }
- type Next a r = ByteString -> a -> Result r
- data Result r
  - = Done ByteString r
  - | Fail ByteString String
  - | More (ByteString -> Result r)
- scan :: Scanner r -> ByteString -> Result r
- anyWord8 :: Scanner Word8
- takeWhile :: (Word8 -> Bool) -> Scanner ByteString
- take :: Int -> Scanner ByteString
- endOfInput :: Scanner Bool
- string :: ByteString -> Scanner ()
- lookAhead :: Scanner (Maybe Word8)
- foldlWhile :: (Word8 -> Bool) -> (a -> Word8 -> a) -> a -> Scanner a
- foldlWhile1 :: (Word8 -> Bool) -> (a -> Word8 -> a) -> a -> Scanner a
- satisfy :: (Word8 -> Bool) -> Scanner Word8
- satisfyMaybe :: (Word8 -> Bool) -> Scanner (Maybe Word8)
- decimal :: Integral n => Scanner n

# Documentation

newtype Scanner a Source #

CPS scanner without backtracking

Constructors

Scanner |

Fields

- run :: forall r. ByteString -> Next a r -> Result r

#### Instances

Instances details

MonadFail Scanner Source # |
Instance details Defined in Scanner.Internal Methods fail :: String -> Scanner a Source #
Applicative Scanner Source # |
Instance details Defined in Scanner.Internal Methods pure :: a -> Scanner a Source # (<*>) :: Scanner (a -> b) -> Scanner a -> Scanner b Source # liftA2 :: (a -> b -> c) -> Scanner a -> Scanner b -> Scanner c Source # (*>) :: Scanner a -> Scanner b -> Scanner b Source # (<*) :: Scanner a -> Scanner b -> Scanner a Source #
Functor Scanner Source # |
Instance details Defined in Scanner.Internal Methods fmap :: (a -> b) -> Scanner a -> Scanner b Source # (<$) :: a -> Scanner b -> Scanner a Source #
Monad Scanner Source # |
Instance details Defined in Scanner.Internal Methods (>>=) :: Scanner a -> (a -> Scanner b) -> Scanner b Source # (>>) :: Scanner a -> Scanner b -> Scanner b Source # return :: a -> Scanner a Source #

type Next a r = ByteString -> a -> Result r Source #

Scanner continuation

data Result r Source #

Scanner result

Constructors

Done ByteString r | Successful result with the rest of input
Fail ByteString String | Scanner failed with rest of input and error message
More (ByteString -> Result r) | Need more input

scan :: Scanner r -> ByteString -> Result r Source #

Run scanner with the input

anyWord8 :: Scanner Word8 Source #

Consume the next word

It fails if end of input

takeWhile :: (Word8 -> Bool) -> Scanner ByteString Source #

Take input while the predicate is `True`

take :: Int -> Scanner ByteString Source #

Take the specified number of bytes

endOfInput :: Scanner Bool Source #

Returns `True` when there is no more input

string :: ByteString -> Scanner () Source #

Consume the specified string

Warning: it is not optimized yet, so for for small string it is better to consume it byte-by-byte using `word8`

lookAhead :: Scanner (Maybe Word8) Source #

Return the next byte, if any, without consuming it

foldlWhile :: (Word8 -> Bool) -> (a -> Word8 -> a) -> a -> Scanner a Source #

Fold over the octets, which satisfy the predicate

foldlWhile1 :: (Word8 -> Bool) -> (a -> Word8 -> a) -> a -> Scanner a Source #

Fold over the octets, which satisfy the predicate, ensuring that there's at least one

satisfy :: (Word8 -> Bool) -> Scanner Word8 Source #

Consume a single octet which satisfies the predicate and fail if it does not

satisfyMaybe :: (Word8 -> Bool) -> Scanner (Maybe Word8) Source #

Consume a single octet in case it satisfies the predicate

decimal :: Integral n => Scanner n Source #

Parse a non-negative decimal number in ASCII