Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data.Parsable
Description
This module contains two simple classes, Parsable
and Printable
.
There is an implicit "soft isomorphism" between parser
and toString
.
(Successfully parsing a string and then running toString
on the result
should result in the original string.)
Language extensions
Because parser
does not take any arguments, it may be necessary
to explicitly declare the type of t
for these functions.
It may be helpful to enable and use the TypeApplications
and possibly
ScopedTypeVariables
extensions..
Look at the Language Extensions
section of the GHC documentation for
instructions on how to use these extensions.
Synopsis
- class Parsable a (m :: Type -> Type) u s where
- parser :: ParsecT s u m a
- parserName :: ParserName a s u m
- newtype ParserName a s u (m :: Type -> Type) = ParserName {}
- runParsableT :: forall a m s. (Stream s m Char, Parsable a m () s) => String -> s -> m (Either ParseError a)
- runParsable :: forall a s. (Stream s Identity Char, Parsable a Identity () s) => String -> s -> Either ParseError a
- newtype NaturalParsable a = NaturalParsable {}
- satisfyAny :: Stream s m Char => [Char -> Bool] -> ParsecT s u m Char
- wordAllowed :: Stream s m Char => [Char -> Bool] -> [Char -> Bool] -> ParsecT s u m [Char]
- readParsec :: forall a s u m. (Typeable a, Read a) => String -> ParsecT s u m a
- class Printable t where
- toText :: (Printable t, IsString s) => t -> s
- newtype ShowPrintable a = ShowPrintable {
- unwrapShowPrintable :: a
- module Control.Monad
- module Control.Monad.Trans.Class
- module Data.Char
- module Data.Functor.Identity
- module Data.String
- module Text.Parsec
- module Text.Parsec.Char
Parsing
class Parsable a (m :: Type -> Type) u s where Source #
Represents types that have a valid Parsec parser.
Instances
(Stream s m Char, Read a, Typeable a) => Parsable (NaturalParsable a) m u s Source # | |
Defined in Data.Parsable Methods parser :: ParsecT s u m (NaturalParsable a) Source # parserName :: ParserName (NaturalParsable a) s u m Source # |
newtype ParserName a s u (m :: Type -> Type) Source #
Constructors
ParserName | |
Fields |
Instances
IsString (ParserName a s u m) Source # | |
Defined in Data.Parsable Methods fromString :: String -> ParserName a s u m # | |
Show (ParserName a s u m) Source # | |
Defined in Data.Parsable Methods showsPrec :: Int -> ParserName a s u m -> ShowS # show :: ParserName a s u m -> String # showList :: [ParserName a s u m] -> ShowS # | |
Eq (ParserName a s u m) Source # | |
Defined in Data.Parsable Methods (==) :: ParserName a s u m -> ParserName a s u m -> Bool # (/=) :: ParserName a s u m -> ParserName a s u m -> Bool # | |
Ord (ParserName a s u m) Source # | |
Defined in Data.Parsable Methods compare :: ParserName a s u m -> ParserName a s u m -> Ordering # (<) :: ParserName a s u m -> ParserName a s u m -> Bool # (<=) :: ParserName a s u m -> ParserName a s u m -> Bool # (>) :: ParserName a s u m -> ParserName a s u m -> Bool # (>=) :: ParserName a s u m -> ParserName a s u m -> Bool # max :: ParserName a s u m -> ParserName a s u m -> ParserName a s u m # min :: ParserName a s u m -> ParserName a s u m -> ParserName a s u m # |
runParsableT :: forall a m s. (Stream s m Char, Parsable a m () s) => String -> s -> m (Either ParseError a) Source #
Convenience function to run a Parsable
parser.
runParsable :: forall a s. (Stream s Identity Char, Parsable a Identity () s) => String -> s -> Either ParseError a Source #
Wrappers
newtype NaturalParsable a Source #
Constructors
NaturalParsable | |
Fields |
Instances
(Stream s m Char, Read a, Typeable a) => Parsable (NaturalParsable a) m u s Source # | |
Defined in Data.Parsable Methods parser :: ParsecT s u m (NaturalParsable a) Source # parserName :: ParserName (NaturalParsable a) s u m Source # |
Parsing functions
satisfyAny :: Stream s m Char => [Char -> Bool] -> ParsecT s u m Char Source #
Parse a token that satisfies any of the given predicates
Arguments
:: Stream s m Char | |
=> [Char -> Bool] | Tokens that start the word |
-> [Char -> Bool] | Any subsequent tokens |
-> ParsecT s u m [Char] |
Parsing of "words" which require a list of predicates for the first token, and a list of predicates for any remaining tokens. This always parses at least one token.
readParsec :: forall a s u m. (Typeable a, Read a) => String -> ParsecT s u m a Source #
Pass a previously-parsed string to this function in order to attempt
using read
. Produces proper error messages on failure.
Printing
class Printable t where Source #
Types that can be converted back to a String
.
Minimal complete definition
Wrappers
newtype ShowPrintable a Source #
Wrapper for types that inherit toString
directly from their Show
instance.
It is convenient to use the DerivingVia
language extension with this.
{-# Language DerivingVia #-} newtype MyNum Int deriving Printable via (ShowPrintable Int) -- Uses Show instance of Int
Constructors
ShowPrintable | |
Fields
|
Instances
Re-exports
module Control.Monad
module Control.Monad.Trans.Class
module Data.Char
module Data.Functor.Identity
module Data.String
module Text.Parsec
module Text.Parsec.Char