-- 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.2.0 module SimpleParser.Result -- | Strict pair of parse result and state at the time it was yielded. data ParseResult e s a ParseResult :: !ParseValue e a -> !s -> ParseResult e s a [prValue] :: ParseResult e s a -> !ParseValue e a [prState] :: ParseResult e s a -> !s -- | Strict Either for parse results. data ParseValue e a ParseError :: !e -> ParseValue e a ParseSuccess :: !a -> ParseValue e a parseSuccessResult :: a -> s -> ParseResult e s a parseErrorResult :: e -> s -> ParseResult e s a parseValue :: (e -> r) -> (a -> r) -> ParseValue e a -> r instance Data.Traversable.Traversable (SimpleParser.Result.ParseValue e) instance Data.Foldable.Foldable (SimpleParser.Result.ParseValue e) instance GHC.Base.Functor (SimpleParser.Result.ParseValue e) instance (GHC.Show.Show e, GHC.Show.Show a) => GHC.Show.Show (SimpleParser.Result.ParseValue e a) instance (GHC.Classes.Eq e, GHC.Classes.Eq a) => GHC.Classes.Eq (SimpleParser.Result.ParseValue e a) instance Data.Traversable.Traversable (SimpleParser.Result.ParseResult e s) instance Data.Foldable.Foldable (SimpleParser.Result.ParseResult e s) instance GHC.Base.Functor (SimpleParser.Result.ParseResult e s) instance (GHC.Show.Show e, GHC.Show.Show a, GHC.Show.Show s) => GHC.Show.Show (SimpleParser.Result.ParseResult e s a) instance (GHC.Classes.Eq e, GHC.Classes.Eq a, GHC.Classes.Eq s) => GHC.Classes.Eq (SimpleParser.Result.ParseResult e s 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 e s m a ParserT :: (s -> ListT m (ParseResult e s a)) -> ParserT e s m a [runParserT] :: ParserT e s m a -> s -> ListT m (ParseResult e s a) -- | Use Parser if you have no need for other monadic effects. type Parser e s a = ParserT e s Identity a -- | Runs a non-effectful parser from an inital state and collects all -- results. runParser :: Parser e s a -> s -> [ParseResult e s a] -- | Filters parse results filterParser :: Monad m => (a -> Bool) -> ParserT e s m a -> ParserT e s m a -- | A kind of "catch" that returns all results, success and failure. reflectParser :: Monad m => ParserT e s m a -> ParserT e s m (ParseValue e a) -- | Combines the results of many parsers. branchParser :: (Foldable f, Monad m) => f (ParserT e s m a) -> ParserT e s m a -- | If the parse results in ANY successes, keep only those. Otherwise -- return all failures. This may block indefinitely as it awaits either -- the end of the parser or its first success. suppressParser :: Monad m => ParserT e s m a -> ParserT e s m a -- | If the parser yields no results (success or failure), yield a given -- value. defaultParser :: Monad m => a -> ParserT e s m a -> ParserT e s m a -- | A parser that yields Nothing if there are no results (success -- or failure), otherwise wrapping successes in Just. optionalParser :: Monad m => ParserT e s m a -> ParserT e s m (Maybe a) -- | Removes all failures from the parse results. silenceParser :: Monad m => ParserT e s m a -> ParserT e s m a -- | Yields the LONGEST string of 0 or more successes of the given parser -- (and passes through failures). greedyStarParser :: Monad m => ParserT e s m a -> ParserT e s m [a] -- | Same as greedyStarParser but discards the result. greedyStarParser_ :: Monad m => ParserT e s m a -> ParserT e s m () -- | Yields the LONGEST string of 1 or more successes of the given parser -- (and passes through failures). greedyPlusParser :: Monad m => ParserT e s m a -> ParserT e s m [a] -- | Same as greedyPlusParser but discards the result. greedyPlusParser_ :: Monad m => ParserT e s m a -> ParserT e s m () instance GHC.Base.Functor m => GHC.Base.Functor (SimpleParser.Parser.ParserT e s m) instance GHC.Base.Monad m => GHC.Base.Applicative (SimpleParser.Parser.ParserT e s m) instance GHC.Base.Monad m => GHC.Base.Monad (SimpleParser.Parser.ParserT e s m) instance GHC.Base.Monad m => GHC.Base.Alternative (SimpleParser.Parser.ParserT e s m) instance GHC.Base.Monad m => GHC.Base.MonadPlus (SimpleParser.Parser.ParserT e s m) instance GHC.Base.Monad m => Control.Monad.Error.Class.MonadError e (SimpleParser.Parser.ParserT e s m) instance GHC.Base.Monad m => Control.Monad.State.Class.MonadState s (SimpleParser.Parser.ParserT e s m) instance Control.Monad.Trans.Class.MonadTrans (SimpleParser.Parser.ParserT e s) -- | This reworks Stream to split interfaces. See -- https://hackage.haskell.org/package/megaparsec-9.0.1/docs/Text-Megaparsec-Stream.html module SimpleParser.Stream -- | 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 -- | 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; } 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) defaultStreamDropN :: Stream s => Int -> s -> Maybe (Int, s) defaultStreamDropWhile :: Stream s => (Token s -> Bool) -> s -> (Int, s) data OffsetStream s OffsetStream :: !Int -> !s -> OffsetStream s [osOffset] :: OffsetStream s -> !Int [osState] :: OffsetStream s -> !s newOffsetStream :: s -> OffsetStream s 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 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 instance SimpleParser.Stream.Chunked [a] a instance SimpleParser.Stream.Chunked (Data.Sequence.Internal.Seq a) a instance SimpleParser.Stream.Chunked Data.Text.Internal.Text GHC.Types.Char -- | Useful combinators for ParserT and Stream. module SimpleParser.Input -- | Return the next token, if any, but don't consume it. peekToken :: (Stream s, Monad m) => ParserT e s m (Maybe (Token s)) -- | Return the next token, if any, and consume it. popToken :: (Stream s, Monad m) => ParserT e s 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. peekChunk :: (Stream s, Monad m) => Int -> ParserT e s 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. popChunk :: (Stream s, Monad m) => Int -> ParserT e s 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. dropChunk :: (Stream s, Monad m) => Int -> ParserT e s m (Maybe Int) -- | Is this the end of the stream? isEnd :: (Stream s, Monad m) => ParserT e s m Bool -- | Match the end of the stream or terminate the parser. matchEnd :: (Stream s, Monad m) => ParserT e s m () -- | Return the next token or terminate the parser at end of stream. anyToken :: (Stream s, Monad m) => ParserT e s 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. anyChunk :: (Stream s, Monad m) => Int -> ParserT e s m (Chunk s) -- | Match the next token with the given predicate or terminate the parser -- at predicate false or end of stream. satisfyToken :: (Stream s, Monad m) => (Token s -> Bool) -> ParserT e s m (Token s) -- | Folds over a stream of tokens while the boolean value is true. Always -- succeeds, even at end of stream. foldTokensWhile :: (Stream s, Monad m) => (Token s -> x -> (Bool, x)) -> (x -> x) -> x -> ParserT e s 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. takeTokensWhile :: (Stream s, Monad m) => (Token s -> Bool) -> ParserT e s 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. dropTokensWhile :: (Stream s, Monad m) => (Token s -> Bool) -> ParserT e s m Int -- | Match token with equality or terminate the parser at inequality or end -- of stream. matchToken :: (Stream s, Monad m, Eq (Token s)) => Token s -> ParserT e s m (Token s) -- | Match chunk with equality or terminate the parser at inequality or end -- of stream. matchChunk :: (Stream s, Monad m, Eq (Chunk s)) => Chunk s -> ParserT e s m (Chunk s) -- | Re-exports for all modules. See Json or the test suit for -- examples, Parser for the core transformer, Stream for -- the source abstraction, or Input for useful combinators. module SimpleParser module SimpleParser.Examples.Json newtype Json Json :: JsonF Json -> Json [unJson] :: Json -> JsonF Json data JsonF a JsonObject :: ![(String, a)] -> JsonF a JsonArray :: ![a] -> JsonF a JsonString :: !String -> JsonF a JsonBool :: !Bool -> JsonF a JsonNull :: JsonF a parseJson :: Text -> [Json] 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