X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Data%2FURI%2FInternal.hs;fp=Data%2FURI%2FInternal.hs;h=ffb8a7bb51cf4f57e06d0e0326f8740ae8d288d5;hb=087dd4f3ffb5aba8107c38f2eae0c82545ec21ca;hp=0000000000000000000000000000000000000000;hpb=898b208c298d71a13869c46ed96518de23a5a30f;p=Lucu.git diff --git a/Data/URI/Internal.hs b/Data/URI/Internal.hs new file mode 100644 index 0000000..ffb8a7b --- /dev/null +++ b/Data/URI/Internal.hs @@ -0,0 +1,37 @@ +{-# LANGUAGE + UnicodeSyntax + #-} +module Data.URI.Internal + ( finishOff + , parseAttempt + , parseAttempt' + ) + where +import Control.Applicative +import Control.Exception.Base +import Control.Monad.Unicode +import Data.Ascii (Ascii) +import qualified Data.Ascii as A +import Data.Attempt +import Data.Attoparsec.Char8 +import Data.ByteString (ByteString) +import Prelude.Unicode + +finishOff ∷ Parser α → Parser α +{-# INLINE finishOff #-} +finishOff = ((endOfInput *>) ∘ return =≪) + +parseAttempt ∷ Exception e + ⇒ (String → e) + → Parser α + → ByteString + → Attempt α +{-# INLINEABLE parseAttempt #-} +parseAttempt f p bs + = case parseOnly (finishOff p) bs of + Right α → Success α + Left e → Failure $ f e + +parseAttempt' ∷ Parser α → Ascii → Attempt α +{-# INLINE parseAttempt' #-} +parseAttempt' = (∘ A.toByteString) ∘ parseAttempt StringException