-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Simple parser combinators
--
-- Please see the README on GitHub at
-- https://github.com/ejconlon/simple-parser#readme
@package simple-parser
@version 0.5.0
module SimpleParser.Chunked
-- | Chunked captures the basic relationship between tokens and
-- chunks of them. Basically, these things behave like lists, sequences,
-- text, etc.
class Monoid chunk => Chunked chunk token | chunk -> token
consChunk :: Chunked chunk token => token -> chunk -> chunk
unconsChunk :: Chunked chunk token => chunk -> Maybe (token, chunk)
tokenToChunk :: Chunked chunk token => token -> chunk
tokensToChunk :: Chunked chunk token => [token] -> chunk
chunkToTokens :: Chunked chunk token => chunk -> [token]
chunkLength :: Chunked chunk token => chunk -> Int
chunkEmpty :: Chunked chunk token => chunk -> Bool
-- | Some datatypes (like Seq) may admit a "better" implementation
-- for building a chunk in reverse.
revTokensToChunk :: Chunked chunk token => [token] -> chunk
-- | Captures textual streams.
class Chunked chunk Char => TextualChunked chunk
buildChunk :: TextualChunked chunk => chunk -> Builder
packChunk :: TextualChunked chunk => chunk -> Text
unpackChunk :: TextualChunked chunk => Text -> chunk
instance (a GHC.Types.~ GHC.Types.Char) => SimpleParser.Chunked.TextualChunked [a]
instance (a GHC.Types.~ GHC.Types.Char) => SimpleParser.Chunked.TextualChunked (Data.Sequence.Internal.Seq a)
instance SimpleParser.Chunked.TextualChunked Data.Text.Internal.Text
instance SimpleParser.Chunked.Chunked [a] a
instance SimpleParser.Chunked.Chunked (Data.Sequence.Internal.Seq a) a
instance SimpleParser.Chunked.Chunked Data.Text.Internal.Text GHC.Types.Char
module SimpleParser.Stack
-- | A stack supporting O(1) push, top, and bottom. Behind the newtype, a
-- "push" onto the stack is implemented as "snoc", therefore
-- fold/traverse goes from bottom of stack (most generic label) to top
-- (most specific label).
newtype Stack a
Stack :: Seq a -> Stack a
[unStack] :: Stack a -> Seq a
-- | Easy constructor for the empty stack
emptyStack :: Stack a
-- | Pushes a an element onto a Stack
pushStack :: a -> Stack a -> Stack a
-- | Returns the top element of the stack (most recently pushed).
topStack :: Stack a -> Maybe a
-- | Returns the bottom element of the stack (least recently pushed).
bottomStack :: Stack a -> Maybe a
instance Data.Traversable.Traversable SimpleParser.Stack.Stack
instance Data.Foldable.Foldable SimpleParser.Stack.Stack
instance GHC.Base.Functor SimpleParser.Stack.Stack
instance GHC.Show.Show a => GHC.Show.Show (SimpleParser.Stack.Stack a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (SimpleParser.Stack.Stack a)
-- | This reworks Stream to split interfaces. See
-- Text.Megaparsec.Stream.
module SimpleParser.Stream
-- | Stream lets us peel off tokens and chunks for parsing with
-- explicit state passing.
class Chunked (Chunk s) (Token s) => Stream s where {
type family Chunk s :: Type;
type family Token s :: Type;
type family Pos s :: Type;
}
streamViewPos :: Stream s => s -> Pos s
streamTake1 :: Stream s => s -> Maybe (Token s, s)
streamTakeN :: Stream s => Int -> s -> Maybe (Chunk s, s)
streamTakeWhile :: Stream s => (Token s -> Bool) -> s -> (Chunk s, s)
streamDropN :: Stream s => Int -> s -> Maybe (Int, s)
streamDropWhile :: Stream s => (Token s -> Bool) -> s -> (Int, s)
type TextualStream s = (Stream s, Token s ~ Char, TextualChunked (Chunk s))
defaultStreamDropN :: Stream s => Int -> s -> Maybe (Int, s)
defaultStreamDropWhile :: Stream s => (Token s -> Bool) -> s -> (Int, s)
newtype Offset
Offset :: Int -> Offset
[unOffset] :: Offset -> Int
-- | Stream wrapper that maintains an offset position.
data OffsetStream s
OffsetStream :: !Offset -> !s -> OffsetStream s
[osOffset] :: OffsetStream s -> !Offset
[osState] :: OffsetStream s -> !s
newOffsetStream :: s -> OffsetStream s
newtype Line
Line :: Int -> Line
[unLine] :: Line -> Int
newtype Col
Col :: Int -> Col
[unCol] :: Col -> Int
-- | A 0-based line/col position in a character-based stream.
data LinePos
LinePos :: !Offset -> !Line -> !Col -> LinePos
[lpOffset] :: LinePos -> !Offset
[lpLine] :: LinePos -> !Line
[lpCol] :: LinePos -> !Col
-- | Stream wrapper that maintains a line/col position.
data LinePosStream s
LinePosStream :: !LinePos -> !s -> LinePosStream s
[lpsLinePos] :: LinePosStream s -> !LinePos
[lpsState] :: LinePosStream s -> !s
newLinePosStream :: s -> LinePosStream s
-- | A range between two positions.
data Span p
Span :: !p -> !p -> Span p
[spanStart] :: Span p -> !p
[spanEnd] :: Span p -> !p
instance GHC.Real.Integral SimpleParser.Stream.Offset
instance GHC.Real.Real SimpleParser.Stream.Offset
instance GHC.Num.Num SimpleParser.Stream.Offset
instance GHC.Enum.Enum SimpleParser.Stream.Offset
instance GHC.Classes.Ord SimpleParser.Stream.Offset
instance GHC.Show.Show SimpleParser.Stream.Offset
instance GHC.Classes.Eq SimpleParser.Stream.Offset
instance Data.Traversable.Traversable SimpleParser.Stream.OffsetStream
instance Data.Foldable.Foldable SimpleParser.Stream.OffsetStream
instance GHC.Base.Functor SimpleParser.Stream.OffsetStream
instance GHC.Show.Show s => GHC.Show.Show (SimpleParser.Stream.OffsetStream s)
instance GHC.Classes.Eq s => GHC.Classes.Eq (SimpleParser.Stream.OffsetStream s)
instance GHC.Real.Integral SimpleParser.Stream.Line
instance GHC.Real.Real SimpleParser.Stream.Line
instance GHC.Num.Num SimpleParser.Stream.Line
instance GHC.Enum.Enum SimpleParser.Stream.Line
instance GHC.Classes.Ord SimpleParser.Stream.Line
instance GHC.Show.Show SimpleParser.Stream.Line
instance GHC.Classes.Eq SimpleParser.Stream.Line
instance GHC.Real.Integral SimpleParser.Stream.Col
instance GHC.Real.Real SimpleParser.Stream.Col
instance GHC.Num.Num SimpleParser.Stream.Col
instance GHC.Enum.Enum SimpleParser.Stream.Col
instance GHC.Classes.Ord SimpleParser.Stream.Col
instance GHC.Show.Show SimpleParser.Stream.Col
instance GHC.Classes.Eq SimpleParser.Stream.Col
instance GHC.Classes.Ord SimpleParser.Stream.LinePos
instance GHC.Show.Show SimpleParser.Stream.LinePos
instance GHC.Classes.Eq SimpleParser.Stream.LinePos
instance Data.Traversable.Traversable SimpleParser.Stream.LinePosStream
instance Data.Foldable.Foldable SimpleParser.Stream.LinePosStream
instance GHC.Base.Functor SimpleParser.Stream.LinePosStream
instance GHC.Show.Show s => GHC.Show.Show (SimpleParser.Stream.LinePosStream s)
instance GHC.Classes.Eq s => GHC.Classes.Eq (SimpleParser.Stream.LinePosStream s)
instance GHC.Classes.Ord p => GHC.Classes.Ord (SimpleParser.Stream.Span p)
instance GHC.Show.Show p => GHC.Show.Show (SimpleParser.Stream.Span p)
instance GHC.Classes.Eq p => GHC.Classes.Eq (SimpleParser.Stream.Span p)
instance (SimpleParser.Stream.Stream s, SimpleParser.Stream.Token s GHC.Types.~ GHC.Types.Char) => SimpleParser.Stream.Stream (SimpleParser.Stream.LinePosStream s)
instance SimpleParser.Stream.Stream s => SimpleParser.Stream.Stream (SimpleParser.Stream.OffsetStream s)
instance SimpleParser.Stream.Stream [a]
instance SimpleParser.Stream.Stream (Data.Sequence.Internal.Seq a)
instance SimpleParser.Stream.Stream Data.Text.Internal.Text
module SimpleParser.Result
data RawError chunk token
RawErrorMatchEnd :: !token -> RawError chunk token
RawErrorAnyToken :: RawError chunk token
RawErrorAnyChunk :: RawError chunk token
RawErrorSatisfyToken :: !Maybe token -> RawError chunk token
RawErrorMatchToken :: !token -> !Maybe token -> RawError chunk token
RawErrorMatchChunk :: !chunk -> !Maybe chunk -> RawError chunk token
RawErrorTakeTokensWhile1 :: !Maybe token -> RawError chunk token
RawErrorDropTokensWhile1 :: !Maybe token -> RawError chunk token
-- | RawStreamError specialized to Stream types - newtyped
-- to allow GHC to derive eq/show in the absense of type families.
newtype StreamError s
StreamError :: RawError (Chunk s) (Token s) -> StreamError s
[unStreamError] :: StreamError s -> RawError (Chunk s) (Token s)
data CompoundError s e
CompoundErrorStream :: !StreamError s -> CompoundError s e
CompoundErrorFail :: !Text -> CompoundError s e
CompoundErrorCustom :: !e -> CompoundError s e
data Mark l s
Mark :: !Maybe l -> !s -> Mark l s
[markLabel] :: Mark l s -> !Maybe l
[markState] :: Mark l s -> !s
data ParseError l s e
ParseError :: !MarkStack l s -> !s -> !CompoundError s e -> ParseError l s e
[peMarkStack] :: ParseError l s e -> !MarkStack l s
[peEndState] :: ParseError l s e -> !s
[peError] :: ParseError l s e -> !CompoundError s e
-- | Returns the resumption point of the ParseError. If it has been
-- marked, we use that, otherwise we assume it starts at the exact error
-- point.
parseErrorResume :: ParseError l s e -> s
-- | Updates a ParseError with a resumption point.
markParseError :: Mark l s -> ParseError l s e -> ParseError l s e
-- | Clears marks from a ParseError.
unmarkParseError :: ParseError l s e -> ParseError l s e
-- | Returns labels enclosing the narrowest span, from coarsest to finest
parseErrorEnclosingLabels :: ParseError l s e -> Seq l
-- | Returns the narrowest span
parseErrorNarrowestSpan :: Stream s => ParseError l s e -> (Maybe l, Span (Pos s))
data ParseSuccess s a
ParseSuccess :: !s -> !a -> ParseSuccess s a
[psEndState] :: ParseSuccess s a -> !s
[psValue] :: ParseSuccess s a -> !a
data ParseResult l s e a
ParseResultError :: !NESeq (ParseError l s e) -> ParseResult l s e a
ParseResultSuccess :: !ParseSuccess s a -> ParseResult l s e a
instance (GHC.Show.Show token, GHC.Show.Show chunk) => GHC.Show.Show (SimpleParser.Result.RawError chunk token)
instance (GHC.Classes.Eq token, GHC.Classes.Eq chunk) => GHC.Classes.Eq (SimpleParser.Result.RawError chunk token)
instance Data.Traversable.Traversable (SimpleParser.Result.CompoundError s)
instance Data.Foldable.Foldable (SimpleParser.Result.CompoundError s)
instance GHC.Base.Functor (SimpleParser.Result.CompoundError s)
instance (GHC.Show.Show l, GHC.Show.Show s) => GHC.Show.Show (SimpleParser.Result.Mark l s)
instance (GHC.Classes.Eq l, GHC.Classes.Eq s) => GHC.Classes.Eq (SimpleParser.Result.Mark l s)
instance Data.Traversable.Traversable (SimpleParser.Result.ParseSuccess s)
instance Data.Foldable.Foldable (SimpleParser.Result.ParseSuccess s)
instance GHC.Base.Functor (SimpleParser.Result.ParseSuccess s)
instance (GHC.Show.Show s, GHC.Show.Show a) => GHC.Show.Show (SimpleParser.Result.ParseSuccess s a)
instance (GHC.Classes.Eq s, GHC.Classes.Eq a) => GHC.Classes.Eq (SimpleParser.Result.ParseSuccess s a)
instance Data.Traversable.Traversable (SimpleParser.Result.ParseResult l s e)
instance Data.Foldable.Foldable (SimpleParser.Result.ParseResult l s e)
instance GHC.Base.Functor (SimpleParser.Result.ParseResult l s e)
instance (GHC.Classes.Eq (SimpleParser.Stream.Token s), GHC.Classes.Eq (SimpleParser.Stream.Chunk s)) => GHC.Classes.Eq (SimpleParser.Result.StreamError s)
instance (GHC.Show.Show (SimpleParser.Stream.Token s), GHC.Show.Show (SimpleParser.Stream.Chunk s)) => GHC.Show.Show (SimpleParser.Result.StreamError s)
instance (GHC.Classes.Eq (SimpleParser.Stream.Token s), GHC.Classes.Eq (SimpleParser.Stream.Chunk s), GHC.Classes.Eq e) => GHC.Classes.Eq (SimpleParser.Result.CompoundError s e)
instance (GHC.Show.Show (SimpleParser.Stream.Token s), GHC.Show.Show (SimpleParser.Stream.Chunk s), GHC.Show.Show e) => GHC.Show.Show (SimpleParser.Result.CompoundError s e)
instance (GHC.Classes.Eq l, GHC.Classes.Eq s, GHC.Classes.Eq (SimpleParser.Stream.Token s), GHC.Classes.Eq (SimpleParser.Stream.Chunk s), GHC.Classes.Eq e) => GHC.Classes.Eq (SimpleParser.Result.ParseError l s e)
instance (GHC.Show.Show l, GHC.Show.Show s, GHC.Show.Show (SimpleParser.Stream.Token s), GHC.Show.Show (SimpleParser.Stream.Chunk s), GHC.Show.Show e) => GHC.Show.Show (SimpleParser.Result.ParseError l s e)
instance (GHC.Classes.Eq l, GHC.Classes.Eq s, GHC.Classes.Eq (SimpleParser.Stream.Token s), GHC.Classes.Eq (SimpleParser.Stream.Chunk s), GHC.Classes.Eq e, GHC.Classes.Eq a) => GHC.Classes.Eq (SimpleParser.Result.ParseResult l s e a)
instance (GHC.Show.Show l, GHC.Show.Show s, GHC.Show.Show (SimpleParser.Stream.Token s), GHC.Show.Show (SimpleParser.Stream.Chunk s), GHC.Show.Show e, GHC.Show.Show a) => GHC.Show.Show (SimpleParser.Result.ParseResult l s e a)
-- | ParserT is the core monad transformer for parsing.
module SimpleParser.Parser
-- | A ParserT is a stateerrorlist transformer useful for
-- parsing. All MTL instances are for this transformer only. If, for
-- example, your effect has its own MonadState instance, you'll
-- have to use 'lift get' instead of get.
newtype ParserT l s e m a
ParserT :: (s -> m (Maybe (ParseResult l s e a))) -> ParserT l s e m a
[runParserT] :: ParserT l s e m a -> s -> m (Maybe (ParseResult l s e a))
-- | Use Parser if you have no need for other monadic effects.
type Parser l s e a = ParserT l s e Identity a
-- | Runs a non-effectful parser from an inital state and collects all
-- results.
runParser :: Parser l s e a -> s -> Maybe (ParseResult l s e a)
-- | Applicative pure
pureParser :: Monad m => a -> ParserT l s e m a
-- | Monadic bind
bindParser :: Monad m => ParserT l s e m a -> (a -> ParserT l s e m b) -> ParserT l s e m b
-- | A simple failing parser
failParser :: Monad m => Text -> ParserT l s e m a
liftParser :: Monad m => m a -> ParserT l s e m a
hoistParser :: (forall x. m x -> n x) -> ParserT l s e m a -> ParserT l s e n a
-- | Catch only a subset of custom errors. This preserves label information
-- vs rethrowing.
catchJustParser :: Monad m => (e -> Maybe b) -> ParserT l s e m a -> (b -> ParserT l s e m a) -> ParserT l s e m a
-- | Throws a custom error
throwParser :: Monad m => e -> ParserT l s e m a
-- | Catches a custom error
catchParser :: Monad m => ParserT l s e m a -> (e -> ParserT l s e m a) -> ParserT l s e m a
-- | The empty parser
emptyParser :: Monad m => ParserT l s e m a
-- | Yields from the first parser of the two that returns a successfull
-- result. Otherwise will merge and yield all errors.
orParser :: Monad m => ParserT l s e m a -> ParserT l s e m a -> ParserT l s e m a
-- | Yields the LONGEST string of 0 or more successes of the given parser.
-- Failures will be silenced.
greedyStarParser :: (Chunked seq elem, Monad m) => ParserT l s e m elem -> ParserT l s e m seq
-- | Same as greedyStarParser but discards the result.
greedyStarParser_ :: Monad m => ParserT l s e m a -> ParserT l s e m ()
-- | Yields the LONGEST string of 1 or more successes of the given parser.
-- Failures in the tail will be silenced, but those in the head will be
-- returned.
greedyPlusParser :: (Chunked seq elem, Monad m) => ParserT l s e m elem -> ParserT l s e m seq
-- | Same as greedyPlusParser but discards the result.
greedyPlusParser_ :: Monad m => ParserT l s e m a -> ParserT l s e m ()
-- | If the parser does not succeed, yield the given value.
defaultParser :: Monad m => a -> ParserT l s e m a -> ParserT l s e m a
-- | A parser that yields Nothing if the parser does not succeed,
-- otherwise wraps success in Just.
optionalParser :: Monad m => ParserT l s e m a -> ParserT l s e m (Maybe a)
-- | Removes all failures from the parse results. Catches more errors than
-- 'catchError (const empty)' because this includes stream errors, not
-- just custom errors. If you want more fine-grained control, use
-- reflectParser and map over the results.
silenceParser :: Monad m => ParserT l s e m a -> ParserT l s e m a
-- | Yield the results of the given parser, but rewind back to the starting
-- state in ALL cases (success and error). Note that these results may
-- contain errors, so you may want to stifle them with
-- silenceParser, for example.
lookAheadParser :: Monad m => Maybe l -> ParserT l s e m a -> ParserT l s e m a
-- | Yield the results of the given parser, but rewind back to the starting
-- state on error ONLY.
markParser :: Monad m => Maybe l -> ParserT l s e m a -> ParserT l s e m a
-- | Like markParser but allows you to mutate state. See
-- withToken and withChunk.
markWithStateParser :: Monad m => Maybe l -> (s -> (b, s)) -> (b -> ParserT l s e m a) -> ParserT l s e m a
-- | Like markParser but allows you to mutate state. See
-- withToken and withChunk.
markWithOptStateParser :: Monad m => Maybe l -> (s -> Maybe (b, s)) -> (Maybe b -> ParserT l s e m a) -> ParserT l s e m a
-- | Clear marks from parse errors. You can mark immediately after to widen
-- the narrowest marked span to the range you want to report.
unmarkParser :: Monad m => ParserT l s e m a -> ParserT l s e m a
-- | If the first parser succeeds in the given state, yield results from
-- the second parser in the given state. This is likely the look-ahead
-- you want. Use the first parser to check a prefix of input, and use the
-- second to consume that input.
commitParser :: Monad m => ParserT l s e m () -> ParserT l s e m a -> ParserT l s e m a
-- | If the first parser yields NO results (success or failure), yield from
-- the second. Note that this is different from orParser in that
-- it does not try the second if there are errors in the first. You might
-- use this on the outside of a complex parser with a fallback to
-- fail to indicate that there are no matches.
onEmptyParser :: Parser l s e a -> Parser l s e a -> Parser l s e a
instance GHC.Base.Functor m => GHC.Base.Functor (SimpleParser.Parser.ParserT l s e m)
instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (SimpleParser.Parser.SeqPartition a b)
instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (SimpleParser.Parser.SeqPartition a b)
instance GHC.Base.Monad m => GHC.Base.Applicative (SimpleParser.Parser.ParserT l s e m)
instance GHC.Base.Monad m => GHC.Base.Monad (SimpleParser.Parser.ParserT l s e m)
instance GHC.Base.Monad m => GHC.Base.Alternative (SimpleParser.Parser.ParserT l s e m)
instance GHC.Base.Monad m => GHC.Base.MonadPlus (SimpleParser.Parser.ParserT l s e m)
instance GHC.Base.Monad m => Control.Monad.State.Class.MonadState s (SimpleParser.Parser.ParserT l s e m)
instance GHC.Base.Monad m => Control.Monad.Error.Class.MonadError e (SimpleParser.Parser.ParserT l s e m)
instance GHC.Base.Monad m => Control.Monad.Fail.MonadFail (SimpleParser.Parser.ParserT l s e m)
instance Control.Monad.Trans.Class.MonadTrans (SimpleParser.Parser.ParserT l s e)
instance Control.Monad.Morph.MFunctor (SimpleParser.Parser.ParserT l s e)
-- | Useful combinators for ParserT and Stream. Classified as
-- SAFE or UNSAFE. SAFE always return a value. UNSAFE throw.
module SimpleParser.Input
-- | Fetches the next token from the stream and runs the callback.
withToken :: (Stream s, Monad m) => Maybe l -> (Maybe (Token s) -> ParserT l s e m a) -> ParserT l s e m a
-- | Fetches the next chunk from the stream and runs the callback.
withChunk :: (Stream s, Monad m) => Maybe l -> Int -> (Maybe (Chunk s) -> ParserT l s e m a) -> ParserT l s e m a
-- | Return the next token, if any, but don't consume it. (SAFE)
peekToken :: (Stream s, Monad m) => ParserT l s e m (Maybe (Token s))
-- | Return the next token, if any, and consume it. (SAFE)
popToken :: (Stream s, Monad m) => ParserT l s e m (Maybe (Token s))
-- | Return the next chunk of the given size, if any, but don't consume it.
-- May return a smaller chunk at end of stream, but never returns an
-- empty chunk. (SAFE)
peekChunk :: (Stream s, Monad m) => Int -> ParserT l s e m (Maybe (Chunk s))
-- | Return the next chunk of the given size, if any, and consume it. May
-- return a smaller chunk at end of stream, but never returns an empty
-- chunk. (SAFE)
popChunk :: (Stream s, Monad m) => Int -> ParserT l s e m (Maybe (Chunk s))
-- | Drop the next chunk of the given size, if any, and consume it. May
-- return a smaller size at end of stream, but never returns size 0.
-- (SAFE)
dropChunk :: (Stream s, Monad m) => Int -> ParserT l s e m (Maybe Int)
-- | Is this the end of the stream? (SAFE)
isEnd :: (Stream s, Monad m) => ParserT l s e m Bool
-- | Match the end of the stream or terminate the parser. (UNSAFE)
matchEnd :: (Stream s, Monad m) => ParserT l s e m ()
-- | Return the next token or terminate the parser at end of stream.
-- (UNSAFE)
anyToken :: (Stream s, Monad m) => ParserT l s e m (Token s)
-- | Return the next chunk of the given size or terminate the parser at end
-- of stream. May return a smaller chunk at end of stream, but never
-- returns an empty chunk. (UNSAFE)
anyChunk :: (Stream s, Monad m) => Int -> ParserT l s e m (Chunk s)
-- | Match the next token with the given predicate or terminate the parser
-- at predicate false or end of stream. (UNSAFE)
satisfyToken :: (Stream s, Monad m) => Maybe l -> (Token s -> Bool) -> ParserT l s e m (Token s)
-- | Folds over a stream of tokens while the boolean value is true. Always
-- succeeds, even at end of stream. Only consumes greediest match. (SAFE)
foldTokensWhile :: (Stream s, Monad m) => (Token s -> x -> (Bool, x)) -> x -> ParserT l s e m x
-- | Take tokens into a chunk while they satisfy the given predicate.
-- Always succeeds, even at end of stream. May return an empty chunk.
-- Only yields greediest match. (SAFE)
takeTokensWhile :: (Stream s, Monad m) => (Token s -> Bool) -> ParserT l s e m (Chunk s)
-- | Take tokens into a chunk while they satisfy the given predicate. Only
-- succeeds if 1 or more tokens are taken, so it never returns an empty
-- chunk. Also takes an optional label to describe the predicate.
-- (UNSAFE)
takeTokensWhile1 :: (Stream s, Monad m) => Maybe l -> (Token s -> Bool) -> ParserT l s e m (Chunk s)
-- | Drop tokens and return chunk size while they satisfy the given
-- predicate. Always succeeds, even at end of stream. May return empty
-- chunk size 0. Only drops greediest match. (SAFE)
dropTokensWhile :: (Stream s, Monad m) => (Token s -> Bool) -> ParserT l s e m Int
-- | Drop tokens and return chunk size while they satisfy the given
-- predicate. Only succeeds if 1 or more tokens are dropped. Also takes
-- an optional label to describe the predicate. (UNSAFE)
dropTokensWhile1 :: (Stream s, Monad m) => Maybe l -> (Token s -> Bool) -> ParserT l s e m Int
-- | Match token with equality or terminate the parser at inequality or end
-- of stream. (UNSAFE)
matchToken :: (Stream s, Monad m, Eq (Token s)) => Token s -> ParserT l s e m (Token s)
-- | Match chunk with equality or terminate the parser at inequality or end
-- of stream. (UNSAFE)
matchChunk :: (Stream s, Monad m, Eq (Chunk s)) => Chunk s -> ParserT l s e m (Chunk s)
-- | Common parsers. See Text.Megaparsec.Char.Lexer.
module SimpleParser.Common
-- | Enumeration of common labels in textual parsing.
data TextLabel
TextLabelSpace :: TextLabel
TextLabelHSpace :: TextLabel
TextLabelDigit :: TextLabel
class EmbedTextLabel l
embedTextLabel :: EmbedTextLabel l => TextLabel -> l
-- | Union of text and custom labels
data CompoundTextLabel l
CompoundTextLabelText :: !TextLabel -> CompoundTextLabel l
CompoundTextLabelCustom :: !l -> CompoundTextLabel l
-- | Yields the maximal list of separated items. May return an empty list.
sepByParser :: (Chunked seq elem, Monad m) => ParserT l s e m elem -> ParserT l s e m () -> ParserT l s e m seq
-- | Parses between start and end markers.
betweenParser :: Monad m => ParserT l s e m () -> ParserT l s e m () -> ParserT l s e m a -> ParserT l s e m a
-- | A wrapper for lexemes (equivalent to Megaparsec's lexeme).
lexemeParser :: Monad m => ParserT l s e m () -> ParserT l s e m a -> ParserT l s e m a
-- | Consumes a newline character.
newlineParser :: (Stream s, Token s ~ Char, Monad m) => ParserT l s e m ()
-- | Consumes 0 or more space characters.
spaceParser :: (Stream s, Token s ~ Char, Monad m) => ParserT l s e m ()
-- | Consumes 0 or more non-line-break space characters
hspaceParser :: (Stream s, Token s ~ Char, Monad m) => ParserT l s e m ()
-- | Consumes 1 or more space characters.
spaceParser1 :: (EmbedTextLabel l, Stream s, Token s ~ Char, Monad m) => ParserT l s e m ()
-- | Consumes 1 or more non-line-break space characters
hspaceParser1 :: (EmbedTextLabel l, Stream s, Token s ~ Char, Monad m) => ParserT l s e m ()
-- | Parses an integer in decimal representation (equivalent to
-- Megaparsec's decimal).
decimalParser :: (EmbedTextLabel l, Stream s, Token s ~ Char, Monad m, Num a) => ParserT l s e m a
-- | Predicate for satisfying the start of signed numbers
signedNumStartPred :: Char -> Bool
-- | Parses a floating point value as a Scientific number
-- (equivalent to Megaparsec's scientific).
scientificParser :: (EmbedTextLabel l, Stream s, Token s ~ Char, Monad m) => ParserT l s e m Scientific
-- | Parses an optional sign character followed by a number and yields a
-- correctly-signed number (equivalend to Megaparsec's signed).
signedParser :: (Stream s, Token s ~ Char, Monad m, Num a) => ParserT l s e m () -> ParserT l s e m a -> ParserT l s e m a
-- | Given a quote charcter (like a single or double quote), yields the
-- contents of the string bounded by those quotes. The contents may
-- contain backslash-escaped quotes. Returns nothing if outside quotes
-- are missing or the stream ends before unquote.
escapedStringParser :: (Stream s, Token s ~ Char, Monad m) => Char -> ParserT l s e m (Chunk s)
-- | Adds span information to parsed values.
spanParser :: (Stream s, Monad m) => (Span (Pos s) -> a -> b) -> ParserT l s e m a -> ParserT l s e m b
-- | Gets the current stream position
getStreamPos :: (Stream s, Monad m) => ParserT l s e m (Pos s)
instance GHC.Show.Show SimpleParser.Common.TextLabel
instance GHC.Classes.Eq SimpleParser.Common.TextLabel
instance Data.Traversable.Traversable SimpleParser.Common.CompoundTextLabel
instance Data.Foldable.Foldable SimpleParser.Common.CompoundTextLabel
instance GHC.Base.Functor SimpleParser.Common.CompoundTextLabel
instance GHC.Show.Show l => GHC.Show.Show (SimpleParser.Common.CompoundTextLabel l)
instance GHC.Classes.Eq l => GHC.Classes.Eq (SimpleParser.Common.CompoundTextLabel l)
instance SimpleParser.Common.EmbedTextLabel (SimpleParser.Common.CompoundTextLabel l)
instance SimpleParser.Common.EmbedTextLabel SimpleParser.Common.TextLabel
module SimpleParser.Explain
class ExplainLabel l
explainLabel :: ExplainLabel l => l -> Builder
explainLabelText :: ExplainLabel l => l -> Text
data ErrorExplanation
ErrorExplanation :: !Text -> !Maybe Text -> !Maybe Text -> ErrorExplanation
[eeReason] :: ErrorExplanation -> !Text
[eeExpected] :: ErrorExplanation -> !Maybe Text
[eeActual] :: ErrorExplanation -> !Maybe Text
class ExplainError e
explainError :: ExplainError e => e -> ErrorExplanation
type Explainable l s e = (TextualStream s, ExplainLabel l, ExplainError e)
data ParseErrorExplanation p
ParseErrorExplanation :: !Span p -> !Seq Text -> !Maybe Text -> !ErrorExplanation -> ParseErrorExplanation p
[peeSpan] :: ParseErrorExplanation p -> !Span p
[peeContext] :: ParseErrorExplanation p -> !Seq Text
[peeDetails] :: ParseErrorExplanation p -> !Maybe Text
[peeErrExp] :: ParseErrorExplanation p -> !ErrorExplanation
explainParseError :: Explainable l s e => ParseError l s e -> ParseErrorExplanation (Pos s)
buildParseErrorExplanation :: ParseErrorExplanation LinePos -> Builder
buildAllParseErrorExplanations :: Foldable f => f (ParseErrorExplanation LinePos) -> Builder
instance GHC.Show.Show SimpleParser.Explain.ErrorExplanation
instance GHC.Classes.Eq SimpleParser.Explain.ErrorExplanation
instance GHC.Show.Show p => GHC.Show.Show (SimpleParser.Explain.ParseErrorExplanation p)
instance GHC.Classes.Eq p => GHC.Classes.Eq (SimpleParser.Explain.ParseErrorExplanation p)
instance SimpleParser.Explain.ExplainError Data.Void.Void
instance (SimpleParser.Stream.Token s GHC.Types.~ GHC.Types.Char, SimpleParser.Chunked.TextualChunked (SimpleParser.Stream.Chunk s)) => SimpleParser.Explain.ExplainError (SimpleParser.Result.StreamError s)
instance (SimpleParser.Stream.Token s GHC.Types.~ GHC.Types.Char, SimpleParser.Chunked.TextualChunked (SimpleParser.Stream.Chunk s), SimpleParser.Explain.ExplainError e) => SimpleParser.Explain.ExplainError (SimpleParser.Result.CompoundError s e)
instance SimpleParser.Explain.ExplainLabel Data.Void.Void
instance SimpleParser.Explain.ExplainLabel SimpleParser.Common.TextLabel
instance SimpleParser.Explain.ExplainLabel l => SimpleParser.Explain.ExplainLabel (SimpleParser.Common.CompoundTextLabel l)
module SimpleParser.Interactive
parseInteractive :: (s ~ LinePosStream Text, Explainable l s e, Show a) => Parser l s e a -> String -> IO ()
-- | This is basically a simpler and slower (Mega)Parsec that is fully
-- backtracking by default.
--
-- The root module re-exports all modules. See
-- SimpleParser.Examples.Json or the test suit for examples,
-- SimpleParser.Parser for the core transformer,
-- SimpleParser.Stream for the source abstraction, or
-- SimpleParser.Input for useful combinators.
module SimpleParser
module SimpleParser.Examples.Sexp
newtype Sexp
Sexp :: SexpF Sexp -> Sexp
[unSexp] :: Sexp -> SexpF Sexp
data SexpF a
SexpAtom :: !Atom -> SexpF a
SexpList :: !Seq a -> SexpF a
data Atom
AtomIdent :: !Text -> Atom
AtomString :: !Text -> Atom
AtomInt :: !Integer -> Atom
AtomFloat :: !Scientific -> Atom
data SexpLabel
SexpLabelIdentStart :: SexpLabel
SexpLabelEmbedText :: !TextLabel -> SexpLabel
type SexpParserC s = TextualStream s
type SexpParserM s a = Parser SexpLabel s Void a
sexpParser :: SexpParserC s => SexpParserM s Sexp
recSexpParser :: SexpParserC s => SexpParserM s a -> SexpParserM s (SexpF a)
instance GHC.Show.Show SimpleParser.Examples.Sexp.Atom
instance GHC.Classes.Eq SimpleParser.Examples.Sexp.Atom
instance Data.Traversable.Traversable SimpleParser.Examples.Sexp.SexpF
instance Data.Foldable.Foldable SimpleParser.Examples.Sexp.SexpF
instance GHC.Base.Functor SimpleParser.Examples.Sexp.SexpF
instance GHC.Show.Show a => GHC.Show.Show (SimpleParser.Examples.Sexp.SexpF a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (SimpleParser.Examples.Sexp.SexpF a)
instance GHC.Show.Show SimpleParser.Examples.Sexp.SexpLabel
instance GHC.Classes.Eq SimpleParser.Examples.Sexp.SexpLabel
instance GHC.Show.Show SimpleParser.Examples.Sexp.Sexp
instance GHC.Classes.Eq SimpleParser.Examples.Sexp.Sexp
instance SimpleParser.Explain.ExplainLabel SimpleParser.Examples.Sexp.SexpLabel
instance SimpleParser.Common.EmbedTextLabel SimpleParser.Examples.Sexp.SexpLabel
module SimpleParser.Examples.Json
newtype Json
Json :: JsonF Json -> Json
[unJson] :: Json -> JsonF Json
data JsonF a
JsonObject :: !Seq (Text, a) -> JsonF a
JsonArray :: !Seq a -> JsonF a
JsonString :: !Text -> JsonF a
JsonBool :: !Bool -> JsonF a
JsonNum :: !Scientific -> JsonF a
JsonNull :: JsonF a
type JsonParserC s = (TextualStream s, Eq (Chunk s))
type JsonParserM s a = Parser TextLabel s Void a
jsonParser :: JsonParserC s => JsonParserM s Json
recJsonParser :: JsonParserC s => JsonParserM s a -> JsonParserM s (JsonF a)
instance Data.Traversable.Traversable SimpleParser.Examples.Json.JsonF
instance Data.Foldable.Foldable SimpleParser.Examples.Json.JsonF
instance GHC.Base.Functor SimpleParser.Examples.Json.JsonF
instance GHC.Show.Show a => GHC.Show.Show (SimpleParser.Examples.Json.JsonF a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (SimpleParser.Examples.Json.JsonF a)
instance GHC.Show.Show SimpleParser.Examples.Json.Json
instance GHC.Classes.Eq SimpleParser.Examples.Json.Json