Scanner.Internal

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

Safe Haskell | None
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)

# Documentation

newtype Scanner a #

CPS scanner without backtracking

Constructors

Scanner |
Fields run :: forall r. ByteString -> Next a r -> Result r

Instances

Monad Scanner # |
Methods (>>=) :: Scanner a -> (a -> Scanner b) -> Scanner b # (>>) :: Scanner a -> Scanner b -> Scanner b # return :: a -> Scanner a # fail :: String -> Scanner a #
Functor Scanner # |
Methods fmap :: (a -> b) -> Scanner a -> Scanner b # (<$) :: a -> Scanner b -> Scanner a #
Applicative Scanner # |
Methods pure :: a -> Scanner a # (<*>) :: Scanner (a -> b) -> Scanner a -> Scanner b # liftA2 :: (a -> b -> c) -> Scanner a -> Scanner b -> Scanner c # (*>) :: Scanner a -> Scanner b -> Scanner b # (<*) :: Scanner a -> Scanner b -> Scanner a #

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

Scanner continuation

data Result r #

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 #

Run scanner with the input

anyWord8 :: Scanner Word8 #

Consume the next word

It fails if end of input

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

Take input while the predicate is `True`

take :: Int -> Scanner ByteString #

Take the specified number of bytes

endOfInput :: Scanner Bool #

Returns `True` when there is no more input

string :: ByteString -> Scanner () #

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

Return the next byte, if any, without consuming it