X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FParser.hs;h=b31d4b89be473835df40f9a1dcf72d97d526b5db;hp=ce4371878890301eb152d3b9ef55c526c4127174;hb=e49345ce5e6c0190c826d130d51ec42ee9f09a67;hpb=18192e5ea2b621a551db27aa39e221a05696e2b3 diff --git a/Network/HTTP/Lucu/Parser.hs b/Network/HTTP/Lucu/Parser.hs index ce43718..b31d4b8 100644 --- a/Network/HTTP/Lucu/Parser.hs +++ b/Network/HTTP/Lucu/Parser.hs @@ -5,16 +5,26 @@ -- use this module directly. module Network.HTTP.Lucu.Parser ( atMost + , finishOff ) where import Control.Applicative import Control.Applicative.Unicode +import Control.Monad.Unicode +import Data.Attoparsec +import Prelude.Unicode -- |@'atMost' n v@ is like @'P.many' v@ but accumulates @v@ at most -- @n@ times. -atMost ∷ Alternative f ⇒ Int → f a → f [a] +atMost ∷ Alternative f ⇒ Int → f α → f [α] {-# INLINE atMost #-} atMost 0 _ = pure [] atMost n v = ( (:) <$> v ⊛ atMost (n-1) v ) <|> pure [] + +-- |@'finishOff' p@ is equivalent to @p '>>=' \a -> endOfInput '>>' +-- 'return' a@. +finishOff ∷ Parser α → Parser α +{-# INLINE finishOff #-} +finishOff = ((endOfInput *>) ∘ return =≪)