]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Data/URI/Internal.hs
Parser and co-parser for Data.URI.Scheme
[Lucu.git] / Data / URI / Internal.hs
diff --git a/Data/URI/Internal.hs b/Data/URI/Internal.hs
new file mode 100644 (file)
index 0000000..ffb8a7b
--- /dev/null
@@ -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