Safe Haskell | None |
---|---|
Language | Haskell2010 |
This reworks Stream
to split interfaces.
See https://hackage.haskell.org/package/megaparsec-9.0.1/docs/Text-Megaparsec-Stream.html
Synopsis
- class Monoid chunk => Chunked chunk token | chunk -> token where
- consChunk :: token -> chunk -> chunk
- unconsChunk :: chunk -> Maybe (token, chunk)
- tokenToChunk :: token -> chunk
- tokensToChunk :: [token] -> chunk
- chunkToTokens :: chunk -> [token]
- chunkLength :: chunk -> Int
- chunkEmpty :: chunk -> Bool
- class Chunked (Chunk s) (Token s) => Stream s where
- type Chunk s :: Type
- type Token s :: Type
- streamTake1 :: s -> Maybe (Token s, s)
- streamTakeN :: Int -> s -> Maybe (Chunk s, s)
- streamTakeWhile :: (Token s -> Bool) -> s -> (Chunk s, s)
- streamDropN :: Int -> s -> Maybe (Int, s)
- streamDropWhile :: (Token s -> Bool) -> s -> (Int, s)
- defaultStreamDropN :: Stream s => Int -> s -> Maybe (Int, s)
- defaultStreamDropWhile :: Stream s => (Token s -> Bool) -> s -> (Int, s)
- data OffsetStream s = OffsetStream {}
- newOffsetStream :: s -> OffsetStream s
Documentation
class Monoid chunk => Chunked chunk token | chunk -> token where Source #
Chunked
captures the basic relationship between tokens and chunks of them.
Basically, these things behave like lists, sequences, text, etc.
consChunk :: token -> chunk -> chunk Source #
unconsChunk :: chunk -> Maybe (token, chunk) Source #
tokenToChunk :: token -> chunk Source #
tokensToChunk :: [token] -> chunk Source #
chunkToTokens :: chunk -> [token] Source #
chunkLength :: chunk -> Int Source #
chunkEmpty :: chunk -> Bool Source #
Instances
Chunked Text Char Source # | |
Defined in SimpleParser.Stream | |
Chunked [a] a Source # | |
Defined in SimpleParser.Stream consChunk :: a -> [a] -> [a] Source # unconsChunk :: [a] -> Maybe (a, [a]) Source # tokenToChunk :: a -> [a] Source # tokensToChunk :: [a] -> [a] Source # chunkToTokens :: [a] -> [a] Source # chunkLength :: [a] -> Int Source # chunkEmpty :: [a] -> Bool Source # | |
Chunked (Seq a) a Source # | |
Defined in SimpleParser.Stream |
class Chunked (Chunk s) (Token s) => Stream s where Source #
Stream
lets us peel off tokens and chunks for parsing
with explicit state passing.
streamTake1 :: s -> Maybe (Token s, s) Source #
streamTakeN :: Int -> s -> Maybe (Chunk s, s) Source #
streamTakeWhile :: (Token s -> Bool) -> s -> (Chunk s, s) Source #
streamDropN :: Int -> s -> Maybe (Int, s) Source #
streamDropWhile :: (Token s -> Bool) -> s -> (Int, s) Source #
Instances
data OffsetStream s Source #
Instances
newOffsetStream :: s -> OffsetStream s Source #