Parser synonym for strict ByteString.
Moduleappar-0.1.8Haskell98
Text.Appar.ByteString
Simple Applicative parser whose input is strict ByteString. The usage is the same as parsec.
Parsec 3 provides features which Parsec 2 does not provide:
Applicative style
ByteString as input
But Haskell Platform includes Parsec 2, not Parsec 3. Installing Parsec 3 to Haskell Platform environment makes it mess. So, this library was implemented.
- 2 types
- 1 class
- 20 values
- Packageappar-0.1.8
- Exports31
- LanguageHaskell98
- LicenceBSD-3-Clause
- SourceByteString.hs
Documentation
0 declarationsParser type
The class for parser input.
Instances3Input
Input ByteStringDefined in appar-0.1.8 · Text.Appar.InputInput ByteStringDefined in appar-0.1.8 · Text.Appar.InputInput StringDefined in appar-0.1.8 · Text.Appar.Input
Run a parser.
char c parses a single character c. Returns the parsed character.
This parser succeeds for any character. Returns the parsed character.
oneOf cs succeeds if the current character is in the supplied list of
characters cs. Returns the parsed character.
As the dual of oneOf, noneOf cs succeeds if the current
character not in the supplied list of characters cs. Returns the
parsed character.
Parses a letter or digit (a character between '0' and '9'). Returns the parsed character.
Parses a digit. Returns the parsed character.
Parses a hexadecimal digit (a digit or a letter between 'a' and 'f' or 'A' and 'F'). Returns the parsed character.
Parses a white space character (any character which satisfies isSpace) Returns the parsed character.
string s parses a sequence of characters given by s. Returns
the parsed string
The parser try p behaves like parser p, except that it pretends that it hasn't consumed any input when an error occurs.
choice ps tries to apply the parsers in the list ps in order,
until one of them succeeds. Returns the value of the succeeding
parser.
option x p tries to apply parser p. If p fails without
consuming input, it returns the value x, otherwise the value
returned by p.
skipMany p applies the parser p zero or more times, skipping
its result.
skipSome p applies the parser p one or more times, skipping
its result.
sepBy1 p sep parses one or more occurrences of p, separated
by sep. Returns a list of values returned by p.
manyTill p end applies parser p zero or more times until
parser end succeeds. Returns the list of values returned by p.
An infix synonym for fmap.
The name of this operator is an allusion to Prelude.$.
Note the similarities between their types:
($) :: (a -> b) -> a -> b
(<$>) :: Functor f => (a -> b) -> f a -> f bWhereas Prelude.$ is function application, <$> is function
application lifted over a Functor.
Examples
Convert from a Maybe Int to a Maybe
String using show:
show <$> NothingNothing
show <$> Just 3Just "3"
Convert from an Either Int Int to an
Either Int String using show:
show <$> Left 17Left 17
show <$> Right 17Right "17"
Double each element of a list:
(*2) <$> [1,2,3][2,4,6]
Apply even to the second element of a pair:
even <$> (2,2)(2,True)
Replace all locations in the input with the same value.
The default definition is fmap . const, but this may be
overridden with a more efficient version.
Examples
Perform a computation with Maybe and replace the result with a constant value if it is Just:
'a' <$ Just 2Just 'a''a' <$ NothingNothing
Sequential application.
A few functors support an implementation of <*> that is more efficient than the default one.
Example
Used in combination with , (Data.Functor.<$>) can be used to build a record.(<*>)
data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}produceFoo :: Applicative f => f FooproduceBar :: Applicative f => f BarproduceBaz :: Applicative f => f Baz
mkState :: Applicative f => f MyStatemkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
Sequence actions, discarding the value of the first argument.
Examples
If used in conjunction with the Applicative instance for Maybe, you can chain Maybe computations, with a possible "early return" in case of Nothing.
Just 2 *> Just 3Just 3
Nothing *> Just 3Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
import Data.Charimport GHC.Internal.Text.ParserCombinators.ReadPlet p = string "my name is " *> munch1 isAlpha <* eofreadP_to_S p "my name is Simon"[("Simon","")]
Sequence actions, discarding the value of the second argument.
Lift a value into the Structure.
Examples
pure 1 :: Maybe IntJust 1
pure 'z' :: [Char]"z"
pure (pure ":D") :: Maybe [String]Just [":D"]
A variant of <*> with the types of the arguments reversed. It differs from
flip in that the effects are resolved in the order the arguments are
presented.(<*>)
Examples
(<**>) (print 1) (id <$ print 2)12
flip (<*>) (print 1) (id <$ print 2)21
ZipList [4, 5, 6] <**> ZipList [(+1), (*2), (/3)]ZipList {getZipList = [5.0,10.0,2.0]}
An associative binary operation
One or more.
Examples
some (putStr "la")lalalalalalalalala... * goes on forever *
some Nothingnothing
take 5 <$> some (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case some parser will attempt to
parse parser one or more times until it fails.
Zero or more.
Examples
many (putStr "la")lalalalalalalalala... * goes on forever *
many NothingJust []
take 5 <$> many (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case many parser will attempt to
parse parser zero or more times until it fails.
Instances6Monad, Functor, MonadFail, Applicative, Alternative, MonadPlus
Monad (MkParser inp)Defined in appar-0.1.8 · Text.Appar.ParserFunctor (MkParser inp)Defined in appar-0.1.8 · Text.Appar.ParserMonadFail (MkParser inp)Defined in appar-0.1.8 · Text.Appar.ParserApplicative (MkParser inp)Defined in appar-0.1.8 · Text.Appar.ParserAlternative (MkParser inp)Defined in appar-0.1.8 · Text.Appar.ParserMonadPlus (MkParser inp)Defined in appar-0.1.8 · Text.Appar.Parser
The parser satisfy f succeeds for any character for which the
supplied function f returns True. Returns the character that is
actually parsed.