module Network.HTTP.Lucu.Parser
( atMost
, finishOff
, skipManyTill
, skipWhile1
, skipSpace1
, isAlphaNum
)
where
import Control.Applicative
import Control.Applicative.Unicode
import Control.Monad.Unicode
import Data.Attoparsec.Char8
import Prelude.Unicode
atMost ∷ Alternative f ⇒ Int → f α → f [α]
atMost 0 _ = pure []
atMost n v = ( (:) <$> v ⊛ atMost (n1) v )
<|>
pure []
finishOff ∷ Parser α → Parser α
finishOff = ((endOfInput *>) ∘ return =≪)
skipManyTill ∷ Alternative f ⇒ f α → f β → f ()
skipManyTill p end = go
where
go = (end *> pure ()) <|> (p *> go)
skipWhile1 ∷ (Char → Bool) → Parser ()
skipWhile1 p = takeWhile1 p *> pure ()
skipSpace1 ∷ Parser ()
skipSpace1 = skipMany1 space
isAlphaNum ∷ Char → Bool
isAlphaNum c = isDigit c ∨ isAlpha_ascii c