]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Parser.hs
haddock comments
[Lucu.git] / Network / HTTP / Lucu / Parser.hs
1 {-# LANGUAGE
2     UnicodeSyntax
3   #-}
4 -- |This is an auxiliary parser utilities. You usually don't have to
5 -- use this module directly.
6 module Network.HTTP.Lucu.Parser
7     ( atMost
8     , finishOff
9     )
10     where
11 import Control.Applicative
12 import Control.Applicative.Unicode
13 import Control.Monad.Unicode
14 import Data.Attoparsec
15 import Prelude.Unicode
16
17 -- |@'atMost' n v@ is like @'P.many' v@ but accumulates @v@ at most
18 -- @n@ times.
19 atMost ∷ Alternative f ⇒ Int → f α → f [α]
20 {-# INLINE atMost #-}
21 atMost 0 _ = pure []
22 atMost n v = ( (:) <$> v ⊛ atMost (n-1) v )
23              <|>
24              pure []
25
26 -- |@'finishOff' p@ is equivalent to @p '>>=' \\a -> 'endOfInput' '>>'
27 -- 'return' a@.
28 finishOff ∷ Parser α → Parser α
29 {-# INLINE finishOff #-}
30 finishOff = ((endOfInput *>) ∘ return =≪)