# HG changeset patch # User Felipe Lessa # Date 1296234509 7200 # Node ID 93525da64413799aa1cc9e3001e1e0e80d2ba8bd # Parent 87b295d9fad01787862a7a614ba4c8c1e69e0752 Add specializations of <* and *>. diff -r 87b295d9fad0 -r 93525da64413 Data/Attoparsec/Char8.hs --- a/Data/Attoparsec/Char8.hs Thu Jan 27 21:23:39 2011 -0800 +++ b/Data/Attoparsec/Char8.hs Fri Jan 28 15:08:29 2011 -0200 @@ -5,7 +5,7 @@ -- Module : Data.Attoparsec.Char8 -- Copyright : Bryan O'Sullivan 2007-2010 -- License : BSD3 --- +-- -- Maintainer : bos@serpentine.com -- Stability : experimental -- Portability : unknown @@ -84,9 +84,14 @@ -- * State observation and manipulation functions , I.endOfInput , I.ensure + + -- * Applicative specializations + -- $applicative + , (<*.) + , (.*>) ) where -import Control.Applicative ((*>), (<$>), (<|>)) +import Control.Applicative (Applicative, (<*), (*>), (<$>), (<|>)) import Data.Attoparsec.Combinator import Data.Attoparsec.FastSet (charClass, memberChar) import Data.Attoparsec.Internal (Parser, ()) @@ -435,4 +440,28 @@ return $! if sign == plus then n else -n - + + +-- $applicative +-- +-- We provide specializations of @\<*@ and @*\>@ as @\<*.@ and +-- @.*\>@, respectively. Together with @IsString@ instance of +-- 'Parser', you may write parsers applicatively more easily. +-- For example: +-- +-- > paren p = "(" .*> p <*. ")" +-- +-- instead of the more verbose +-- +-- > paren p = string "(" *> p <* string ")" + +-- | Same as @Applicative@'s @\<*@ but specialized to +-- 'B.ByteString' on the second argument. +(<*.) :: Applicative f => f a -> f B.ByteString -> f a +(<*.) = (<*) + +-- | Same as @Applicative@'s @*\>@ but specialized to +-- 'B.ByteString' on the first argument. +(.*>) :: Applicative f => f B.ByteString -> f a -> f a +(.*>) = (*>) +